From fd4bf1e235fe586296da9dd65e8f45c8880cfb48 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Thu, 22 Jun 2023 16:18:03 -0400 Subject: [PATCH] cephadm: add identity field to CephContainer Add an optional identity field based on the new DaemonIdentity type to help name/identify the CephContainers. I would have preferred to make this field mandatory but there are so many places in the code that call CephContainer now, I didn't want to have to touch them all at once. CephContainer objects created using the for_daemon classmethod *will* all have DaemonIdentity set. Signed-off-by: John Mulligan --- src/cephadm/cephadm.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/cephadm/cephadm.py b/src/cephadm/cephadm.py index a4bbd932cc6c2..ea4c736478a3b 100755 --- a/src/cephadm/cephadm.py +++ b/src/cephadm/cephadm.py @@ -4627,6 +4627,7 @@ class CephContainer(BasicContainer): entrypoint: str, args: List[str] = [], volume_mounts: Dict[str, str] = {}, + identity: Optional['DaemonIdentity'] = None, cname: str = '', container_args: List[str] = [], envs: Optional[List[str]] = None, @@ -4643,6 +4644,7 @@ class CephContainer(BasicContainer): self.entrypoint = entrypoint self.args = args self.volume_mounts = volume_mounts + self.identity = identity self._cname = cname self.container_args = container_args self.envs = envs or [] @@ -4676,13 +4678,14 @@ class CephContainer(BasicContainer): memory_request: Optional[str] = None, memory_limit: Optional[str] = None, ) -> 'CephContainer': + ident = DaemonIdentity(fsid, daemon_type, daemon_id) return cls( ctx, image=ctx.image, entrypoint=entrypoint, args=args, volume_mounts=volume_mounts, - cname='ceph-%s-%s.%s' % (fsid, daemon_type, daemon_id), + identity=ident, container_args=container_args, envs=envs, privileged=privileged, @@ -4714,6 +4717,8 @@ class CephContainer(BasicContainer): Fascinatingly, this doesn't happen when using dashes. """ + if not self._cname and self.identity: + return self.identity.container_name return self._cname.replace('.', '-') @cname.setter @@ -4722,6 +4727,8 @@ class CephContainer(BasicContainer): @property def old_cname(self) -> str: + if not self._cname and self.identity: + return self.identity.legacy_container_name return self._cname def run_cmd(self) -> List[str]: -- 2.39.5