summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDimitris Tsiolakis <dmts@intracom-telecom.com>2018-10-09 14:21:25 +0000
committerGerrit Code Review <gerrit@opnfv.org>2018-10-09 14:21:25 +0000
commit9c5b191165018cd43f7acb076903619f4681ce23 (patch)
treeac9958523a0daf4a286b7fdb493f7661254609cf
parentebf6885a907379083b360ae729f69151c1dd8115 (diff)
parentb2bf7e5f2a793d3f3b9121a62966b576e5f0b95e (diff)
Merge "Replace cinder client calls with openstack sdk"
-rw-r--r--sdnvpn/lib/openstack_utils.py25
1 files changed, 14 insertions, 11 deletions
diff --git a/sdnvpn/lib/openstack_utils.py b/sdnvpn/lib/openstack_utils.py
index 9126eeb..fc36c5b 100644
--- a/sdnvpn/lib/openstack_utils.py
+++ b/sdnvpn/lib/openstack_utils.py
@@ -1165,44 +1165,47 @@ def delete_glance_image(conn, image_id):
# *********************************************
# CINDER
# *********************************************
-def get_volumes(cinder_client):
+def get_volumes(conn):
try:
- volumes = cinder_client.volumes.list(search_opts={'all_tenants': 1})
+ volumes = conn.block_store.volumes(all_tenants=1)
return volumes
except Exception as e:
- logger.error("Error [get_volumes(cinder_client)]: %s" % e)
+ logger.error("Error [get_volumes(volume)]: %s" % e)
return None
-def update_cinder_quota(cinder_client, tenant_id, vols_quota,
+def update_cinder_quota(cloud, tenant_id, vols_quota,
snapshots_quota, gigabytes_quota):
quotas_values = {"volumes": vols_quota,
"snapshots": snapshots_quota,
"gigabytes": gigabytes_quota}
try:
- cinder_client.quotas.update(tenant_id, **quotas_values)
+ cloud.set_volume_quotas(tenant_id, **quotas_values)
return True
except Exception as e:
- logger.error("Error [update_cinder_quota(cinder_client, '%s', '%s', "
+ logger.error("Error [update_cinder_quota(volume, '%s', '%s', "
"'%s' '%s')]: %s" % (tenant_id, vols_quota,
snapshots_quota, gigabytes_quota, e))
return False
-def delete_volume(cinder_client, volume_id, forced=False):
+def delete_volume(cloud, volume_id, forced=False):
try:
if forced:
try:
- cinder_client.volumes.detach(volume_id)
+ volume = cloud.get_volume(volume_id)
+ for attachment in volume.attachments:
+ server = cloud.get_server(attachment.server_id)
+ cloud.detach_volume(server, volume)
except:
logger.error(sys.exc_info()[0])
- cinder_client.volumes.force_delete(volume_id)
+ cloud.delete_volume(volume_id, force=True)
else:
- cinder_client.volumes.delete(volume_id)
+ cloud.delete_volume(volume_id)
return True
except Exception as e:
- logger.error("Error [delete_volume(cinder_client, '%s', '%s')]: %s"
+ logger.error("Error [delete_volume(volume, '%s', '%s')]: %s"
% (volume_id, str(forced), e))
return False