From 6421f6a5a20638c85921f80e8ce79b065298a75a Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 2 Mar 2020 09:01:05 -0600 Subject: [PATCH] mgr/orch: show placement in 'orch ls' Signed-off-by: Sage Weil --- src/pybind/mgr/orchestrator/_interface.py | 9 ++++++--- src/pybind/mgr/orchestrator/module.py | 4 +++- src/pybind/mgr/tests/test_orchestrator.py | 6 ++++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/pybind/mgr/orchestrator/_interface.py b/src/pybind/mgr/orchestrator/_interface.py index 4f015993df3be..183217a4a1767 100644 --- a/src/pybind/mgr/orchestrator/_interface.py +++ b/src/pybind/mgr/orchestrator/_interface.py @@ -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): diff --git a/src/pybind/mgr/orchestrator/module.py b/src/pybind/mgr/orchestrator/module.py index a43218d7a991a..247ce76b7bf8e 100644 --- a/src/pybind/mgr/orchestrator/module.py +++ b/src/pybind/mgr/orchestrator/module.py @@ -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()) diff --git a/src/pybind/mgr/tests/test_orchestrator.py b/src/pybind/mgr/tests/test_orchestrator.py index fc9641664a26b..8d74754262a0e 100644 --- a/src/pybind/mgr/tests/test_orchestrator.py +++ b/src/pybind/mgr/tests/test_orchestrator.py @@ -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)'), -- 2.39.5