From: Sage Weil Date: Mon, 11 Nov 2019 16:26:13 +0000 (-0600) Subject: mgr/ssh: optionally specify names for mgr daemons X-Git-Tag: v15.1.0~929^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c2caa369075041d819e24103aedfed97fca34407;p=ceph.git mgr/ssh: optionally specify names for mgr daemons Use '=' as a separator. Signed-off-by: Sage Weil --- diff --git a/src/pybind/mgr/orchestrator_cli/module.py b/src/pybind/mgr/orchestrator_cli/module.py index 6f9f3c30008b..4bcfc3c985ea 100644 --- a/src/pybind/mgr/orchestrator_cli/module.py +++ b/src/pybind/mgr/orchestrator_cli/module.py @@ -551,6 +551,23 @@ Usage: return HandleCommandResult(-errno.EINVAL, stderr="Invalid number of mgrs: require {} > 0".format(num)) + def split_host(host): + """Split host into host and name parts""" + # TODO: stricter validation + a = host.split('=', 1) + if len(a) == 1: + return (a[0], None) + else: + assert len(a) == 2 + return tuple(a) + + if hosts: + try: + hosts = list(map(split_host, hosts)) + except Exception as e: + msg = "Failed to parse host list: '{}': {}".format(hosts, e) + return HandleCommandResult(-errno.EINVAL, stderr=msg) + completion = self.update_mgrs(num, hosts) self._orchestrator_wait([completion]) orchestrator.raise_if_exception(completion) diff --git a/src/pybind/mgr/ssh/module.py b/src/pybind/mgr/ssh/module.py index 62beeb7abe55..dd22a86aa9cb 100644 --- a/src/pybind/mgr/ssh/module.py +++ b/src/pybind/mgr/ssh/module.py @@ -941,7 +941,7 @@ class SSHOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin): return SSHWriteCompletionReady("The requested number of managers exist.") # check that all the hosts are registered - self._require_hosts(hosts) + self._require_hosts(map(lambda h: h[0], hosts)) results = [] if num < num_mgrs: @@ -987,13 +987,19 @@ class SSHOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin): "Error: {} hosts provided, expected {}".format( len(hosts), num_new_mgrs)) + for _, name in hosts: + if name and len([d for d in daemons if d.service_instance == name]): + raise RuntimeError('name %s alrady exists', name) + self.log.info("creating {} managers on hosts: '{}'".format( - num_new_mgrs, ",".join(hosts))) + num_new_mgrs, ",".join(map(lambda h: h[0], hosts)))) for i in range(num_new_mgrs): - name = self.get_unique_name(daemons) + host, name = hosts[i] + if not name: + name = self.get_unique_name(daemons) result = self._worker_pool.apply_async(self._create_mgr, - (hosts[i], name)) + (host, name)) results.append(result) return SSHWriteCompletion(results)