From 10d1b3aba6a297f0ec1f31f8bbd09177461b4c70 Mon Sep 17 00:00:00 2001 From: eric Date: Mon, 11 May 2015 15:35:10 -0600 Subject: [PATCH] Add quota check for domain create Change-Id: I45bd5ab714cff98cbe9648f625e818cd1b8b2278 Closes-Bug: #1453870 --- .../designatedashboard/api/designate.py | 7 +++++++ .../dashboards/project/dns_domains/tables.py | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/contrib/designate-dashboard/designatedashboard/api/designate.py b/contrib/designate-dashboard/designatedashboard/api/designate.py index 3fd432acd..837d41858 100644 --- a/contrib/designate-dashboard/designatedashboard/api/designate.py +++ b/contrib/designate-dashboard/designatedashboard/api/designate.py @@ -165,3 +165,10 @@ def record_update(request, domain_id, record_id, **kwargs): record.description = kwargs.get('description', None) return d_client.records.update(domain_id, record) + + +def quota_get(request, project_id=None): + if not project_id: + project_id = request.user.project_id + d_client = designateclient(request) + return d_client.quotas.get(project_id) \ No newline at end of file diff --git a/contrib/designate-dashboard/designatedashboard/dashboards/project/dns_domains/tables.py b/contrib/designate-dashboard/designatedashboard/dashboards/project/dns_domains/tables.py index d2d334f4d..c9180cc14 100644 --- a/contrib/designate-dashboard/designatedashboard/dashboards/project/dns_domains/tables.py +++ b/contrib/designate-dashboard/designatedashboard/dashboards/project/dns_domains/tables.py @@ -18,6 +18,7 @@ from django.utils.translation import ugettext_lazy as _ # noqa from horizon import exceptions from horizon import tables +from horizon.utils import memoized from designatedashboard import api @@ -45,6 +46,17 @@ class CreateDomain(tables.LinkAction): classes = ("ajax-modal", "btn-create") policy_rules = (("dns", "create_domain"),) + @memoized.memoized_method + def allowed(self, request, datum): + try: + if self.table: + quota = api.designate.quota_get(request) + return quota['domains'] > len(self.table.data) + except: + msg = _("The quotas could not be retrieved.") + messages.warning(request, msg) + return True + class EditDomain(tables.LinkAction):