From 3154cd228ba836a3925d06e81d2cdb4e15b71aa0 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Thu, 30 Jan 2025 18:48:42 -0500 Subject: [PATCH] cephadm: add get_container_stats to container_types 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 --- src/cephadm/cephadmlib/container_types.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/cephadm/cephadmlib/container_types.py b/src/cephadm/cephadmlib/container_types.py index 52a68888e78..c38a27d8daa 100644 --- a/src/cephadm/cephadmlib/container_types.py +++ b/src/cephadm/cephadmlib/container_types.py @@ -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 -- 2.39.5