from mgr_module import MgrModule
import mgr_util
import orchestrator
-from orchestrator import OrchestratorError, HostPlacementSpec, OrchestratorValidationError
+from orchestrator import OrchestratorError, HostPlacementSpec, OrchestratorValidationError, HostSpec
from . import remotes
return self.inventory_cache.items_filtered(wanted)
@async_completion
- def add_host(self, host):
+ def add_host(self, spec):
+ # type: (HostSpec) -> str
"""
Add a host to be managed by the orchestrator.
:param host: host name
"""
- assert_valid_host(host)
- out, err, code = self._run_cephadm(host, 'client', 'check-host',
- ['--expect-hostname', host],
+ assert_valid_host(spec.hostname)
+ out, err, code = self._run_cephadm(spec.addr, 'client', 'check-host',
+ ['--expect-hostname', spec.hostname],
error_ok=True, no_fsid=True)
if code:
- raise OrchestratorError('New host %s failed check: %s' % (host, err))
+ raise OrchestratorError('New host %s (%s) failed check: %s' % (
+ spec.hostname, spec.addr, err))
- self.inventory[host] = {}
+ self.inventory[spec.hostname] = {
+ 'addr': spec.addr,
+ 'labels': spec.labels,
+ }
self._save_inventory()
- self.inventory_cache[host] = orchestrator.OutdatableData()
- self.service_cache[host] = orchestrator.OutdatableData()
+ self.inventory_cache[spec.hostname] = orchestrator.OutdatableData()
+ self.service_cache[spec.hostname] = orchestrator.OutdatableData()
self.event.set() # refresh stray health check
- return "Added host '{}'".format(host)
+ return "Added host '{}'".format(spec.hostname)
@async_completion
def remove_host(self, host):
pass
from orchestrator import ServiceDescription, InventoryNode, \
- StatelessServiceSpec, PlacementSpec, RGWSpec, StatefulServiceSpec
+ StatelessServiceSpec, PlacementSpec, RGWSpec, StatefulServiceSpec, HostSpec
from tests import mock
from .fixtures import cephadm_module, wait
@contextmanager
def _with_host(self, m, name):
- wait(m, m.add_host(name))
+ wait(m, m.add_host(HostSpec(hostname=name)))
yield
wait(m, m.remove_host(name))
"""
raise NotImplementedError()
- def add_host(self, host):
- # type: (str) -> Completion
+ def add_host(self, HostSpec):
+ # type: (HostSpec) -> Completion
"""
Add a host to the orchestrator inventory.
"""
raise NotImplementedError()
+class HostSpec(object):
+ def __init__(self, hostname, addr=None, labels=None):
+ # type: (str, Optional[str], Optional[List[str]]) -> None
+ self.hostname = hostname # the hostname on the host
+ self.addr = addr or hostname # DNS name or IP address to reach it
+ self.labels = labels or [] # initial label(s), if any
class UpgradeStatusSpec(object):
# Orchestrator's report on what's going on with any ongoing upgrade
@orchestrator._cli_write_command(
'orchestrator host add',
- "name=host,type=CephString,req=true",
+ 'name=host,type=CephString,req=true '
+ 'name=addr,type=CephString,req=false '
+ 'name=labels,type=CephString,n=N,req=false',
'Add a host')
- def _add_host(self, host):
- completion = self.add_host(host)
+ def _add_host(self, host, addr=None, labels=None):
+ s = orchestrator.HostSpec(hostname=host, addr=addr, labels=labels)
+ completion = self.add_host(s)
self._orchestrator_wait([completion])
orchestrator.raise_if_exception(completion)
return HandleCommandResult(stdout=completion.result_str())
return [orchestrator.InventoryNode('localhost', inventory.Devices([]))]
@deferred_write("add_host")
- def add_host(self, host):
+ def add_host(self, spec):
+ # type: (orchestrator.HostSpec) -> None
+ host = spec.hostname
if host == 'raise_no_support':
raise orchestrator.OrchestratorValidationError("MON count must be either 1, 3 or 5")
if host == 'raise_bug':