diff options
author | Kiall Mac Innes <kiall@hp.com> | 2013-10-16 14:02:59 +0100 |
---|---|---|
committer | Kiall Mac Innes <kiall@hp.com> | 2013-10-16 14:02:59 +0100 |
commit | b76ff81565f6b6700b298ca2121df6548972f0a3 (patch) | |
tree | 5e5251621736e7cd534fe9eb208ad0286f614f42 | |
parent | 064eb4f26d9ccf9c86a804778c6c6a4e5bfdfad0 (diff) | |
download | designate-b76ff81565f6b6700b298ca2121df6548972f0a3.tar.gz |
Abstract quota enforcement in central service
Change-Id: Ibc746aed1fd7960722ecd8eaf44bf55da682f6c7
-rw-r--r-- | designate/central/service.py | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/designate/central/service.py b/designate/central/service.py index c147da41..1b509429 100644 --- a/designate/central/service.py +++ b/designate/central/service.py @@ -233,6 +233,21 @@ class Service(rpc_service.Service): return domain + # Quota Enforcement Methods + def _enforce_domain_quota(self, context, tenant_id): + criterion = {'tenant_id': tenant_id} + count = self.storage_api.count_domains(context, criterion) + + self.quota.limit_check(context, tenant_id, domains=count) + + def _enforce_record_quota(self, context, domain): + # Ensure the records per domain quota is OK + criterion = {'domain_id': domain['id']} + count = self.storage_api.count_records(context, criterion) + + self.quota.limit_check(context, domain['tenant_id'], + domain_records=count) + # Misc Methods def get_absolute_limits(self, context): # NOTE(Kiall): Currently, we only have quota based limits.. @@ -394,11 +409,7 @@ class Service(rpc_service.Service): policy.check('create_domain', context, target) # Ensure the tenant has enough quota to continue - quota_criterion = {'tenant_id': values['tenant_id']} - domain_count = self.storage_api.count_domains( - context, criterion=quota_criterion) - self.quota.limit_check(context, values['tenant_id'], - domains=domain_count) + self._enforce_domain_quota(context, values['tenant_id']) # Ensure the domain name is valid self._is_valid_domain_name(context, values['name']) @@ -592,11 +603,7 @@ class Service(rpc_service.Service): policy.check('create_record', context, target) # Ensure the tenant has enough quota to continue - quota_criterion = {'domain_id': domain_id} - record_count = self.storage_api.count_records( - context, criterion=quota_criterion) - self.quota.limit_check(context, domain['tenant_id'], - domain_records=record_count) + self._enforce_record_quota(context, domain) # Ensure the record name and placement is valid self._is_valid_record_name(context, domain, values['name'], |