Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor change in get volumes #1577

Merged
merged 3 commits into from
Jun 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 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 @@ -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.

Expand Down Expand Up @@ -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 = 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)
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')
Expand Down Expand Up @@ -1303,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 @@ -1720,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 @@ -1748,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 @@ -1995,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 @@ -2179,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