From ebf506ea65c553eb8f723067e5d7d06efafa5dd1 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Thu, 11 May 2023 10:30:12 -0400 Subject: [PATCH] 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 --- src/cephadm/cephadm.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/cephadm/cephadm.py b/src/cephadm/cephadm.py index d8159396c5fb6..d6d928c2a04aa 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 -- 2.39.5