]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
python-common: reduce output of ServiceSpec.to_json() 34005/head
authorSebastian Wagner <sebastian.wagner@suse.com>
Tue, 17 Mar 2020 14:23:14 +0000 (15:23 +0100)
committerSebastian Wagner <sebastian.wagner@suse.com>
Tue, 17 Mar 2020 14:23:14 +0000 (15:23 +0100)
Signed-off-by: Sebastian Wagner <sebastian.wagner@suse.com>
src/python-common/ceph/deployment/service_spec.py

index 08edc09170d6dceb24d6db1030f0225d98deaee4..e1f6331c9264fc71df1b32499c95fe7a38f760ff 100644 (file)
@@ -198,12 +198,16 @@ class PlacementSpec(object):
         return _cls
 
     def to_json(self):
-        return {
-            'label': self.label,
-            'hosts': [host.to_json() for host in self.hosts] if self.hosts else [],
-            'count': self.count,
-            'host_pattern': self.host_pattern,
-        }
+        r = {}
+        if self.label:
+            r['label'] = self.label
+        if self.hosts:
+            r['hosts'] = [host.to_json() for host in self.hosts]
+        if self.count:
+            r['count'] = self.count
+        if self.host_pattern:
+            r['host_pattern'] = self.host_pattern
+        return r
 
     def validate(self):
         if self.hosts and self.label:
@@ -378,9 +382,12 @@ class ServiceSpec(object):
 
     def to_json(self):
         # type: () -> Dict[str, Any]
-        c = self.__dict__.copy()
-        if self.placement:
-            c['placement'] = self.placement.to_json()
+        c = {}
+        for key, val in self.__dict__.items():
+            if hasattr(val, 'to_json'):
+                val = val.to_json()
+            if val:
+                c[key] = val
         return c
 
     def validate(self):