From 380fa8be6a180ffeec79c8ed4fc256966a47b9a2 Mon Sep 17 00:00:00 2001 From: dweinholz Date: Tue, 5 Jul 2022 09:40:40 +0200 Subject: [PATCH] fixed also for other image function --- .../VirtualMachineHandler.py | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/VirtualMachineService/VirtualMachineHandler.py b/VirtualMachineService/VirtualMachineHandler.py index cfb76f6a..1c7a25a3 100644 --- a/VirtualMachineService/VirtualMachineHandler.py +++ b/VirtualMachineService/VirtualMachineHandler.py @@ -1989,19 +1989,23 @@ def get_active_image_by_os_version(self, os_version, os_distro): LOG.info(f"Get active Image by os-version: {os_version}") images = self.conn.list_images() for image in images: - metadata = image["metadata"] - image_os_version = metadata.get("os_version", None) - image_os_distro = metadata.get("os_distro", None) - base_image_ref = metadata.get("base_image_ref", None) - if ( - os_version == image_os_version - and image.status == "active" - and base_image_ref is None - ): - if os_distro and os_distro == image_os_distro: - return image - elif os_distro is None: - return image + if image and image.status == "active": + image_os_version = image.get("os_version", None) + image_os_distro = image.get("os_distro", None) + metadata = image.get("metadata", {}) + base_image_ref = metadata.get("base_image_ref", None) + + if not image_os_distro or not image_os_version: + image_os_version = metadata.get("os_version", None) + image_os_distro = metadata.get("os_distro", None) + if ( + os_version == image_os_version + and base_image_ref is None + ): + if os_distro and os_distro == image_os_distro: + return image + elif os_distro is None: + return image return None def create_deactivate_update_script(self):