From: Sage Weil Date: Fri, 25 Oct 2019 17:50:50 +0000 (-0500) Subject: mgr/ssh: implement (synchronous) describe_service X-Git-Tag: v15.1.0~1156^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8bbb13f0eb8fd570ed0d626f49e0d2dc64aaba9c;p=ceph.git mgr/ssh: implement (synchronous) describe_service Signed-off-by: Sage Weil --- diff --git a/src/pybind/mgr/ssh/module.py b/src/pybind/mgr/ssh/module.py index aca101936eaa..da46255dda96 100644 --- a/src/pybind/mgr/ssh/module.py +++ b/src/pybind/mgr/ssh/module.py @@ -377,7 +377,58 @@ class SSHOrchestrator(MgrModule, orchestrator.Orchestrator): nodes = [orchestrator.InventoryNode(host_name, []) for host_name in self.inventory_cache] return orchestrator.TrivialReadCompletion(nodes) - def _run_ceph_daemon(self, host, entity, command, args, stdin=None): + def describe_service(self, service_type=None, service_id=None, + node_name=None, refresh=False): + + if service_type not in ("mds", "osd", "mgr", "mon", "nfs", None): + raise orchestrator.OrchestratorValidationError( + service_type + " unsupported") + + #daemons = self.get_daemons() + daemons = {} + for host, _ in self._get_hosts(): + self.log.info("refresh stale daemons for '{}'".format(host)) + out, code = self._run_ceph_daemon( + host, 'mon', 'ls', [], no_fsid=True) + daemons[host] = json.loads(''.join(out)) + + result = [] + for host, ls in daemons.items(): + for d in ls: + if not d['style'].startswith('ceph-daemon'): + self.log.debug('ignoring non-ceph-daemon on %s: %s' % (host, d)) + continue + if d['fsid'] != self._cluster_fsid: + self.log.debug('ignoring foreign daemon on %s: %s' % (host, d)) + continue + self.log.debug('including %s' % d) + sd = orchestrator.ServiceDescription() + sd.service_type = d['name'].split('.')[0] + if service_type and service_type != sd.service_type: + continue + if '.' in d['name']: + sd.service_instance = d['name'].split('.')[1] + else: + sd.service_instance = host # e.g., crash + if service_id and service_id != sd.service_instance: + continue + sd.nodename = host + sd.container_id = d['container_id'] + sd.version = d['version'] + sd.status_desc = d['state'] + sd.status = { + 'running': 1, + 'inactive': 0, + 'error': -1, + 'unknown': -1, + }[d['state']] + result.append(sd) + + return orchestrator.TrivialReadCompletion(result) + + def _run_ceph_daemon(self, host, entity, command, args, + stdin=None, + no_fsid=False): """ Run ceph-daemon on the remote host with the given command + args """ @@ -395,9 +446,11 @@ class SSHOrchestrator(MgrModule, orchestrator.Orchestrator): final_args = [ '--image', image, - command, - '--fsid', self._cluster_fsid, - ] + args + command + ] + if not no_fsid: + final_args += ['--fsid', self._cluster_fsid] + final_args += args script = 'injected_argv = ' + json.dumps(final_args) + '\n' if stdin: