Add support for quotas for v1 cli / bindings
Change-Id: Id89fff58e1975fa84ae12a44ac2fd43cd2255b52
This commit is contained in:
parent
e9adf2a88f
commit
322c455cdc
80
designateclient/cli/quotas.py
Normal file
80
designateclient/cli/quotas.py
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
# Copyright 2014 Hewlett-Packard Development Company, L.P.
|
||||||
|
#
|
||||||
|
# Author: Endre Karlson <endre.karlson@hp.com>
|
||||||
|
#
|
||||||
|
# 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)
|
38
designateclient/v1/quotas.py
Normal file
38
designateclient/v1/quotas.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
# Copyright 2014 Hewlett-Packard Development Company, L.P.
|
||||||
|
#
|
||||||
|
# Author: Endre Karlson <endre.karlson@hp.com>
|
||||||
|
#
|
||||||
|
# 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
|
@ -35,6 +35,7 @@ designateclient.v1.controllers =
|
|||||||
domains = designateclient.v1.domains:DomainsController
|
domains = designateclient.v1.domains:DomainsController
|
||||||
records = designateclient.v1.records:RecordsController
|
records = designateclient.v1.records:RecordsController
|
||||||
servers = designateclient.v1.servers:ServersController
|
servers = designateclient.v1.servers:ServersController
|
||||||
|
quotas = designateclient.v1.quotas:QuotasController
|
||||||
sync = designateclient.v1.sync:SyncController
|
sync = designateclient.v1.sync:SyncController
|
||||||
touch = designateclient.v1.touch:TouchController
|
touch = designateclient.v1.touch:TouchController
|
||||||
|
|
||||||
@ -73,6 +74,10 @@ designateclient.cli =
|
|||||||
report-tenants-all = designateclient.cli.reports:TenantsCommand
|
report-tenants-all = designateclient.cli.reports:TenantsCommand
|
||||||
report-tenant-domains = designateclient.cli.reports:TenantCommand
|
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]
|
[build_sphinx]
|
||||||
all_files = 1
|
all_files = 1
|
||||||
build-dir = doc/build
|
build-dir = doc/build
|
||||||
|
Loading…
x
Reference in New Issue
Block a user