Skip to content

Commit

Permalink
Improve get_volume function
Browse files Browse the repository at this point in the history
  • Loading branch information
micafer committed Jun 18, 2024
1 parent 1a57f7c commit 9d751eb
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions IM/connectors/OpenStack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.")

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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

0 comments on commit 9d751eb

Please sign in to comment.