]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: add fetch_meta function for reading metadata properties from ctx
authorJohn Mulligan <jmulligan@redhat.com>
Thu, 11 May 2023 14:30:12 +0000 (10:30 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Thu, 15 Jun 2023 20:35:34 +0000 (16:35 -0400)
The CephadmContext holds much of cephadm's state, including values from
cli options and (soon) configuration file input. Add a `fetch_meta`
function that reads processed metadata from `meta_properties` or parses
JSON stored on `meta_json`. Parsed JSON is saved to `meta_properties`.
Future code should always use fetch_meta for reading, and only ever
set `meta_properties` as a python dict, not round trip JSON through
meta_json.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/cephadm/cephadm.py

index d8159396c5fb64948696e63bcd74e82c1d64c935..d6d928c2a04aaca5137c750ddf5344fbeae1462e 100755 (executable)
@@ -3035,6 +3035,20 @@ def _get_config_json(option: str) -> Dict[str, Any]:
         return js
 
 
+def fetch_meta(ctx: CephadmContext) -> Dict[str, Any]:
+    """Return a dict containing metadata about a deployment.
+    """
+    meta = getattr(ctx, 'meta_properties', None)
+    if meta is not None:
+        return meta
+    mjson = getattr(ctx, 'meta_json', None)
+    if mjson is not None:
+        meta = json.loads(mjson) or {}
+        ctx.meta_properties = meta
+        return meta
+    return {}
+
+
 def get_config_and_keyring(ctx):
     # type: (CephadmContext) -> Tuple[Optional[str], Optional[str]]
     config = None