X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=utils%2Fenv_prepare%2Fquota_prepare.py;h=367f76133bde27daadef58a44211c93e9b941f53;hb=316f53716106bbcff780761ee1d24a610cc0e925;hp=e52a3e32d6324ded2d46010d84c0ec9b4eb1a5b3;hpb=5938133db9d2a4a8796c45eeeeef2c74da3ddeba;p=bottlenecks.git diff --git a/utils/env_prepare/quota_prepare.py b/utils/env_prepare/quota_prepare.py index e52a3e32..367f7613 100644 --- a/utils/env_prepare/quota_prepare.py +++ b/utils/env_prepare/quota_prepare.py @@ -21,7 +21,10 @@ neutron_quota = {"subnet": -1, "floatingip": -1, "subnetpool": -1, "router": -1, - "port": -1} + "port": -1, + "security_group": -1, + "security_group_rule": -1, + "rbac_policy": -1} nova_quota = {"ram": -1, "cores": -1, @@ -39,18 +42,52 @@ nova_quota = {"ram": -1, "injected_file_path_bytes": -1} +def check_https_enabled(): + LOG.debug("Check if https is enabled in OpenStack") + os_auth_url = os.getenv('OS_AUTH_URL') + if os_auth_url.startswith('https'): + LOG.debug("https is enabled") + return True + LOG.debug("https is not enabled") + return False + + def quota_env_prepare(): - tenant_name = os.getenv("OS_TENANT_NAME") - cmd = ("openstack project list | grep " + - tenant_name + - " | awk '{print $2}'") + https_enabled = check_https_enabled() + insecure_option = '' + insecure = os.getenv('OS_INSECURE',) + if https_enabled: + LOG.info("https is enabled") + if insecure: + if insecure.lower() == "true": + insecure_option = ' --insecure ' + else: + LOG.warn("Env variable OS_INSECURE is {}: if https + no " + "credential used, it should be set as True." + .format(insecure)) - result = commands.getstatusoutput(cmd) - if result[0] == 0: - LOG.info(result[1]) + quota_name = os.getenv("OS_PROJECT_NAME") + if quota_name: + cmd = ("openstack {} project list | grep ".format(insecure_option) + + quota_name + + " | awk '{print $2}'") + result = commands.getstatusoutput(cmd) + if result[0] == 0 and 'exception' not in result[1]: + LOG.info("Get %s project name is %s" % (quota_name, result[1])) + else: + LOG.error("can't get openstack project name") + return 1 else: - LOG.error("can't get openstack project id") - return 1 + quota_name = os.getenv("OS_TENANT_NAME") + cmd = ("openstack {} tenant list | grep ".format(insecure_option) + + quota_name + + " | awk '{print $2}'") + result = commands.getstatusoutput(cmd) + if result[0] == 0 and 'exception' not in result[1]: + LOG.info("Get %s tenant name is %s" % (quota_name, result[1])) + else: + LOG.error("can't get openstack tenant name") + return 1 openstack_id = result[1] @@ -59,7 +96,7 @@ def quota_env_prepare(): nova_q = nova_client.quotas.get(openstack_id).to_dict() neutron_q = neutron_client.show_quota(openstack_id) - LOG.info(tenant_name + "tenant nova and neutron quota(previous) :") + LOG.info(quota_name + " nova and neutron quotas (previous) :") LOG.info(nova_q) LOG.info(neutron_q) @@ -70,7 +107,7 @@ def quota_env_prepare(): nova_q = nova_client.quotas.get(openstack_id).to_dict() neutron_q = neutron_client.show_quota(openstack_id) - LOG.info(tenant_name + "tenant nova and neutron quota(now) :") + LOG.info(quota_name + " nova and neutron quotas (now) :") LOG.info(nova_q) LOG.info(neutron_q) return 0