]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/orch: pass HostSpec to add_host
authorSage Weil <sage@redhat.com>
Wed, 5 Feb 2020 23:33:41 +0000 (17:33 -0600)
committerSage Weil <sage@redhat.com>
Fri, 7 Feb 2020 19:36:45 +0000 (13:36 -0600)
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 <sage@redhat.com>
src/pybind/mgr/cephadm/module.py
src/pybind/mgr/cephadm/tests/test_cephadm.py
src/pybind/mgr/orchestrator.py
src/pybind/mgr/orchestrator_cli/module.py
src/pybind/mgr/test_orchestrator/module.py

index d8dc967c3e6997eacf4a54ae1826dabe48f43c25..21a38d33c37f35cd32df95f705081da79630d274 100644 (file)
@@ -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):
index 8e59cc93b6dfed70724ec1e90a71a361a854ba21..a6d768be8a882b6389286b4edd9bb3d0de13c4df 100644 (file)
@@ -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))
 
index d93bc26993d8f6048d4d9cf020f91b88b9a93697..f926fee1868e06bdb5196b375dcb48eaddd041fb 100644 (file)
@@ -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
index 37249d5aa6ff66d1cb9a3004db588706604ce570..94c2dd2984938cab21fa739f7679e5c1dd4c89ed 100644 (file)
@@ -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())
index 642528aa5fc5c18e6eda99ce467318f94fb73abc..7e712dc0170dcff9e0d42c2bba9bbabb7b630db4 100644 (file)
@@ -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':