diff options
author | Abdulwasiu Apalowo <abdulwasiuapalowo@gmail.com> | 2023-04-08 10:07:13 +0100 |
---|---|---|
committer | Abdulwasiu Apalowo <abdulwasiuapalowo@gmail.com> | 2023-05-03 15:09:02 +0100 |
commit | be011898d1944d2ddac75f429255e0c358a8a83b (patch) | |
tree | 1ab19c3ad33484995e3fa816acecb7ffc1d91378 | |
parent | 43f1d562f525f69116df43c857a51742c6ca9c4f (diff) | |
download | libvirt-ci-be011898d1944d2ddac75f429255e0c358a8a83b.zip libvirt-ci-be011898d1944d2ddac75f429255e0c358a8a83b.tar.gz libvirt-ci-be011898d1944d2ddac75f429255e0c358a8a83b.tar.bz2 |
containers: add tag parameter to image_exists method
Add :param image_tag: to :method image_exists: to clean
up the code.
Signed-off-by: Abdulwasiu Apalowo <abdulwasiuapalowo@gmail.com>
-rw-r--r-- | lcitool/containers/docker.py | 9 | ||||
-rw-r--r-- | lcitool/containers/podman.py | 8 |
2 files changed, 6 insertions, 11 deletions
diff --git a/lcitool/containers/docker.py b/lcitool/containers/docker.py index f260e99..f142550 100644 --- a/lcitool/containers/docker.py +++ b/lcitool/containers/docker.py @@ -53,24 +53,21 @@ class Docker(Container): log.debug(f"Deserialized {self.engine} images\n%s", images) return images - def image_exists(self, image_ref): + def image_exists(self, image_ref, image_tag): """ Check if image exists in docker. :param image_ref: name/id/registry-path of image to check (str). + :param image_tag: image tag (str). :returns: boolean """ - image_name, _, image_tag = image_ref.partition(':') - if not image_tag: - image_tag = "latest" - for img in self._images(): id = img.get("ID") img_repository = img.get("Repository") img_tag = img.get("Tag", "latest") - if id.startswith(image_ref) or (image_name == img_repository and image_tag == img_tag): + if id.startswith(image_ref) or (image_ref == img_repository and image_tag == img_tag): return True return False diff --git a/lcitool/containers/podman.py b/lcitool/containers/podman.py index 58779f5..749488a 100644 --- a/lcitool/containers/podman.py +++ b/lcitool/containers/podman.py @@ -128,18 +128,16 @@ class Podman(Container): log.debug(f"Deserialized {self.engine} images\n%s", images) return images - def image_exists(self, image_ref): + def image_exists(self, image_ref, image_tag): """ Check if image exists in podman. :param image_ref: name/id/registry-path of image to check (str). + :param image_tag: image tag (str). :returns: boolean """ - image_name, _, image_tag = image_ref.partition(':') - image_repository, _, image_name = image_name.rpartition('/') - if not image_tag: - image_tag = "latest" + image_repository, _, image_name = image_ref.rpartition('/') for img in self._images(): id = img.get("Id") |