From: John Mulligan Date: Fri, 29 Sep 2023 19:34:28 +0000 (-0400) Subject: cephadm: add a container copying method X-Git-Tag: v19.3.0~284^2~31 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=517d8fb2c919aabd4b4b4ec1cb4b3dd69accbcd7;p=ceph-ci.git cephadm: add a container copying method Add a method for duplicating the container properties into a new object. Signed-off-by: John Mulligan --- diff --git a/src/cephadm/cephadmlib/container_types.py b/src/cephadm/cephadmlib/container_types.py index 7ec323acf31..7bddecb6516 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__(