From aa3ceb31df148f5ebb185271b10e4fd60fac3db1 Mon Sep 17 00:00:00 2001 From: Periyasamy Palanisamy Date: Thu, 19 Oct 2017 14:34:19 +0200 Subject: use openstack api's instead of CLIs add two apis update_instance_quota_class and update_nw_subnet_port_quota and make run_sdnvpn_tests.py to use these APIs for setting quotas JIRA:SDNVPN-188 Change-Id: I764bb6897e6c4c5abad4d252c1f3b4ccc742d52e Signed-off-by: Periyasamy Palanisamy --- sdnvpn/lib/utils.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'sdnvpn/lib/utils.py') diff --git a/sdnvpn/lib/utils.py b/sdnvpn/lib/utils.py index e241d79..371f3ed 100644 --- a/sdnvpn/lib/utils.py +++ b/sdnvpn/lib/utils.py @@ -681,3 +681,49 @@ def is_fail_mode_secure(): 'in {} node'.format(openstack_node.name)) is_secure[openstack_node.name] = False return is_secure + + +def update_nw_subnet_port_quota(neutron_client, tenant_id, nw_quota, + subnet_quota, port_quota): + json_body = {"quota": { + "network": nw_quota, + "subnet": subnet_quota, + "port": port_quota + }} + + try: + neutron_client.update_quota(tenant_id=tenant_id, + body=json_body) + return True + except Exception as e: + logger.error("Error [update_nw_subnet_port_quota(neutron_client," + " '%s', '%s', '%s', '%s')]: %s" % + (tenant_id, nw_quota, subnet_quota, port_quota, e)) + return False + + +def update_instance_quota_class(nova_client, instances_quota): + try: + nova_client.quota_classes.update("default", instances=instances_quota) + return True + except Exception as e: + logger.error("Error [update_instance_quota_class(nova_client," + " '%s' )]: %s" % (instances_quota, e)) + return False + + +def get_neutron_quota(neutron_client, tenant_id): + try: + return neutron_client.show_quota(tenant_id=tenant_id)['quota'] + except Exception as e: + logger.error("Error in getting neutron quota for tenant " + " '%s' )]: %s" % (tenant_id, e)) + raise + + +def get_nova_instances_quota(nova_client): + try: + return nova_client.quota_classes.get("default").instances + except Exception as e: + logger.error("Error in getting nova instances quota: %s" % e) + raise -- cgit 1.2.3-korg