From: Sebastian Wagner Date: Mon, 4 May 2020 11:51:15 +0000 (+0200) Subject: mgr/cephadm: Add MonService X-Git-Tag: v16.1.0~2396^2~10 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e2ddfefaaa755abc58efde1b9e7756b04ee58154;p=ceph.git mgr/cephadm: Add MonService Signed-off-by: Sebastian Wagner --- diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 269eaaaf9218..75d359a911e9 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -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): """ diff --git a/src/pybind/mgr/cephadm/services/cephadmservice.py b/src/pybind/mgr/cephadm/services/cephadmservice.py index 54cee3820654..3c088440638a 100644 --- a/src/pybind/mgr/cephadm/services/cephadmservice.py +++ b/src/pybind/mgr/cephadm/services/cephadmservice.py @@ -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