AuthEntity = NewType('AuthEntity', str)
+def get_auth_entity(daemon_type: str, daemon_id: str, host: str = "") -> AuthEntity:
+ """
+ Map the daemon id to a cephx keyring entity name
+ """
+ # despite this mapping entity names to daemons, self.TYPE within
+ # the CephService class refers to service types, not daemon types
+ if daemon_type in ['rgw', 'rbd-mirror', 'cephfs-mirror', 'nfs', "iscsi", 'ingress']:
+ return AuthEntity(f'client.{daemon_type}.{daemon_id}')
+ elif daemon_type in ['crash', 'agent']:
+ if host == "":
+ raise OrchestratorError(
+ f'Host not provided to generate <{daemon_type}> auth entity name')
+ return AuthEntity(f'client.{daemon_type}.{host}')
+ elif daemon_type == 'mon':
+ return AuthEntity('mon.')
+ elif daemon_type in ['mgr', 'osd', 'mds']:
+ return AuthEntity(f'{daemon_type}.{daemon_id}')
+ else:
+ raise OrchestratorError(f"unknown daemon type {daemon_type}")
+
+
class CephadmDaemonDeploySpec:
# typing.NamedTuple + Generic is broken in py36
def __init__(self, host: str, daemon_id: str,
def name(self) -> str:
return '%s.%s' % (self.daemon_type, self.daemon_id)
+ def entity_name(self) -> str:
+ return get_auth_entity(self.daemon_type, self.daemon_id, host=self.host)
+
def config_get_files(self) -> Dict[str, Any]:
files = self.extra_files
if self.ceph_conf:
self.remove_keyring(daemon)
def get_auth_entity(self, daemon_id: str, host: str = "") -> AuthEntity:
- """
- Map the daemon id to a cephx keyring entity name
- """
- # despite this mapping entity names to daemons, self.TYPE within
- # the CephService class refers to service types, not daemon types
- if self.TYPE in ['rgw', 'rbd-mirror', 'cephfs-mirror', 'nfs', "iscsi", 'ingress']:
- return AuthEntity(f'client.{self.TYPE}.{daemon_id}')
- elif self.TYPE in ['crash', 'agent']:
- if host == "":
- raise OrchestratorError(
- f'Host not provided to generate <{self.TYPE}> auth entity name')
- return AuthEntity(f'client.{self.TYPE}.{host}')
- elif self.TYPE == 'mon':
- return AuthEntity('mon.')
- elif self.TYPE in ['mgr', 'osd', 'mds']:
- return AuthEntity(f'{self.TYPE}.{daemon_id}')
- else:
- raise OrchestratorError("unknown daemon type")
+ return get_auth_entity(self.TYPE, daemon_id, host=host)
def get_config_and_keyring(self,
daemon_type: str,
# get mon. key
ret, keyring, err = self.mgr.check_mon_command({
'prefix': 'auth get',
- 'entity': self.get_auth_entity(name),
+ 'entity': daemon_spec.entity_name(),
})
extra_config = '[mon.%s]\n' % name
ret, keyring, err = self.mgr.check_mon_command({
'prefix': 'auth get-or-create',
- 'entity': self.get_auth_entity(daemon_spec.daemon_id),
+ 'entity': daemon_spec.entity_name(),
'caps': ['mon', 'profile cephfs-mirror',
'mds', 'allow r',
'osd', 'allow rw tag cephfs metadata=*, allow r tag cephfs data=*',