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)
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:
"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)