From 9b817f0214db70ec5bef941dcc62f3458117980b Mon Sep 17 00:00:00 2001 From: dweinholz Date: Tue, 5 Jul 2022 10:11:21 +0200 Subject: [PATCH] fixed baseref --- .../VirtualMachineHandler.py | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/VirtualMachineService/VirtualMachineHandler.py b/VirtualMachineService/VirtualMachineHandler.py index 1c7a25a3..2556c576 100644 --- a/VirtualMachineService/VirtualMachineHandler.py +++ b/VirtualMachineService/VirtualMachineHandler.py @@ -1992,12 +1992,14 @@ def get_active_image_by_os_version(self, os_version, os_distro): 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) + metadata = image.get("metadata", None) + base_image_ref = None + if 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 @@ -2040,9 +2042,13 @@ def add_cluster_machine( image_os_version = image.get("os_version", None) image_os_distro = image.get("os_distro", None) if not image_os_distro or not image_os_version: - metadata = image.get("metadata", {}) - image_os_version = metadata.get("os_version", "ubuntu") - image_os_distro = metadata.get("os_distro", "1804") + metadata = image.get("metadata", None) + if metadata: + image_os_version = metadata.get("os_version", "ubuntu") + image_os_distro = metadata.get("os_distro", "1804") + else: + image_os_version = "ubuntu" + image_os_distro = "1804" image = self.get_active_image_by_os_version( os_version=image_os_version, os_distro=image_os_distro )