]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: add get_container_stats to container_types
authorJohn Mulligan <jmulligan@redhat.com>
Thu, 30 Jan 2025 23:48:42 +0000 (18:48 -0500)
committerJohn Mulligan <jmulligan@redhat.com>
Wed, 5 Feb 2025 18:13:06 +0000 (13:13 -0500)
We're in the process of trying to remove get_container_types from
cephadm.py. Most of the generic logic has been moved to
container_engines.py. However, the remaining parts of the current
get_container_stats rely on classes from container_types.py so add a
future replacement for the existing get_container_types to
container_types.py.

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

index 52a68888e78a249416933cfa67a1f524980d04d2..c38a27d8daab63a1e26a33de76e5deb68a825379 100644 (file)
@@ -10,7 +10,12 @@ from typing import Dict, List, Optional, Any, Union, Tuple, Iterable, cast
 from .call_wrappers import call, call_throws, CallVerbosity
 from .constants import DEFAULT_TIMEOUT
 from ceph.cephadm.images import DefaultImages
-from .container_engines import Docker, Podman
+from .container_engines import (
+    ContainerInfo,
+    Docker,
+    Podman,
+    parsed_container_stats,
+)
 from .context import CephadmContext
 from .daemon_identity import DaemonIdentity, DaemonSubIdentity
 from .exceptions import Error
@@ -670,3 +675,15 @@ def get_mgr_images() -> dict:
         f'{mgr_prefix}{image.key}': image.image_ref for image in DefaultImages
     }
     return mgr_images
+
+
+def get_container_stats(
+    ctx: CephadmContext, identity: DaemonIdentity, *, container_path: str = ''
+) -> Optional[ContainerInfo]:
+    """returns container id, image name, image id, created time, and ceph version if available"""
+    c = CephContainer.for_daemon(ctx, identity, 'bash')
+    for name in (c.cname, c.old_cname):
+        ci = parsed_container_stats(ctx, name, container_path=container_path)
+        if ci is not None:
+            return ci
+    return None