From 322c455cdcde32a23cecd7f7e138084e328f075d Mon Sep 17 00:00:00 2001 From: Endre Karlson Date: Fri, 1 Aug 2014 10:44:53 +0200 Subject: [PATCH] Add support for quotas for v1 cli / bindings Change-Id: Id89fff58e1975fa84ae12a44ac2fd43cd2255b52 --- designateclient/cli/quotas.py | 80 +++++++++++++++++++++++++++++++++++ designateclient/v1/quotas.py | 38 +++++++++++++++++ setup.cfg | 5 +++ 3 files changed, 123 insertions(+) create mode 100644 designateclient/cli/quotas.py create mode 100644 designateclient/v1/quotas.py diff --git a/designateclient/cli/quotas.py b/designateclient/cli/quotas.py new file mode 100644 index 0000000..da85528 --- /dev/null +++ b/designateclient/cli/quotas.py @@ -0,0 +1,80 @@ +# Copyright 2014 Hewlett-Packard Development Company, L.P. +# +# Author: Endre Karlson +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import logging + +from designateclient.cli import base + + +LOG = logging.getLogger(__name__) + + +class GetQuotaCommand(base.GetCommand): + """Get Quota""" + + def get_parser(self, prog_name): + parser = super(GetQuotaCommand, self).get_parser(prog_name) + + parser.add_argument('tenant_id', help="Tenant ID") + + return parser + + def execute(self, parsed_args): + return self.client.quotas.get(parsed_args.tenant_id) + + +class UpdateQuotaCommand(base.UpdateCommand): + """Update Quota""" + + def get_parser(self, prog_name): + parser = super(UpdateQuotaCommand, self).get_parser(prog_name) + + parser.add_argument('tenant_id', help="Tenant ID") + parser.add_argument('--domains', help="Allowed Domains", type=int) + parser.add_argument('--domain-recordsets', + help="Allowed Domain Records", + type=int) + parser.add_argument('--recordset-records', + help="Allowed Recordset Records", + type=int) + parser.add_argument('--domain-records', + help="Allowed Domain Records", + type=int) + return parser + + def execute(self, parsed_args): + # TODO(kiall): API needs updating.. this get is silly + quota = self.client.quotas.get(parsed_args.tenant_id) + + for key, old in quota.items(): + new = getattr(parsed_args, key) + if new is not None and new != old: + quota[key] = new + return self.client.quotas.update(parsed_args.tenant_id, quota) + + +class ResetQuotaCommand(base.DeleteCommand): + """Reset Quota""" + + def get_parser(self, prog_name): + parser = super(ResetQuotaCommand, self).get_parser(prog_name) + + parser.add_argument('tenant_id', help="Tenant ID") + + return parser + + def execute(self, parsed_args): + self.client.quotas.reset(parsed_args.tenant_id) diff --git a/designateclient/v1/quotas.py b/designateclient/v1/quotas.py new file mode 100644 index 0000000..c231610 --- /dev/null +++ b/designateclient/v1/quotas.py @@ -0,0 +1,38 @@ +# Copyright 2014 Hewlett-Packard Development Company, L.P. +# +# Author: Endre Karlson +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +import json + +from designateclient.v1.base import Controller + + +class QuotasController(Controller): + def get(self, tenant_id): + """ + Ping a service on a given host + """ + response = self.client.get('/quotas/%s' % tenant_id) + + return response.json() + + def update(self, tenant_id, values): + response = self.client.put('/quotas/%s' % tenant_id, + data=json.dumps(values)) + return response.json() + + def reset(self, tenant_id): + response = self.client.delete('/quotas/%s' % tenant_id) + + return response diff --git a/setup.cfg b/setup.cfg index c874aef..01ac7ee 100644 --- a/setup.cfg +++ b/setup.cfg @@ -35,6 +35,7 @@ designateclient.v1.controllers = domains = designateclient.v1.domains:DomainsController records = designateclient.v1.records:RecordsController servers = designateclient.v1.servers:ServersController + quotas = designateclient.v1.quotas:QuotasController sync = designateclient.v1.sync:SyncController touch = designateclient.v1.touch:TouchController @@ -73,6 +74,10 @@ designateclient.cli = report-tenants-all = designateclient.cli.reports:TenantsCommand report-tenant-domains = designateclient.cli.reports:TenantCommand + quota-get = designateclient.cli.quotas:GetQuotaCommand + quota-update = designateclient.cli.quotas:UpdateQuotaCommand + quota-reset = designateclient.cli.quotas:ResetQuotaCommand + [build_sphinx] all_files = 1 build-dir = doc/build