From ea92f363a947be0d9f2a07647c9b67406e0ff1ca Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 11 Nov 2019 10:52:34 -0600 Subject: [PATCH] mgr/ssh: optionally specify names for mon daemons Signed-off-by: Sage Weil --- src/pybind/mgr/orchestrator.py | 2 +- src/pybind/mgr/orchestrator_cli/module.py | 5 +++-- src/pybind/mgr/ssh/module.py | 17 +++++++++++------ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/pybind/mgr/orchestrator.py b/src/pybind/mgr/orchestrator.py index dc9e57f2fe9..fb634eac7c7 100644 --- a/src/pybind/mgr/orchestrator.py +++ b/src/pybind/mgr/orchestrator.py @@ -474,7 +474,7 @@ class Orchestrator(object): Update the number of cluster monitors. :param num: requested number of monitors. - :param hosts: list of hosts + network (optional) + :param hosts: list of hosts + network + name (optional) """ raise NotImplementedError() diff --git a/src/pybind/mgr/orchestrator_cli/module.py b/src/pybind/mgr/orchestrator_cli/module.py index 4bcfc3c985e..9b402322ed4 100644 --- a/src/pybind/mgr/orchestrator_cli/module.py +++ b/src/pybind/mgr/orchestrator_cli/module.py @@ -587,11 +587,12 @@ Usage: def split_host(host): """Split host into host and network parts""" # TODO: stricter validation + (host, name) = host.split('=', 1) parts = host.split(":", 1) if len(parts) == 1: - return (parts[0], None) + return (parts[0], None, name) elif len(parts) == 2: - return (parts[0], parts[1]) + return (parts[0], parts[1], name) else: raise RuntimeError("Invalid host specification: " "'{}'".format(host)) diff --git a/src/pybind/mgr/ssh/module.py b/src/pybind/mgr/ssh/module.py index dd22a86aa9c..d648679db76 100644 --- a/src/pybind/mgr/ssh/module.py +++ b/src/pybind/mgr/ssh/module.py @@ -850,7 +850,7 @@ class SSHOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin): return add_func(spec) return SSHWriteCompletion(results) - def _create_mon(self, host, network): + def _create_mon(self, host, network, name): """ Create a new monitor on the given host. """ @@ -872,7 +872,7 @@ class SSHOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin): else: raise RuntimeError('Must specify a CIDR network, ceph addrvec, or plain IP: \'%s\'' % network) - return self._create_daemon('mon', host, host, keyring, + return self._create_daemon('mon', name or host, host, keyring, extra_args=extra_args) def update_mons(self, num, hosts): @@ -891,10 +891,15 @@ class SSHOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin): self._require_hosts(map(lambda h: h[0], hosts)) # current support requires a network to be specified - for host, network in hosts: + for host, network, name in hosts: if not network: raise RuntimeError("Host '{}' missing network part".format(host)) + daemons = self._get_services('mon') + 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) + # explicit placement: enough hosts provided? num_new_mons = num - num_mons if len(hosts) < num_new_mons: @@ -907,9 +912,9 @@ class SSHOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin): # TODO: we may want to chain the creation of the monitors so they join # the quorum one at a time. results = [] - for host, network in hosts: - result = self._worker_pool.apply_async(self._create_mon, (host, - network)) + for host, network, name in hosts: + result = self._worker_pool.apply_async(self._create_mon, + (host, network, name)) results.append(result) return SSHWriteCompletion(results) -- 2.39.5