From 2a0940d3214ba3a6c3c12149908e009b5a179142 Mon Sep 17 00:00:00 2001 From: Steve Leon Date: Fri, 15 Feb 2013 15:53:19 -0800 Subject: [PATCH] Quota commands for listing and updating quotas These commands are admin-command that is used to obtain quota informations and updating quotas for a particular tenant. Change-Id: I77ec538d12564b7d245fecbbc6f2698ce4b634b4 --- reddwarfclient/client.py | 2 ++ reddwarfclient/mcli.py | 22 ++++++++++++++++ reddwarfclient/quota.py | 55 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 reddwarfclient/quota.py diff --git a/reddwarfclient/client.py b/reddwarfclient/client.py index 2b2dcbdf..cc6c4280 100644 --- a/reddwarfclient/client.py +++ b/reddwarfclient/client.py @@ -304,6 +304,7 @@ class Dbaas(object): from reddwarfclient.users import Users from reddwarfclient.root import Root from reddwarfclient.hosts import Hosts + from reddwarfclient.quota import Quotas from reddwarfclient.storage import StorageInfo from reddwarfclient.management import Management from reddwarfclient.accounts import Accounts @@ -324,6 +325,7 @@ class Dbaas(object): self.users = Users(self) self.root = Root(self) self.hosts = Hosts(self) + self.quota = Quotas(self) self.storage = StorageInfo(self) self.management = Management(self) self.accounts = Accounts(self) diff --git a/reddwarfclient/mcli.py b/reddwarfclient/mcli.py index f89bfe7e..83d5acf2 100644 --- a/reddwarfclient/mcli.py +++ b/reddwarfclient/mcli.py @@ -66,6 +66,27 @@ class HostCommands(common.AuthedCommandsBase): self._pretty_list(self.dbaas.hosts.index) +class QuotaCommands(common.AuthedCommandsBase): + """List and update quota limits for a tenant.""" + + params = [ + 'id', + 'instances', + 'volume_size', + ] + + def list(self): + """List all quotas for a tenant""" + self._require('id') + self._pretty_print(self.dbaas.quota.show, self.id) + + def update(self): + """Update quota limits for a tenant""" + self._require('id', 'instances', 'volume_size') + self._pretty_print(self.dbaas.quota.update, self.id, + self.instances, self.volume_size) + + class RootCommands(common.AuthedCommandsBase): """List details about the root info for an instance.""" @@ -173,6 +194,7 @@ COMMANDS = {'account': AccountCommands, 'instance': InstanceCommands, 'root': RootCommands, 'storage': StorageCommands, + 'quotas': QuotaCommands } diff --git a/reddwarfclient/quota.py b/reddwarfclient/quota.py new file mode 100644 index 00000000..0876f727 --- /dev/null +++ b/reddwarfclient/quota.py @@ -0,0 +1,55 @@ +# Copyright (c) 2011 OpenStack, LLC. +# All Rights Reserved. +# +# 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. + +from reddwarfclient import base +from reddwarfclient.common import check_for_exceptions + + +class Quota(base.Resource): + """ + Quota is a resource used to hold quota information. + """ + def __repr__(self): + return "" % self.name + + +class Quotas(base.ManagerWithFind): + """ + Manage :class:`Quota` information. + """ + + resource_class = Quota + + def show(self, tenant_id): + """Get a list of all quotas for a tenant id""" + + url = "/mgmt/quotas/%s" % tenant_id + resp, body = self.api.client.get(url) + check_for_exceptions(resp, body) + if not body: + raise Exception("Call to " + url + " did not return a body.") + return base.Resource(self, body) + + def update(self, tenant_id, instances, volume_size): + """ + Set limits for quotas + """ + url = "/mgmt/quotas/%s" % tenant_id + body = {"quotas": {"instances": instances, "volumes": volume_size}} + resp, body = self.api.client.put(url, body=body) + check_for_exceptions(resp, body) + if not body: + raise Exception("Call to " + url + " did not return a body.") + return base.Resource(self, body)