From: Sage Weil Date: Wed, 5 Feb 2020 23:33:41 +0000 (-0600) Subject: mgr/orch: pass HostSpec to add_host X-Git-Tag: v15.1.1~506^2~4 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=16c35f2011cd11b1725c87623fa1375520beae57;p=ceph.git mgr/orch: pass HostSpec to add_host Distinguish between the hostname and the addr (dns name or IP) to reach the host. Include labels here too since it's convenient to do so. Signed-off-by: Sage Weil --- diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index d8dc967c3e699..21a38d33c37f3 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -30,7 +30,7 @@ from ceph.deployment.drive_selection import selector 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 @@ -1127,25 +1127,30 @@ class CephadmOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin): 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): diff --git a/src/pybind/mgr/cephadm/tests/test_cephadm.py b/src/pybind/mgr/cephadm/tests/test_cephadm.py index 8e59cc93b6dfe..a6d768be8a882 100644 --- a/src/pybind/mgr/cephadm/tests/test_cephadm.py +++ b/src/pybind/mgr/cephadm/tests/test_cephadm.py @@ -10,7 +10,7 @@ except ImportError: 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 @@ -37,7 +37,7 @@ class TestCephadm(object): @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)) diff --git a/src/pybind/mgr/orchestrator.py b/src/pybind/mgr/orchestrator.py index d93bc26993d8f..f926fee1868e0 100644 --- a/src/pybind/mgr/orchestrator.py +++ b/src/pybind/mgr/orchestrator.py @@ -766,8 +766,8 @@ class Orchestrator(object): """ 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. @@ -1028,6 +1028,12 @@ class Orchestrator(object): """ 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 diff --git a/src/pybind/mgr/orchestrator_cli/module.py b/src/pybind/mgr/orchestrator_cli/module.py index 37249d5aa6ff6..94c2dd2984938 100644 --- a/src/pybind/mgr/orchestrator_cli/module.py +++ b/src/pybind/mgr/orchestrator_cli/module.py @@ -157,10 +157,13 @@ class OrchestratorCli(orchestrator.OrchestratorClientMixin, MgrModule): @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()) diff --git a/src/pybind/mgr/test_orchestrator/module.py b/src/pybind/mgr/test_orchestrator/module.py index 642528aa5fc5c..7e712dc0170dc 100644 --- a/src/pybind/mgr/test_orchestrator/module.py +++ b/src/pybind/mgr/test_orchestrator/module.py @@ -263,7 +263,9 @@ class TestOrchestrator(MgrModule, orchestrator.Orchestrator): 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':