From: John Mulligan Date: Thu, 11 May 2023 14:30:12 +0000 (-0400) Subject: cephadm: add fetch_meta function for reading metadata properties from ctx X-Git-Tag: v19.0.0~982^2~26 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ebf506ea65c553eb8f723067e5d7d06efafa5dd1;p=ceph.git cephadm: add fetch_meta function for reading metadata properties from ctx 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 --- diff --git a/src/cephadm/cephadm.py b/src/cephadm/cephadm.py index d8159396c5fb..d6d928c2a04a 100755 --- a/src/cephadm/cephadm.py +++ b/src/cephadm/cephadm.py @@ -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