]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/orchestrator: move split_host into shared helpers 31537/head
authorSage Weil <sage@redhat.com>
Tue, 12 Nov 2019 14:24:31 +0000 (08:24 -0600)
committerSage Weil <sage@redhat.com>
Tue, 12 Nov 2019 15:00:52 +0000 (09:00 -0600)
Signed-off-by: Sage Weil <sage@redhat.com>
src/pybind/mgr/orchestrator.py
src/pybind/mgr/orchestrator_cli/module.py

index 5ef1338ecafac16b969625eedd662f40fae60e87..1e4723d44c4589aa6e4b1ba66fe6a884acc28b99 100644 (file)
@@ -26,6 +26,40 @@ try:
 except ImportError:
     T, G = object, object
 
+def split_host(host):
+    """
+    Split host into host and (optional) daemon name parts
+    e.g.,
+      "myhost=name" -> ('myhost', 'name')
+      "myhost" -> ('myhost', None)
+    """
+    # TODO: stricter validation
+    a = host.split('=', 1)
+    if len(a) == 1:
+        return (a[0], None)
+    else:
+        assert len(a) == 2
+        return tuple(a)
+
+def split_host_with_network(host):
+    """
+    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]'.
+    e.g.,
+      "myhost:1.2.3.4=name" -> ('myhost', '1.2.3.4', 'name')
+      "myhost:1.2.3.0/24" -> ('myhost', '1.2.3.0/24', None)
+    """
+    # TODO: stricter validation
+    (host, name) = host.split('=', 1)
+    parts = host.split(":", 1)
+    if len(parts) == 1:
+        return (parts[0], None, name)
+    elif len(parts) == 2:
+        return (parts[0], parts[1], name)
+    else:
+        raise RuntimeError("Invalid host specification: "
+                           "'{}'".format(host))
 
 class OrchestratorError(Exception):
     """
@@ -598,16 +632,6 @@ class PlacementSpec(object):
     def __init__(self, label=None, nodes=[]):
         self.label = label
 
-        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)
-
         self.nodes = list(map(split_host, nodes))
 
 def handle_type_error(method):
index 9b402322ed468fdca1bb0f19a2f867529a46cc38..9f3741b228423b69f5d15fca8339b39387c88b28 100644 (file)
@@ -551,19 +551,9 @@ Usage:
             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))
+                hosts = list(map(orchestrator.split_host, hosts))
             except Exception as e:
                 msg = "Failed to parse host list: '{}': {}".format(hosts, e)
                 return HandleCommandResult(-errno.EINVAL, stderr=msg)
@@ -584,22 +574,9 @@ Usage:
             return HandleCommandResult(-errno.EINVAL,
                     stderr="Invalid number of mons: require {} > 0".format(num))
 
-        def split_host(host):
-            """Split host into host and network parts"""
-            # TODO: stricter validation
-            (host, name) = host.split('=', 1)
-            parts = host.split(":", 1)
-            if len(parts) == 1:
-                return (parts[0], None, name)
-            elif len(parts) == 2:
-                return (parts[0], parts[1], name)
-            else:
-                raise RuntimeError("Invalid host specification: "
-                        "'{}'".format(host))
-
         if hosts:
             try:
-                hosts = list(map(split_host, hosts))
+                hosts = list(map(orchestrator.split_host_with_network, hosts))
             except Exception as e:
                 msg = "Failed to parse host list: '{}': {}".format(hosts, e)
                 return HandleCommandResult(-errno.EINVAL, stderr=msg)