]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
cephadm: add a container copying method
authorJohn Mulligan <jmulligan@redhat.com>
Fri, 29 Sep 2023 19:34:28 +0000 (15:34 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Tue, 2 Jan 2024 14:30:20 +0000 (09:30 -0500)
Add a method for duplicating the container properties into a new object.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/cephadm/cephadmlib/container_types.py

index 7ec323acf314e6873ecd8171044e8f6823229f35..7bddecb6516cb51cb19eaa722d0edfe060cd58ea 100644 (file)
@@ -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__(