]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: Add MonService
authorSebastian Wagner <sebastian.wagner@suse.com>
Mon, 4 May 2020 11:51:15 +0000 (13:51 +0200)
committerSebastian Wagner <sebastian.wagner@suse.com>
Thu, 21 May 2020 21:33:18 +0000 (23:33 +0200)
Signed-off-by: Sebastian Wagner <sebastian.wagner@suse.com>
(cherry picked from commit e2ddfefaaa755abc58efde1b9e7756b04ee58154)

src/pybind/mgr/cephadm/module.py
src/pybind/mgr/cephadm/services/cephadmservice.py

index 269eaaaf92188f61388e6660bf7b53d891219ecd..75d359a911e9e7c7550268123cd74c4141205972 100644 (file)
@@ -38,6 +38,7 @@ from orchestrator import OrchestratorError, OrchestratorValidationError, HostSpe
 
 from . import remotes
 from . import utils
+from .services.cephadmservice import MonService
 from .services.nfs import NFSService
 from .services.osd import RemoveUtil, OSDRemoval, OSDService
 from .inventory import Inventory, SpecStore, HostCache
@@ -422,6 +423,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule):
         # services:
         self.osd_service = OSDService(self)
         self.nfs_service = NFSService(self)
+        self.mon_service = MonService(self)
 
     def shutdown(self):
         self.log.debug('shutdown')
@@ -1924,7 +1926,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule):
             return False
         self.log.debug('Applying service %s spec' % service_name)
         create_fns = {
-            'mon': self._create_mon,
+            'mon': self.mon_service.create,
             'mgr': self._create_mgr,
             'osd': self.create_osds,  # osds work a bit different.
             'mds': self._create_mds,
@@ -2174,48 +2176,9 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule):
     def apply_mon(self, spec):
         return self._apply(spec)
 
-    def _create_mon(self, name, host, network):
-        """
-        Create a new monitor on the given host.
-        """
-        # get mon. key
-        ret, keyring, err = self.check_mon_command({
-            'prefix': 'auth get',
-            'entity': 'mon.',
-        })
-
-        extra_config = '[mon.%s]\n' % name
-        if network:
-            # infer whether this is a CIDR network, addrvec, or plain IP
-            if '/' in network:
-                extra_config += 'public network = %s\n' % network
-            elif network.startswith('[v') and network.endswith(']'):
-                extra_config += 'public addrv = %s\n' % network
-            elif ':' not in network:
-                extra_config += 'public addr = %s\n' % network
-            else:
-                raise OrchestratorError('Must specify a CIDR network, ceph addrvec, or plain IP: \'%s\'' % network)
-        else:
-            # try to get the public_network from the config
-            ret, network, err = self.check_mon_command({
-                'prefix': 'config get',
-                'who': 'mon',
-                'key': 'public_network',
-            })
-            network = network.strip() # type: ignore
-            if not network:
-                raise OrchestratorError('Must set public_network config option or specify a CIDR network, ceph addrvec, or plain IP')
-            if '/' not in network:
-                raise OrchestratorError('public_network is set but does not look like a CIDR network: \'%s\'' % network)
-            extra_config += 'public network = %s\n' % network
-
-        return self._create_daemon('mon', name, host,
-                                   keyring=keyring,
-                                   extra_config={'config': extra_config})
-
     def add_mon(self, spec):
         # type: (ServiceSpec) -> orchestrator.Completion
-        return self._add_daemon('mon', spec, self._create_mon)
+        return self._add_daemon('mon', spec, self.mon_service.create)
 
     def _create_mgr(self, mgr_id, host):
         """
index 54cee3820654e0110c55056dc6de3564637d7151..3c088440638ad81fb5f75ceaad417a93e13cd274 100644 (file)
@@ -1,5 +1,7 @@
 from typing import  TYPE_CHECKING
 
+from orchestrator import OrchestratorError
+
 if TYPE_CHECKING:
     from cephadm.module import CephadmOrchestrator
 
@@ -9,4 +11,45 @@ class CephadmService:
     Base class for service types. Often providing a create() and config() fn.
     """
     def __init__(self, mgr: "CephadmOrchestrator"):
-        self.mgr: "CephadmOrchestrator" = mgr
\ No newline at end of file
+        self.mgr: "CephadmOrchestrator" = mgr
+
+
+class MonService(CephadmService):
+    def create(self, name, host, network):
+        """
+        Create a new monitor on the given host.
+        """
+        # get mon. key
+        ret, keyring, err = self.mgr.check_mon_command({
+            'prefix': 'auth get',
+            'entity': 'mon.',
+        })
+
+        extra_config = '[mon.%s]\n' % name
+        if network:
+            # infer whether this is a CIDR network, addrvec, or plain IP
+            if '/' in network:
+                extra_config += 'public network = %s\n' % network
+            elif network.startswith('[v') and network.endswith(']'):
+                extra_config += 'public addrv = %s\n' % network
+            elif ':' not in network:
+                extra_config += 'public addr = %s\n' % network
+            else:
+                raise OrchestratorError('Must specify a CIDR network, ceph addrvec, or plain IP: \'%s\'' % network)
+        else:
+            # try to get the public_network from the config
+            ret, network, err = self.mgr.check_mon_command({
+                'prefix': 'config get',
+                'who': 'mon',
+                'key': 'public_network',
+            })
+            network = network.strip() # type: ignore
+            if not network:
+                raise OrchestratorError('Must set public_network config option or specify a CIDR network, ceph addrvec, or plain IP')
+            if '/' not in network:
+                raise OrchestratorError('public_network is set but does not look like a CIDR network: \'%s\'' % network)
+            extra_config += 'public network = %s\n' % network
+
+        return self.mgr._create_daemon('mon', name, host,
+                                       keyring=keyring,
+                                       extra_config={'config': extra_config})
\ No newline at end of file