From 517d8fb2c919aabd4b4b4ec1cb4b3dd69accbcd7 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Fri, 29 Sep 2023 15:34:28 -0400 Subject: [PATCH] cephadm: add a container copying method Add a method for duplicating the container properties into a new object. Signed-off-by: John Mulligan --- src/cephadm/cephadmlib/container_types.py | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/cephadm/cephadmlib/container_types.py b/src/cephadm/cephadmlib/container_types.py index 7ec323acf314e..7bddecb6516cb 100644 --- a/src/cephadm/cephadmlib/container_types.py +++ b/src/cephadm/cephadmlib/container_types.py @@ -1,5 +1,6 @@ # container_types.py - container instance wrapper types +import copy import os from typing import Dict, List, Optional, Any, Union, Tuple @@ -179,6 +180,33 @@ class BasicContainer: cmd.append(cname or self.cname) return cmd + @classmethod + def from_container( + cls, + other: 'BasicContainer', + *, + ident: Optional[DaemonIdentity] = None + ) -> 'BasicContainer': + return cls( + other.ctx, + image=other.image, + entrypoint=other.entrypoint, + identity=(ident or other.identity), + args=other.args, + container_args=copy.copy(other.container_args), + envs=copy.copy(other.envs), + volume_mounts=copy.copy(other.volume_mounts), + bind_mounts=copy.copy(other.bind_mounts), + network=other.network, + ipc=other.ipc, + init=other.init, + ptrace=other.ptrace, + privileged=other.privileged, + remove=other.remove, + memory_request=other.memory_request, + memory_limit=other.memory_limit, + ) + class CephContainer(BasicContainer): def __init__( -- 2.39.5