|
85 | 85 | concurrent_tasks, |
86 | 86 | ) |
87 | 87 | from cephadmlib.container_engines import ( |
| 88 | + ContainerInfo, |
88 | 89 | Podman, |
89 | 90 | check_container_engine, |
90 | 91 | find_container_engine, |
91 | | - parsed_container_mem_usage, |
92 | 92 | parsed_container_cpu_perc, |
| 93 | + parsed_container_image_stats, |
| 94 | + parsed_container_mem_usage, |
93 | 95 | pull_command, |
94 | 96 | registry_login, |
95 | 97 | ) |
|
146 | 148 | InitContainer, |
147 | 149 | SidecarContainer, |
148 | 150 | extract_uid_gid, |
149 | | - is_container_running, |
| 151 | + get_container_stats, |
150 | 152 | get_mgr_images, |
| 153 | + is_container_running, |
151 | 154 | ) |
152 | 155 | from cephadmlib.decorators import ( |
153 | 156 | deprecated_command, |
|
200 | 203 | ################################## |
201 | 204 |
|
202 | 205 |
|
203 | | -class ContainerInfo: |
204 | | - def __init__(self, container_id: str, |
205 | | - image_name: str, |
206 | | - image_id: str, |
207 | | - start: str, |
208 | | - version: str) -> None: |
209 | | - self.container_id = container_id |
210 | | - self.image_name = image_name |
211 | | - self.image_id = image_id |
212 | | - self.start = start |
213 | | - self.version = version |
214 | | - |
215 | | - def __eq__(self, other: Any) -> bool: |
216 | | - if not isinstance(other, ContainerInfo): |
217 | | - return NotImplemented |
218 | | - return (self.container_id == other.container_id |
219 | | - and self.image_name == other.image_name |
220 | | - and self.image_id == other.image_id |
221 | | - and self.start == other.start |
222 | | - and self.version == other.version) |
223 | | - |
224 | | -################################## |
225 | | - |
226 | | - |
227 | 206 | def get_supported_daemons(): |
228 | 207 | # type: () -> List[str] |
229 | 208 | supported_daemons = ceph_daemons() |
@@ -522,22 +501,16 @@ def daemon_name_or_type(daemon: Dict[str, str]) -> str: |
522 | 501 | # container will not help us. If we have the image name from the list_daemons output |
523 | 502 | # we can try that. |
524 | 503 | image_name = matching_daemons[0]['container_image_name'] |
525 | | - out, _, code = get_container_stats_by_image_name(ctx, ctx.container_engine.path, image_name) |
526 | | - if not code: |
527 | | - # keep in mind, the daemon container is not running, so no container id here |
528 | | - (image_id, start, version) = out.strip().split(',') |
529 | | - return ContainerInfo( |
530 | | - container_id='', |
531 | | - image_name=image_name, |
532 | | - image_id=image_id, |
533 | | - start=start, |
534 | | - version=version) |
| 504 | + cinfo = parsed_container_image_stats(ctx, image_name) |
| 505 | + if cinfo: |
| 506 | + return cinfo |
535 | 507 | else: |
536 | 508 | d_type, d_id = matching_daemons[0]['name'].split('.', 1) |
537 | | - out, _, code = get_container_stats(ctx, ctx.container_engine.path, ctx.fsid, d_type, d_id) |
538 | | - if not code: |
539 | | - (container_id, image_name, image_id, start, version) = out.strip().split(',') |
540 | | - return ContainerInfo(container_id, image_name, image_id, start, version) |
| 509 | + cinfo = get_container_stats( |
| 510 | + ctx, DaemonIdentity(ctx.fsid, d_type, d_id) |
| 511 | + ) |
| 512 | + if cinfo: |
| 513 | + return cinfo |
541 | 514 | return None |
542 | 515 |
|
543 | 516 |
|
@@ -3513,10 +3486,17 @@ def list_daemons( |
3513 | 3486 | version = None |
3514 | 3487 | start_stamp = None |
3515 | 3488 |
|
3516 | | - out, err, code = get_container_stats(ctx, container_path, fsid, daemon_type, daemon_id) |
3517 | | - if not code: |
3518 | | - (container_id, image_name, image_id, start, |
3519 | | - version) = out.strip().split(',') |
| 3489 | + cinfo = get_container_stats( |
| 3490 | + ctx, |
| 3491 | + DaemonIdentity(fsid, daemon_type, daemon_id), |
| 3492 | + container_path=container_path |
| 3493 | + ) |
| 3494 | + if cinfo: |
| 3495 | + container_id = cinfo.container_id |
| 3496 | + image_name = cinfo.image_name |
| 3497 | + image_id = cinfo.image_id |
| 3498 | + start = cinfo.start |
| 3499 | + version = cinfo.version |
3520 | 3500 | image_id = normalize_container_id(image_id) |
3521 | 3501 | daemon_type = name.split('.', 1)[0] |
3522 | 3502 | start_stamp = try_convert_datetime(start) |
@@ -3660,36 +3640,6 @@ def get_daemon_description(ctx, fsid, name, detail=False, legacy_dir=None): |
3660 | 3640 | return d |
3661 | 3641 | raise Error('Daemon not found: {}. See `cephadm ls`'.format(name)) |
3662 | 3642 |
|
3663 | | - |
3664 | | -def get_container_stats(ctx: CephadmContext, container_path: str, fsid: str, daemon_type: str, daemon_id: str) -> Tuple[str, str, int]: |
3665 | | - """returns container id, image name, image id, created time, and ceph version if available""" |
3666 | | - c = CephContainer.for_daemon( |
3667 | | - ctx, DaemonIdentity(fsid, daemon_type, daemon_id), 'bash' |
3668 | | - ) |
3669 | | - out, err, code = '', '', -1 |
3670 | | - for name in (c.cname, c.old_cname): |
3671 | | - cmd = [ |
3672 | | - container_path, 'inspect', |
3673 | | - '--format', '{{.Id}},{{.Config.Image}},{{.Image}},{{.Created}},{{index .Config.Labels "io.ceph.version"}}', |
3674 | | - name |
3675 | | - ] |
3676 | | - out, err, code = call(ctx, cmd, verbosity=CallVerbosity.QUIET) |
3677 | | - if not code: |
3678 | | - break |
3679 | | - return out, err, code |
3680 | | - |
3681 | | - |
3682 | | -def get_container_stats_by_image_name(ctx: CephadmContext, container_path: str, image_name: str) -> Tuple[str, str, int]: |
3683 | | - """returns image id, created time, and ceph version if available""" |
3684 | | - out, err, code = '', '', -1 |
3685 | | - cmd = [ |
3686 | | - container_path, 'image', 'inspect', |
3687 | | - '--format', '{{.Id}},{{.Created}},{{index .Config.Labels "io.ceph.version"}}', |
3688 | | - image_name |
3689 | | - ] |
3690 | | - out, err, code = call(ctx, cmd, verbosity=CallVerbosity.QUIET) |
3691 | | - return out, err, code |
3692 | | - |
3693 | 3643 | ################################## |
3694 | 3644 |
|
3695 | 3645 |
|
|
0 commit comments