From d9dab9d34eee21b20bca8a05cad9e28b69e75496 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 11 Nov 2019 17:27:57 -0600 Subject: [PATCH] mgr/ssh: allow names to be specified for stateless services Signed-off-by: Sage Weil --- src/pybind/mgr/orchestrator.py | 12 +++++++++++- src/pybind/mgr/ssh/module.py | 20 +++++++++++++------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/pybind/mgr/orchestrator.py b/src/pybind/mgr/orchestrator.py index fb634eac7c70b..5ef1338ecafac 100644 --- a/src/pybind/mgr/orchestrator.py +++ b/src/pybind/mgr/orchestrator.py @@ -597,8 +597,18 @@ class PlacementSpec(object): """ def __init__(self, label=None, nodes=[]): self.label = label - self.nodes = nodes + 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) + + self.nodes = list(map(split_host, nodes)) def handle_type_error(method): @wraps(method) diff --git a/src/pybind/mgr/ssh/module.py b/src/pybind/mgr/ssh/module.py index d648679db7693..d83a2715e20cf 100644 --- a/src/pybind/mgr/ssh/module.py +++ b/src/pybind/mgr/ssh/module.py @@ -200,10 +200,15 @@ class SSHOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin): self.get_ceph_option(opt)) self.log.debug(' native option %s = %s', opt, getattr(self, opt)) - def get_unique_name(self, existing, prefix=None): + def get_unique_name(self, existing, prefix=None, forcename=None): """ Generate a unique random service name """ + if forcename: + if len([d for d in existing if d.service_instance == name]): + raise RuntimeError('specified name %s already in use', name) + return forcename + while True: if prefix: name = prefix + '.' @@ -1015,10 +1020,10 @@ class SSHOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin): daemons = self._get_services('mds') results = [] num_added = 0 - for host in spec.placement.nodes: + for host, name in spec.placement.nodes: if num_added >= spec.count: break - mds_id = self.get_unique_name(daemons, spec.name) + mds_id = self.get_unique_name(daemons, spec.name, name) self.log.debug('placing mds.%s on host %s' % (mds_id, host)) results.append( self._worker_pool.apply_async(self._create_mds, (mds_id, host)) @@ -1072,10 +1077,10 @@ class SSHOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin): daemons = self._get_services('rgw') results = [] num_added = 0 - for host in spec.placement.nodes: + for host, name in spec.placement.nodes: if num_added >= spec.count: break - rgw_id = self.get_unique_name(daemons, spec.name) + rgw_id = self.get_unique_name(daemons, spec.name, name) self.log.debug('placing rgw.%s on host %s' % (rgw_id, host)) results.append( self._worker_pool.apply_async(self._create_rgw, (rgw_id, host)) @@ -1118,13 +1123,14 @@ class SSHOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin): def add_rbd_mirror(self, spec): if not spec.placement.nodes or len(spec.placement.nodes) < spec.count: raise RuntimeError("must specify at least %d hosts" % spec.count) + self.log.debug('nodes %s' % spec.placement.nodes) daemons = self._get_services('rbd-mirror') results = [] num_added = 0 - for host in spec.placement.nodes: + for host, name in spec.placement.nodes: if num_added >= spec.count: break - daemon_id = self.get_unique_name(daemons) + daemon_id = self.get_unique_name(daemons, None, name) self.log.debug('placing rbd-mirror.%s on host %s' % (daemon_id, host)) results.append( -- 2.39.5