From 9a46b5c7796d4f7d90b1405ffe99724aab863e4a Mon Sep 17 00:00:00 2001 From: Miguel Caballer Date: Tue, 18 Jun 2024 10:10:29 +0200 Subject: [PATCH 1/3] Minor change in get volumes --- IM/connectors/OpenStack.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/IM/connectors/OpenStack.py b/IM/connectors/OpenStack.py index e84b67a0..731286a5 100644 --- a/IM/connectors/OpenStack.py +++ b/IM/connectors/OpenStack.py @@ -1184,8 +1184,7 @@ def get_networks(self, driver, radl): return nets - @staticmethod - def get_volumes(driver, image, volume, radl): + def get_volumes(self, driver, image, volume, radl): """ Create the required volumes (in the RADL) for the VM. @@ -1226,13 +1225,17 @@ def get_volumes(driver, image, volume, radl): disk_size = None if disk_url: - new_volume = driver.ex_get_volume(os.path.basename(disk_url)) + try: + new_volume_id = driver.ex_get_volume(os.path.basename(disk_url)).id + except Exception: + self.log_war("Error getting volume %s. Using ID." % disk_url) + new_volume_id = os.path.basename(disk_url) disk = { 'boot_index': cont, 'source_type': "volume", 'delete_on_termination': False, 'destination_type': "volume", - 'uuid': new_volume.id + 'uuid': new_volume_id } else: disk_size = system.getFeature("disk." + str(cont) + ".size").getValue('G') From 1a57f7cc976f47d07e29f6233566709732d4267b Mon Sep 17 00:00:00 2001 From: Miguel Caballer Date: Tue, 18 Jun 2024 10:11:29 +0200 Subject: [PATCH 2/3] Fix typo --- IM/connectors/OpenStack.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IM/connectors/OpenStack.py b/IM/connectors/OpenStack.py index 731286a5..d99d61ba 100644 --- a/IM/connectors/OpenStack.py +++ b/IM/connectors/OpenStack.py @@ -1228,7 +1228,7 @@ def get_volumes(self, driver, image, volume, radl): try: new_volume_id = driver.ex_get_volume(os.path.basename(disk_url)).id except Exception: - self.log_war("Error getting volume %s. Using ID." % disk_url) + self.log_warn("Error getting volume %s. Using ID." % disk_url) new_volume_id = os.path.basename(disk_url) disk = { 'boot_index': cont, From 9d751eb630f08afcc4b0092a0208aeefec4517c2 Mon Sep 17 00:00:00 2001 From: Miguel Caballer Date: Tue, 18 Jun 2024 10:33:17 +0200 Subject: [PATCH 3/3] Improve get_volume function --- IM/connectors/OpenStack.py | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/IM/connectors/OpenStack.py b/IM/connectors/OpenStack.py index d99d61ba..e375e4ca 100644 --- a/IM/connectors/OpenStack.py +++ b/IM/connectors/OpenStack.py @@ -472,7 +472,7 @@ def setVolumesInfo(self, vm, node): for vol_info in node.extra['volumes_attached']: vol_id = vol_info['id'] self.log_debug("Getting Volume info %s" % vol_id) - volume = node.driver.ex_get_volume(vol_id) + volume = self.get_volume(node.driver, vol_id) disk_size = None if vm.info.systems[0].getValue("disk." + str(cont) + ".size"): disk_size = vm.info.systems[0].getFeature("disk." + str(cont) + ".size").getValue('G') @@ -1226,7 +1226,7 @@ def get_volumes(self, driver, image, volume, radl): disk_size = None if disk_url: try: - new_volume_id = driver.ex_get_volume(os.path.basename(disk_url)).id + new_volume_id = self.get_volume(driver, os.path.basename(disk_url)).id except Exception: self.log_warn("Error getting volume %s. Using ID." % disk_url) new_volume_id = os.path.basename(disk_url) @@ -1306,7 +1306,7 @@ def launch(self, inf, radl, requested_radl, num_vm, auth_data): volume_id = self.get_volume_id(system.getValue("disk.0.image.url")) if not volume_id: raise Exception("Incorrect OpenStack image set.") - volume = driver.ex_get_volume(volume_id) + volume = self.get_volume(driver, volume_id) if not volume: raise Exception("Incorrect OpenStack volume id.") @@ -1723,7 +1723,7 @@ def finalize(self, vm, last, auth_data): for vol_id in vm.volumes: try: self.log_debug("Dettaching volume %s." % vol_id) - volume = node.driver.ex_get_volume(vol_id) + volume = self.get_volume(node.driver, vol_id) node.driver.detach_volume(volume) except Exception: self.log_exception("Error dettaching volume %s." % vol_id) @@ -1751,7 +1751,7 @@ def finalize(self, vm, last, auth_data): for vol_id in vm.volumes: volume = None try: - volume = node.driver.ex_get_volume(vol_id) + volume = self.get_volume(node.driver, vol_id) self.wait_volume(volume) except Exception: self.log_exception("Error getting volume ID: %s. No deleting it." % vol_id) @@ -1998,7 +1998,7 @@ def create_attach_volume(self, node, disk_size, disk_device, volume_name, locati # wait the volume to be attached success = self.wait_volume(volume, state='in-use') # update the volume data - volume = volume.driver.ex_get_volume(volume.id) + volume = self.get_volume(volume.driver, volume.id) return success, volume, "" def add_new_disks(self, vm, radl, auth_data): @@ -2182,3 +2182,20 @@ def get_quotas(self, auth_data): "limit": vol_quotas.gigabytes.limit} return quotas_dict + + def get_volume(self, driver, vol_id): + """ + Get the volume object, if it exists + """ + volume = None + try: + volume = driver.ex_get_volume(vol_id) + except Exception: + self.log_warn("Error getting volume ID using Cinder API: %s." % vol_id) + try: + volume = super(OpenStack_2_NodeDriver, driver).ex_get_volume(vol_id) + except Exception: + self.log_warn("Error getting volume ID using Nova API: %s." % vol_id) + if not volume: + raise Exception("Volume %s not found." % vol_id) + return volume