2 ##############################################################################
3 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
14 import utils.logger as log
15 import utils.infra_setup.heat.manager as client_manager
17 LOG = log.Logger(__name__).getLogger()
19 neutron_quota = {"subnet": -1,
26 "security_group_rule": -1,
30 "flow_classifier": -1,
31 "port_pair_group": -1}
33 nova_quota = {"ram": -1,
42 "security_groups": -1,
43 "security_group_rules": -1,
44 "server_group_members": -1,
45 "injected_file_content_bytes": -1,
46 "injected_file_path_bytes": -1}
49 def quota_env_prepare():
50 tenant_name = os.getenv("OS_TENANT_NAME")
51 cmd = ("openstack project list | grep " +
53 " | awk '{print $2}'")
55 result = commands.getstatusoutput(cmd)
57 LOG.info("Get %s project id is %s" % (tenant_name, result[1]))
59 LOG.error("can't get openstack project id")
62 openstack_id = result[1]
64 nova_client = client_manager._get_nova_client()
65 neutron_client = client_manager._get_neutron_client()
67 nova_q = nova_client.quotas.get(openstack_id).to_dict()
68 neutron_q = neutron_client.show_quota(openstack_id)
69 LOG.info(tenant_name + "tenant nova and neutron quota(previous) :")
73 nova_client.quotas.update(openstack_id, **nova_quota)
74 neutron_client.update_quota(openstack_id,
75 {'quota': neutron_quota})
76 LOG.info("Quota has been changed!")
78 nova_q = nova_client.quotas.get(openstack_id).to_dict()
79 neutron_q = neutron_client.show_quota(openstack_id)
80 LOG.info(tenant_name + "tenant nova and neutron quota(now) :")