From cb5251d1d70a7dff9a590651840fafa18dcf9962 Mon Sep 17 00:00:00 2001 From: Sachin Bansal Date: Mon, 8 Sep 2014 17:43:01 -0700 Subject: [PATCH] We will use default-project to store default quotas. If quota is not 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 7e9ed18d3fbf01e53102e928012405312a0da051) --- .../plugins/opencontrail/quota/driver.py | 36 +++++++++++++++---- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/neutron_plugin_contrail/plugins/opencontrail/quota/driver.py b/neutron_plugin_contrail/plugins/opencontrail/quota/driver.py index 4e48558..f974ee2 100644 --- a/neutron_plugin_contrail/plugins/opencontrail/quota/driver.py +++ b/neutron_plugin_contrail/plugins/opencontrail/quota/driver.py @@ -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) @@ -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 @@ -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)