]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/orch: show placement in 'orch ls' 33667/head
authorSage Weil <sage@redhat.com>
Mon, 2 Mar 2020 15:01:05 +0000 (09:01 -0600)
committerSage Weil <sage@redhat.com>
Tue, 3 Mar 2020 13:01:07 +0000 (07:01 -0600)
Signed-off-by: Sage Weil <sage@redhat.com>
src/pybind/mgr/orchestrator/_interface.py
src/pybind/mgr/orchestrator/module.py
src/pybind/mgr/tests/test_orchestrator.py

index 4f015993df3beec4edcbc7fd6d838eac8ab3f603..183217a4a1767bc51623f9d8afcdb3c8130093ae 100644 (file)
@@ -1256,17 +1256,20 @@ class PlacementSpec(object):
         # in the orchestrator backend.
         self.hosts = hosts
 
-    def __repr__(self):
+    def pretty_str(self):
         kv = []
         if self.count:
             kv.append('count=%d' % self.count)
         if self.label:
             kv.append('label=%s' % self.label)
         if self.hosts:
-            kv.append('hosts=%s' % self.hosts)
+            kv.append('hosts=%s' % ','.join([str(h) for h in self.hosts]))
         if self.all_hosts:
             kv.append('all=true')
-        return "PlacementSpec(%s)" % (' '.join(kv))
+        return ' '.join(kv)
+
+    def __repr__(self):
+        return "PlacementSpec(%s)" % self.pretty_str()
 
     @classmethod
     def from_dict(cls, data):
index a43218d7a991a3ddf62c6683ed93e9fabe4319f6..247ce76b7bf8ee1113ba5ec8f6464360baff82bb 100644 (file)
@@ -335,7 +335,7 @@ class OrchestratorCli(OrchestratorClientMixin, MgrModule):
         else:
             now = datetime.datetime.utcnow()
             table = PrettyTable(
-                ['NAME', 'RUNNING', 'REFRESHED', 'IMAGE NAME', 'IMAGE ID', 'SPEC'],
+                ['NAME', 'RUNNING', 'REFRESHED', 'IMAGE NAME', 'IMAGE ID', 'SPEC', 'PLACEMENT'],
                 border=False)
             table.align['NAME'] = 'l'
             table.align['RUNNING'] = 'r'
@@ -343,6 +343,7 @@ class OrchestratorCli(OrchestratorClientMixin, MgrModule):
             table.align['IMAGE NAME'] = 'l'
             table.align['IMAGE ID'] = 'l'
             table.align['SPEC'] = 'l'
+            table.align['PLACEMENT'] = 'l'
             table.left_padding_width = 0
             table.right_padding_width = 2
             for s in sorted(services, key=lambda s: s.service_name):
@@ -357,6 +358,7 @@ class OrchestratorCli(OrchestratorClientMixin, MgrModule):
                     ukn(s.container_image_name),
                     ukn(s.container_image_id)[0:12],
                     'present' if s.spec else '-',
+                    s.spec.placement.pretty_str() if s.spec else '-',
                 ))
 
             return HandleCommandResult(stdout=table.get_string())
index fc9641664a26bd1c5218db247f171e2d11fc6a7c..8d74754262a0e340dd1cc5108461d03695d72cd3 100644 (file)
@@ -35,8 +35,10 @@ def test_parse_host_placement_specs(test_input, expected, require_network):
     [
         ('', "PlacementSpec()"),
         ("3", "PlacementSpec(count=3)"),
-        ("host1 host2", "PlacementSpec(hosts=[HostPlacementSpec(hostname='host1', network='', name=''), HostPlacementSpec(hostname='host2', network='', name='')])"),
-        ('2 host1 host2', "PlacementSpec(count=2 hosts=[HostPlacementSpec(hostname='host1', network='', name=''), HostPlacementSpec(hostname='host2', network='', name='')])"),
+        ("host1 host2", "PlacementSpec(hosts=host1,host2)"),
+        ("host1=a host2=b", "PlacementSpec(hosts=host1=a,host2=b)"),
+        ("host1:1.2.3.4=a host2:1.2.3.5=b", "PlacementSpec(hosts=host1:1.2.3.4=a,host2:1.2.3.5=b)"),
+        ('2 host1 host2', "PlacementSpec(count=2 hosts=host1,host2)"),
         ('label:foo', "PlacementSpec(label=foo)"),
         ('3 label:foo', "PlacementSpec(count=3 label=foo)"),
         ('*', 'PlacementSpec(all=true)'),