From fd29e1c4a8ccaa84f3f2e73920b637576d565015 Mon Sep 17 00:00:00 2001 From: Sebastian Wagner Date: Thu, 11 Jun 2020 11:55:00 +0200 Subject: [PATCH] mgr/orch: make YAML of ServiceDescription readable Signed-off-by: Sebastian Wagner --- src/pybind/mgr/orchestrator/_interface.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/pybind/mgr/orchestrator/_interface.py b/src/pybind/mgr/orchestrator/_interface.py index daaad69c49c..7899b4fef48 100644 --- a/src/pybind/mgr/orchestrator/_interface.py +++ b/src/pybind/mgr/orchestrator/_interface.py @@ -1420,7 +1420,7 @@ class ServiceDescription(object): def __repr__(self): return f"" - def to_json(self): + def to_json(self) -> OrderedDict: out = self.spec.to_json() status = { 'container_image_id': self.container_image_id, @@ -1452,6 +1452,13 @@ class ServiceDescription(object): c_status[k] = datetime.datetime.strptime(c_status[k], DATEFMT) return cls(spec=spec, **c_status) + @staticmethod + def yaml_representer(dumper: 'yaml.SafeDumper', data: 'DaemonDescription'): + return dumper.represent_dict(data.to_json().items()) + + +yaml.add_representer(ServiceDescription, ServiceDescription.yaml_representer) + class InventoryFilter(object): """ -- 2.39.5