Skip to content

Commit e965813

Browse files
cephadm: add parsed_container_image_stats to container_engines
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 <[email protected]>
1 parent 32fe8aa commit e965813

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

src/cephadm/cephadmlib/container_engines.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,3 +370,48 @@ def parsed_container_stats(
370370
ctx, container_name, container_path=container_path
371371
)
372372
return _parse_container_stats(out, err, code)
373+
374+
375+
def _container_image_stats(
376+
ctx: CephadmContext, image_name: str, *, container_path: str = ''
377+
) -> Tuple[str, str, int]:
378+
"""returns image id, created time, and ceph version if available"""
379+
container_path = container_path or ctx.container_engine.path
380+
cmd = [
381+
container_path,
382+
'image',
383+
'inspect',
384+
'--format',
385+
'{{.Id}},{{.Created}},{{index .Config.Labels "io.ceph.version"}}',
386+
image_name,
387+
]
388+
out, err, code = call(ctx, cmd, verbosity=CallVerbosity.QUIET)
389+
return out, err, code
390+
391+
392+
def _parse_container_image_stats(
393+
image_name: str,
394+
out: str,
395+
err: str,
396+
code: int,
397+
) -> Optional[ContainerInfo]:
398+
if code != 0:
399+
return None
400+
(image_id, start, version) = out.strip().split(',')
401+
# keep in mind, the daemon container is not running, so no container id here
402+
return ContainerInfo(
403+
container_id='',
404+
image_name=image_name,
405+
image_id=image_id,
406+
start=start,
407+
version=version,
408+
)
409+
410+
411+
def parsed_container_image_stats(
412+
ctx: CephadmContext, image_name: str, *, container_path: str = ''
413+
) -> Optional[ContainerInfo]:
414+
out, err, code = _container_image_stats(
415+
ctx, image_name, container_path=container_path
416+
)
417+
return _parse_container_image_stats(image_name, out, err, code)

0 commit comments

Comments
 (0)