]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: add parsed_container_stats to container_engines
authorJohn Mulligan <jmulligan@redhat.com>
Thu, 30 Jan 2025 23:48:26 +0000 (18:48 -0500)
committerJohn Mulligan <jmulligan@redhat.com>
Wed, 5 Feb 2025 18:13:06 +0000 (13:13 -0500)
Add a new function that combines the call and parse operations that
exist in cephadm.py (currently get_container_stats and related parsing
code).. This will be used in a future commit to replace that code and
reduce the size of cephadm.py.

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

index 9eb2f622b8f17f73a426de3bdb28ab7c280a2b9d..6bc896bcd8a4db8e0f832a5e1e23feccd910f40b 100644 (file)
@@ -329,3 +329,44 @@ class ContainerInfo:
             and self.start == other.start
             and self.version == other.version
         )
+
+
+def _container_stats(
+    ctx: CephadmContext,
+    container_name: str,
+    *,
+    container_path: str,
+) -> Tuple[str, str, int]:
+    """returns container id, image name, image id, created time, and ceph version if available"""
+    container_path = container_path or ctx.container_engine.path
+    out, err, code = '', '', -1
+    cmd = [
+        container_path,
+        'inspect',
+        '--format',
+        '{{.Id}},{{.Config.Image}},{{.Image}},{{.Created}},{{index .Config.Labels "io.ceph.version"}}',
+        container_name,
+    ]
+    out, err, code = call(ctx, cmd, verbosity=CallVerbosity.QUIET)
+    return out, err, code
+
+
+def _parse_container_stats(
+    out: str, err: str, code: int
+) -> Optional[ContainerInfo]:
+    if code != 0:
+        return None
+    # container_id, image_name, image_id, start, version
+    return ContainerInfo(*list(out.strip().split(',')))
+
+
+def parsed_container_stats(
+    ctx: CephadmContext,
+    container_name: str,
+    *,
+    container_path: str,
+) -> Optional[ContainerInfo]:
+    out, err, code = _container_stats(
+        ctx, container_name, container_path=container_path
+    )
+    return _parse_container_stats(out, err, code)