]> git.apps.os.sepia.ceph.com Git - ceph-ci.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)
committerAdam King <adking@redhat.com>
Thu, 31 Aug 2023 17:35:13 +0000 (13: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 18a900ca074f7d72d67f965acce32d9bcf2f9fd5..fb2e62af69dcf22b062f9cd681ce785a883a8181 100755 (executable)
@@ -3034,6 +3034,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