]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/orch: HostSpec -> HostPlacementSpec
authorSage Weil <sage@redhat.com>
Wed, 5 Feb 2020 23:19:56 +0000 (17:19 -0600)
committerSage Weil <sage@redhat.com>
Fri, 7 Feb 2020 19:36:16 +0000 (13:36 -0600)
This object is about describing where to place a service on a host: it
includes a host name and either an IP or network and possibly even a name
for the service.

Signed-off-by: Sage Weil <sage@redhat.com>
src/pybind/mgr/cephadm/module.py
src/pybind/mgr/orchestrator.py
src/pybind/mgr/tests/test_orchestrator.py

index 319a50e89d6eabf28818154a1e2d115f3cf6b92c..d8dc967c3e6997eacf4a54ae1826dabe48f43c25 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, HostSpec, OrchestratorValidationError
+from orchestrator import OrchestratorError, HostPlacementSpec, OrchestratorValidationError
 
 from . import remotes
 
@@ -2168,7 +2168,7 @@ class BaseScheduler(object):
 
     * requires a placement_spec
 
-    `place(host_pool)` needs to return a List[HostSpec, ..]
+    `place(host_pool)` needs to return a List[HostPlacementSpec, ..]
     """
 
     def __init__(self, placement_spec):
@@ -2176,7 +2176,7 @@ class BaseScheduler(object):
         self.placement_spec = placement_spec
 
     def place(self, host_pool, count=None):
-        # type: (List, Optional[int]) -> List[HostSpec]
+        # type: (List, Optional[int]) -> List[HostPlacementSpec]
         raise NotImplementedError
 
 
@@ -2190,10 +2190,10 @@ class SimpleScheduler(BaseScheduler):
         super(SimpleScheduler, self).__init__(placement_spec)
 
     def place(self, host_pool, count=None):
-        # type: (List, Optional[int]) -> List[HostSpec]
+        # type: (List, Optional[int]) -> List[HostPlacementSpec]
         if not host_pool:
             raise Exception('List of host candidates is empty')
-        host_pool = [HostSpec(x, '', '') for x in host_pool]
+        host_pool = [HostPlacementSpec(x, '', '') for x in host_pool]
         # shuffle for pseudo random selection
         random.shuffle(host_pool)
         return host_pool[:count]
@@ -2241,7 +2241,7 @@ class NodeAssignment(object):
         # NOTE: This currently queries for all hosts without label restriction
         if self.spec.placement.label:
             logger.info("Found labels. Assinging nodes that match the label")
-            candidates = [HostSpec(x[0], '', '') for x in self.get_hosts_func()]  # TODO: query for labels
+            candidates = [HostPlacementSpec(x[0], '', '') for x in self.get_hosts_func()]  # TODO: query for labels
             logger.info('Assigning nodes to spec: {}'.format(candidates))
             self.spec.placement.set_hosts(candidates)
 
index 09fed945d5555f002191264817deda752e972a54..d93bc26993d8f6048d4d9cf020f91b88b9a93697 100644 (file)
@@ -35,7 +35,7 @@ except ImportError:
 logger = logging.getLogger(__name__)
 
 
-class HostSpec(namedtuple('HostSpec', ['hostname', 'network', 'name'])):
+class HostPlacementSpec(namedtuple('HostPlacementSpec', ['hostname', 'network', 'name'])):
     def __str__(self):
         res = ''
         res += self.hostname
@@ -46,7 +46,8 @@ class HostSpec(namedtuple('HostSpec', ['hostname', 'network', 'name'])):
         return res
 
 
-def parse_host_specs(host, require_network=True):
+def parse_host_placement_specs(host, require_network=True):
+    # type: (str, Optional[bool]) -> HostPlacementSpec
     """
     Split host into host, network, and (optional) daemon name parts.  The network
     part can be an IP, CIDR, or ceph addrvec like '[v2:1.2.3.4:3300,v1:1.2.3.4:6789]'.
@@ -68,7 +69,7 @@ def parse_host_specs(host, require_network=True):
     name_re = r'=(.*?)$'
 
     # assign defaults
-    host_spec = HostSpec('', '', '')
+    host_spec = HostPlacementSpec('', '', '')
 
     match_host = re.search(host_re, host)
     if match_host:
@@ -1045,10 +1046,10 @@ class PlacementSpec(object):
         # type: (Optional[str], Optional[List], Optional[int]) -> None
         self.label = label
         if hosts:
-            if all([isinstance(host, HostSpec) for host in hosts]):
-                self.hosts = hosts  # type: List[HostSpec]
+            if all([isinstance(host, HostPlacementSpec) for host in hosts]):
+                self.hosts = hosts  # type: List[HostPlacementSpec]
             else:
-                self.hosts = [parse_host_specs(x, require_network=False) for x in hosts if x]
+                self.hosts = [parse_host_placement_specs(x, require_network=False) for x in hosts if x]
         else:
             self.hosts = []
 
index 3687e253d1ef6fd558263ff9495b0cff26b55e23..b86e8cb5fe759e4018959fd25cb6e00fca2e25b4 100644 (file)
@@ -9,7 +9,7 @@ from ceph.deployment import inventory
 from orchestrator import raise_if_exception, RGWSpec, Completion, ProgressReference
 from orchestrator import InventoryNode, ServiceDescription
 from orchestrator import OrchestratorValidationError
-from orchestrator import parse_host_specs
+from orchestrator import parse_host_placement_specs
 
 
 @pytest.mark.parametrize("test_input,expected, require_network",
@@ -24,8 +24,8 @@ from orchestrator import parse_host_specs
                           ("myhost:[v1:10.1.1.10:6789,v2:10.1.1.11:3000]", ('myhost', '[v1:10.1.1.10:6789,v2:10.1.1.11:3000]', ''), True),
                           ("myhost:[v1:10.1.1.10:6789,v2:10.1.1.11:3000]=sname", ('myhost', '[v1:10.1.1.10:6789,v2:10.1.1.11:3000]', 'sname'), True),
                           ])
-def test_parse_host_specs(test_input, expected, require_network):
-    ret = parse_host_specs(test_input, require_network=require_network)
+def test_parse_host_placement_specs(test_input, expected, require_network):
+    ret = parse_host_placement_specs(test_input, require_network=require_network)
     assert ret == expected
     assert str(ret) == test_input
 
@@ -37,9 +37,9 @@ def test_parse_host_specs(test_input, expected, require_network):
                           # empty string
                           ("myhost=1"),
                           ])
-def test_parse_host_specs_raises(test_input):
+def test_parse_host_placement_specs_raises(test_input):
     with pytest.raises(ValueError):
-        ret = parse_host_specs(test_input)
+        ret = parse_host_placement_specs(test_input)
 
 
 def _test_resource(data, resource_class, extra=None):