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
This commit is contained in:
Steve Leon 2013-02-15 15:53:19 -08:00
parent 3e5cdd673e
commit 2a0940d321
3 changed files with 79 additions and 0 deletions

View File

@ -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)

View File

@ -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
}

55
reddwarfclient/quota.py Normal file
View File

@ -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 "<Quota: %s>" % 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)