From f396fa1d7ff669edc32cccd45590f36449f9e786 Mon Sep 17 00:00:00 2001 From: Jeff Layton Date: Tue, 30 Oct 2018 14:28:02 -0400 Subject: [PATCH] orchestrator_cli: add an orchestrator service ls function There's currently no way to enumerate the services that the orchestrator backend knows about. Add a "service ls" command that will list them with some basic info, subject to filters given on the command line. Signed-off-by: Jeff Layton --- doc/mgr/orchestrator_cli.rst | 9 ++++++ src/pybind/mgr/orchestrator_cli/module.py | 34 ++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/doc/mgr/orchestrator_cli.rst b/doc/mgr/orchestrator_cli.rst index cbd2b317525..55a76d7fa37 100644 --- a/doc/mgr/orchestrator_cli.rst +++ b/doc/mgr/orchestrator_cli.rst @@ -43,6 +43,15 @@ filtered to a particular node: orchestrator device ls [node] +Print a list of services known to the orchestrator. The list can be limited to +services on a particular host with the optional --host parameter and/or +services of a particular type via optional --type parameter +(mon, osd, mgr, mds, rgw): + +:: + + orchestrator service ls [--host=host] [--type=type] + Query the status of a particular service (mon, osd, mgr, mds, rgw). For OSDs the id is the numeric OSD ID, for MDS services it is the filesystem name: diff --git a/src/pybind/mgr/orchestrator_cli/module.py b/src/pybind/mgr/orchestrator_cli/module.py index b727efcfd26..d442cb72c13 100644 --- a/src/pybind/mgr/orchestrator_cli/module.py +++ b/src/pybind/mgr/orchestrator_cli/module.py @@ -20,6 +20,13 @@ class OrchestratorCli(MgrModule): "desc": "List devices on a node", "perm": "r" }, + { + 'cmd': "orchestrator service ls " + "name=host,type=CephString,req=false " + "name=type,type=CephString,req=false ", + "desc": "List services known to orchestrator" , + "perm": "r" + }, { 'cmd': "orchestrator service status " "name=svc_type,type=CephString " @@ -118,6 +125,29 @@ class OrchestratorCli(MgrModule): return 0, result, "" + def _list_services(self, cmd): + hostname = cmd.get('host', None) + service_type = cmd.get('type', None) + + completion = self._oremote("describe_service", service_type, None, hostname) + self._wait([completion]) + services = completion.result + + if len(services) == 0: + return 0, "", "No services reported" + else: + # Sort the list for display + services.sort(key = lambda s: (s.service_type, s.nodename, s.daemon_name)) + lines = [] + for s in services: + lines.append("{0}.{1} {2} {3}".format( + s.service_type, + s.daemon_name, + s.nodename, + s.container_id)) + + return 0, "\n".join(lines), "" + def _service_status(self, cmd): svc_type = cmd['svc_type'] svc_id = cmd['svc_id'] @@ -125,7 +155,7 @@ class OrchestratorCli(MgrModule): # XXX this is kind of confusing for people because in the orchestrator # context the service ID for MDS is the filesystem ID, not the daemon ID - completion = self._oremote("describe_service", svc_type, svc_id) + completion = self._oremote("describe_service", svc_type, svc_id, None) self._wait([completion]) @@ -275,6 +305,8 @@ class OrchestratorCli(MgrModule): def _handle_command(self, _, cmd): if cmd['prefix'] == "orchestrator device ls": return self._list_devices(cmd) + elif cmd['prefix'] == "orchestrator service ls": + return self._list_services(cmd) elif cmd['prefix'] == "orchestrator service status": return self._service_status(cmd) elif cmd['prefix'] == "orchestrator service add": -- 2.39.5