From: John Mulligan Date: Fri, 7 Feb 2025 16:29:40 +0000 (-0500) Subject: cephadm: move normalize_conatiner_id function to container_engines.py X-Git-Tag: v20.3.0~256^2~9 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=6c6c51dea20b7fd7500df2ac77d35f95cc6446d2;p=ceph.git cephadm: move normalize_conatiner_id function to container_engines.py The container_engines.py is the current home of functions related to generic container engine (podman & docker) stuff. The normalize_conatiner_id is a function from stripping the hash type prefix from digests and thus easily fits that description. Signed-off-by: John Mulligan --- diff --git a/src/cephadm/cephadm.py b/src/cephadm/cephadm.py index 4529ade7e33..86b8deca24d 100755 --- a/src/cephadm/cephadm.py +++ b/src/cephadm/cephadm.py @@ -89,6 +89,7 @@ from cephadmlib.container_engines import ( Podman, check_container_engine, find_container_engine, + normalize_container_id, parsed_container_cpu_perc, parsed_container_image_stats, parsed_container_mem_usage, @@ -275,18 +276,6 @@ def generate_password(): for i in range(10)) -def normalize_container_id(i): - # type: (str) -> str - # docker adds the sha256: prefix, but AFAICS both - # docker (18.09.7 in bionic at least) and podman - # both always use sha256, so leave off the prefix - # for consistency. - prefix = 'sha256:' - if i.startswith(prefix): - i = i[len(prefix):] - return i - - def make_fsid(): # type: () -> str return str(uuid.uuid1()) diff --git a/src/cephadm/cephadmlib/container_engines.py b/src/cephadm/cephadmlib/container_engines.py index 9b308fdd417..1e17c337980 100644 --- a/src/cephadm/cephadmlib/container_engines.py +++ b/src/cephadm/cephadmlib/container_engines.py @@ -415,3 +415,18 @@ def parsed_container_image_stats( ctx, image_name, container_path=container_path ) return _parse_container_image_stats(image_name, out, err, code) + + +def normalize_container_id(i: str) -> str: + # docker adds the sha256: prefix, but AFAICS both + # docker (18.09.7 in bionic at least) and podman + # both always use sha256, so leave off the prefix + # for consistency. + # --- + # (JJM) This is not a good idea and cephadm should move away from stripping + # the hash-type prefix. This is there so that docker/OCI can eventually + # move hash types if need be. Removing it breaks hash agility! + prefix = 'sha256:' + if i.startswith(prefix): + i = i[len(prefix) :] + return i