mgr/cephadm: add utils.py

move `name_to_config_section` and `assert_valid_host` into utils.py

Signed-off-by: Michael Fritch <mfritch@suse.com>
This commit is contained in:
Michael Fritch 2020-03-16 22:47:36 -06:00
parent 084fd4a91a
commit 322eea8099
No known key found for this signature in database
GPG Key ID: 75F3EB2E80A03B7F
4 changed files with 25 additions and 20 deletions

View File

@ -3,4 +3,4 @@ import os
if 'UNITTEST' in os.environ:
import tests
from .module import CephadmOrchestrator, name_to_config_section
from .module import CephadmOrchestrator

View File

@ -40,6 +40,7 @@ from orchestrator import OrchestratorError, OrchestratorValidationError, HostSpe
CLICommandMeta
from . import remotes
from . import utils
from .nfs import NFSGanesha
from .osd import RemoveUtil, OSDRemoval
@ -97,19 +98,6 @@ except ImportError:
self.cleanup()
def name_to_config_section(name):
"""
Map from daemon names to ceph entity names (as seen in config)
"""
daemon_type = name.split('.', 1)[0]
if daemon_type in ['rgw', 'rbd-mirror', 'nfs', 'crash']:
return 'client.' + name
elif daemon_type in ['mon', 'osd', 'mds', 'mgr', 'client']:
return name
else:
return 'mon'
class SpecStore():
def __init__(self, mgr):
# type: (CephadmOrchestrator) -> None
@ -907,7 +895,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule):
'prefix': 'config set',
'name': 'container_image',
'value': target_name,
'who': name_to_config_section(daemon_type + '.' + d.daemon_id),
'who': utils.name_to_config_section(daemon_type + '.' + d.daemon_id),
})
self._daemon_action(
d.daemon_type,
@ -971,7 +959,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule):
})
to_clean = []
for section in image_settings.keys():
if section.startswith(name_to_config_section(daemon_type) + '.'):
if section.startswith(utils.name_to_config_section(daemon_type) + '.'):
to_clean.append(section)
if to_clean:
self.log.debug('Upgrade: Cleaning up container_image for %s...' %
@ -998,7 +986,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule):
ret, image, err = self.mon_command({
'prefix': 'config rm',
'name': 'container_image',
'who': name_to_config_section(daemon_type),
'who': utils.name_to_config_section(daemon_type),
})
self.log.info('Upgrade: Complete!')
@ -1587,7 +1575,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule):
# get container image
ret, image, err = self.mon_command({
'prefix': 'config get',
'who': name_to_config_section(entity),
'who': utils.name_to_config_section(entity),
'key': 'container_image',
})
image = image.strip() # type: ignore
@ -2229,7 +2217,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule):
if daemon_type == 'mon':
ename = 'mon.'
else:
ename = name_to_config_section(daemon_type + '.' + daemon_id)
ename = utils.name_to_config_section(daemon_type + '.' + daemon_id)
ret, keyring, err = self.mon_command({
'prefix': 'auth get',
'entity': ename,

View File

@ -7,6 +7,8 @@ from ceph.deployment.service_spec import NFSServiceSpec
import cephadm
from orchestrator import OrchestratorError
from . import utils
logger = logging.getLogger(__name__)
class NFSGanesha(object):
@ -41,7 +43,7 @@ class NFSGanesha(object):
def get_keyring_entity(self):
# type: () -> str
return cephadm.name_to_config_section(self.get_rados_user())
return utils.name_to_config_section(self.get_rados_user())
def get_or_create_keyring(self, entity=None):
# type: (Optional[str]) -> str

View File

@ -0,0 +1,15 @@
import re
from orchestrator import OrchestratorError
def name_to_config_section(name):
"""
Map from daemon names to ceph entity names (as seen in config)
"""
daemon_type = name.split('.', 1)[0]
if daemon_type in ['rgw', 'rbd-mirror', 'nfs', 'crash']:
return 'client.' + name
elif daemon_type in ['mon', 'osd', 'mds', 'mgr', 'client']:
return name
else:
return 'mon'