Skip to content

Commit cc087cf

Browse files
cephadm: add parsed_container_stats to container_engines
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 <[email protected]>
1 parent bc61710 commit cc087cf

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/cephadm/cephadmlib/container_engines.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,3 +329,44 @@ def __eq__(self, other: Any) -> bool:
329329
and self.start == other.start
330330
and self.version == other.version
331331
)
332+
333+
334+
def _container_stats(
335+
ctx: CephadmContext,
336+
container_name: str,
337+
*,
338+
container_path: str,
339+
) -> Tuple[str, str, int]:
340+
"""returns container id, image name, image id, created time, and ceph version if available"""
341+
container_path = container_path or ctx.container_engine.path
342+
out, err, code = '', '', -1
343+
cmd = [
344+
container_path,
345+
'inspect',
346+
'--format',
347+
'{{.Id}},{{.Config.Image}},{{.Image}},{{.Created}},{{index .Config.Labels "io.ceph.version"}}',
348+
container_name,
349+
]
350+
out, err, code = call(ctx, cmd, verbosity=CallVerbosity.QUIET)
351+
return out, err, code
352+
353+
354+
def _parse_container_stats(
355+
out: str, err: str, code: int
356+
) -> Optional[ContainerInfo]:
357+
if code != 0:
358+
return None
359+
# container_id, image_name, image_id, start, version
360+
return ContainerInfo(*list(out.strip().split(',')))
361+
362+
363+
def parsed_container_stats(
364+
ctx: CephadmContext,
365+
container_name: str,
366+
*,
367+
container_path: str,
368+
) -> Optional[ContainerInfo]:
369+
out, err, code = _container_stats(
370+
ctx, container_name, container_path=container_path
371+
)
372+
return _parse_container_stats(out, err, code)

0 commit comments

Comments
 (0)