From b2bf7e5f2a793d3f3b9121a62966b576e5f0b95e Mon Sep 17 00:00:00 2001 From: Stamatis Katsaounis Date: Tue, 18 Sep 2018 11:51:45 +0300 Subject: Replace cinder client calls with openstack sdk JIRA: SDNVPN-220 This patch replaces all calls of cinder client with openstack sdk. Change-Id: Iee73a33ee6c2d87236c6bad3ea6a4ca7b100ced0 Signed-off-by: Stamatis Katsaounis --- sdnvpn/lib/openstack_utils.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/sdnvpn/lib/openstack_utils.py b/sdnvpn/lib/openstack_utils.py index bf78ef1..f379a6a 100644 --- a/sdnvpn/lib/openstack_utils.py +++ b/sdnvpn/lib/openstack_utils.py @@ -1210,44 +1210,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 -- cgit 1.2.3-korg