]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: add parsed_container_image_stats to container_engines
authorJohn Mulligan <jmulligan@redhat.com>
Fri, 31 Jan 2025 00:04:32 +0000 (19:04 -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_by_image_name 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 6bc896bcd8a4db8e0f832a5e1e23feccd910f40b..9b308fdd4174eb7577ca4526531c4618425b2ed3 100644 (file)
@@ -370,3 +370,48 @@ def parsed_container_stats(
         ctx, container_name, container_path=container_path
     )
     return _parse_container_stats(out, err, code)
+
+
+def _container_image_stats(
+    ctx: CephadmContext, image_name: str, *, container_path: str = ''
+) -> Tuple[str, str, int]:
+    """returns image id, created time, and ceph version if available"""
+    container_path = container_path or ctx.container_engine.path
+    cmd = [
+        container_path,
+        'image',
+        'inspect',
+        '--format',
+        '{{.Id}},{{.Created}},{{index .Config.Labels "io.ceph.version"}}',
+        image_name,
+    ]
+    out, err, code = call(ctx, cmd, verbosity=CallVerbosity.QUIET)
+    return out, err, code
+
+
+def _parse_container_image_stats(
+    image_name: str,
+    out: str,
+    err: str,
+    code: int,
+) -> Optional[ContainerInfo]:
+    if code != 0:
+        return None
+    (image_id, start, version) = out.strip().split(',')
+    # keep in mind, the daemon container is not running, so no container id here
+    return ContainerInfo(
+        container_id='',
+        image_name=image_name,
+        image_id=image_id,
+        start=start,
+        version=version,
+    )
+
+
+def parsed_container_image_stats(
+    ctx: CephadmContext, image_name: str, *, container_path: str = ''
+) -> Optional[ContainerInfo]:
+    out, err, code = _container_image_stats(
+        ctx, image_name, container_path=container_path
+    )
+    return _parse_container_image_stats(image_name, out, err, code)