From ab56b54f230e9a42584164952a9e607fabe2f35e Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 8 Mar 2021 14:14:49 -0500 Subject: [PATCH] mgr/cephadm: gather and report ports in 'orch ps' output Signed-off-by: Sage Weil (cherry picked from commit 3c348e0dae4caeb81d3085cf98b6d7db9310cf57) --- src/pybind/mgr/cephadm/serve.py | 2 ++ src/pybind/mgr/cephadm/tests/test_cephadm.py | 6 ++++-- src/pybind/mgr/orchestrator/_interface.py | 14 ++++++++++++++ src/pybind/mgr/orchestrator/module.py | 3 ++- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/pybind/mgr/cephadm/serve.py b/src/pybind/mgr/cephadm/serve.py index 121cb3912ee7a..5fc0ae35ebfe3 100644 --- a/src/pybind/mgr/cephadm/serve.py +++ b/src/pybind/mgr/cephadm/serve.py @@ -281,6 +281,8 @@ class CephadmServe: sd.memory_limit = d.get('memory_limit') sd._service_name = d.get('service_name') sd.version = d.get('version') + sd.ports = d.get('ports') + sd.ip = d.get('ip') if sd.daemon_type == 'osd': sd.osdspec_affinity = self.mgr.osd_service.get_osdspec_affinity(sd.daemon_id) if 'state' in d: diff --git a/src/pybind/mgr/cephadm/tests/test_cephadm.py b/src/pybind/mgr/cephadm/tests/test_cephadm.py index 0372924dcc9bd..2b396c8547e7e 100644 --- a/src/pybind/mgr/cephadm/tests/test_cephadm.py +++ b/src/pybind/mgr/cephadm/tests/test_cephadm.py @@ -122,7 +122,9 @@ class TestCephadm(object): 'hostname': 'test', 'status': 1, 'status_desc': 'starting', - 'is_active': False} + 'is_active': False, + 'ports': [], + } ] with with_service(cephadm_module, ServiceSpec('rgw', 'r.z'), CephadmOrchestrator.apply_rgw, 'test'): @@ -287,7 +289,7 @@ class TestCephadm(object): _run_cephadm.assert_called_with( 'test', 'mon.test', 'deploy', [ '--name', 'mon.test', - '--meta-json', '{"service_name": "mon"}', + '--meta-json', '{"service_name": "mon", "ports": [], "ip": null}', '--config-json', '-', '--reconfig', ], diff --git a/src/pybind/mgr/orchestrator/_interface.py b/src/pybind/mgr/orchestrator/_interface.py index 11c70b0f8354f..cf3781f75b15a 100644 --- a/src/pybind/mgr/orchestrator/_interface.py +++ b/src/pybind/mgr/orchestrator/_interface.py @@ -791,6 +791,8 @@ class DaemonDescription(object): memory_request: Optional[int] = None, memory_limit: Optional[int] = None, service_name: Optional[str] = None, + ports: Optional[List[int]] = None, + ip: Optional[str] = None, ) -> None: # Host is at the same granularity as InventoryHost @@ -843,8 +845,18 @@ class DaemonDescription(object): self.memory_request: Optional[int] = memory_request self.memory_limit: Optional[int] = memory_limit + self.ports: Optional[List[int]] = ports + self.ip: Optional[str] = ip + self.is_active = is_active + def get_port_summary(self) -> str: + if not self.ports: + return '' + return ' '.join([ + f"{self.ip or '*'}:{p}" for p in self.ports + ]) + def name(self) -> str: return '%s.%s' % (self.daemon_type, self.daemon_id) @@ -951,6 +963,8 @@ class DaemonDescription(object): if self.daemon_type == 'osd': out['osdspec_affinity'] = self.osdspec_affinity out['is_active'] = self.is_active + out['ports'] = self.ports + out['ip'] = self.ip for k in ['last_refresh', 'created', 'started', 'last_deployed', 'last_configured']: diff --git a/src/pybind/mgr/orchestrator/module.py b/src/pybind/mgr/orchestrator/module.py index bcffdc833e6c0..cd843ff170030 100644 --- a/src/pybind/mgr/orchestrator/module.py +++ b/src/pybind/mgr/orchestrator/module.py @@ -626,7 +626,7 @@ class OrchestratorCli(OrchestratorClientMixin, MgrModule, now = datetime_now() table = PrettyTable( - ['NAME', 'HOST', 'STATUS', 'REFRESHED', 'AGE', + ['NAME', 'HOST', 'STATUS', 'REFRESHED', 'AGE', 'PORTS', 'VERSION', 'IMAGE NAME', 'IMAGE ID', 'CONTAINER ID'], border=False) table.align = 'l' @@ -651,6 +651,7 @@ class OrchestratorCli(OrchestratorClientMixin, MgrModule, status, nice_delta(now, s.last_refresh, ' ago'), nice_delta(now, s.created), + s.get_port_summary() or '-', ukn(s.version), ukn(s.container_image_name), ukn(s.container_image_id)[0:12], -- 2.39.5