Skip to content

Commit

Permalink
We will use default-project to store default quotas. If quota is not …
Browse files Browse the repository at this point in the history
…set for a particular resource, we should not check its values in default-project

We will need corresponding fix in api server for this to work

Change-Id: I164e871fbed8cd3c172084377c228a63e6b01a1f
Partial-Bug: 1363914
(cherry picked from commit 7e9ed18)
  • Loading branch information
Sachin Bansal committed Oct 1, 2014
1 parent 53a43c4 commit cb5251d
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions neutron_plugin_contrail/plugins/opencontrail/quota/driver.py
Expand Up @@ -87,6 +87,17 @@ def limit_check(self, context, tenant_id,

@classmethod
def get_tenant_quotas(cls, context, resources, tenant_id):
try:
default_project = cls._get_vnc_conn().project_read(
fq_name=['default-domain', 'default-project'])
default_quota = default_project.get_quota()
except vnc_exc.NoIdError:
default_quota = None
return cls._get_tenant_quotas(context, resources, tenant_id,
default_quota)

@classmethod
def _get_tenant_quotas(cls, context, resources, tenant_id, default_quota):
try:
proj_id = str(uuid.UUID(tenant_id))
proj_obj = cls._get_vnc_conn().project_read(id=proj_id)
Expand All @@ -100,21 +111,34 @@ def get_tenant_quotas(cls, context, resources, tenant_id):
qn2c = cls.quota_neutron_to_contrail_type
quotas = {}
for resource in resources:
quota_res = None
if quota and resource in qn2c:
quota_res = getattr(quota, qn2c[resource], None)
if quota_res is None and default_quota and resource in qn2c:
quota_res = getattr(default_quota, qn2c[resource], None)
if quota_res is None:
quota_res = quota.get_defaults()
quotas[resource] = quota_res
else:
quotas[resource] = resources[resource].default
quota_res = default_quota.get_defaults()
if quota_res is None:
quota_res = resources[resource].default
quotas[resource] = quota_res
return quotas

@classmethod
def get_all_quotas(cls, context, resources):
try:
default_project = cls._get_vnc_conn().project_read(
fq_name=['default-domain', 'default-project'])
default_quota = default_project.get_quota()
except vnc_exc.NoIdError:
default_quota = None

project_list = cls._get_vnc_conn().projects_list()['projects']
ret_list = []
for project in project_list:
quotas = cls.get_tenant_quotas(context, resources, project['uuid'])
if default_quota and (project['uuid'] == default_project.uuid):
continue
quotas = cls._get_tenant_quotas(context, resources, project['uuid'].
default_quota)
quotas['tenant_id'] = project['uuid']
ret_list.append(quotas)
return ret_list
Expand All @@ -133,7 +157,7 @@ def delete_tenant_quota(cls, context, tenant_id):

for k,v in quota.__dict__.items():
if k != 'defaults':
quota.__dict__[k] = quota.defaults
quota.__dict__[k] = None
proj_obj.set_quota(quota)
cls._get_vnc_conn().project_update(proj_obj)

Expand Down

0 comments on commit cb5251d

Please sign in to comment.