Merge "Add quota-usage command"
This commit is contained in:
@@ -25,7 +25,7 @@ class QuotaSetsTest(utils.TestCase):
|
||||
def test_tenant_quotas_get(self):
|
||||
tenant_id = 'test'
|
||||
cs.quotas.get(tenant_id)
|
||||
cs.assert_called('GET', '/os-quota-sets/%s' % tenant_id)
|
||||
cs.assert_called('GET', '/os-quota-sets/%s?usage=False' % tenant_id)
|
||||
|
||||
def test_tenant_quotas_defaults(self):
|
||||
tenant_id = 'test'
|
||||
|
@@ -25,7 +25,7 @@ class QuotaSetsTest(utils.TestCase):
|
||||
def test_tenant_quotas_get(self):
|
||||
tenant_id = 'test'
|
||||
cs.quotas.get(tenant_id)
|
||||
cs.assert_called('GET', '/os-quota-sets/%s' % tenant_id)
|
||||
cs.assert_called('GET', '/os-quota-sets/%s?usage=False' % tenant_id)
|
||||
|
||||
def test_tenant_quotas_defaults(self):
|
||||
tenant_id = 'test'
|
||||
|
@@ -168,7 +168,10 @@ def print_list(objs, fields, formatters={}, order_by=None):
|
||||
field_name = field.replace(' ', '_')
|
||||
else:
|
||||
field_name = field.lower().replace(' ', '_')
|
||||
data = getattr(o, field_name, '')
|
||||
if type(o) == dict and field in o:
|
||||
data = o[field]
|
||||
else:
|
||||
data = getattr(o, field_name, '')
|
||||
row.append(data)
|
||||
pt.add_row(row)
|
||||
|
||||
|
@@ -32,10 +32,11 @@ class QuotaSet(base.Resource):
|
||||
class QuotaSetManager(base.Manager):
|
||||
resource_class = QuotaSet
|
||||
|
||||
def get(self, tenant_id):
|
||||
def get(self, tenant_id, usage=False):
|
||||
if hasattr(tenant_id, 'tenant_id'):
|
||||
tenant_id = tenant_id.tenant_id
|
||||
return self._get("/os-quota-sets/%s" % (tenant_id), "quota_set")
|
||||
return self._get("/os-quota-sets/%s?usage=%s" % (tenant_id, usage),
|
||||
"quota_set")
|
||||
|
||||
def update(self, tenant_id, **updates):
|
||||
body = {'quota_set': {'tenant_id': tenant_id}}
|
||||
|
@@ -580,6 +580,7 @@ def do_credentials(cs, args):
|
||||
|
||||
|
||||
_quota_resources = ['volumes', 'snapshots', 'gigabytes']
|
||||
_quota_infos = ['Type', 'In_use', 'Reserved', 'Limit']
|
||||
|
||||
|
||||
def _quota_show(quotas):
|
||||
@@ -595,6 +596,22 @@ def _quota_show(quotas):
|
||||
utils.print_dict(quota_dict)
|
||||
|
||||
|
||||
def _quota_usage_show(quotas):
|
||||
quota_list = []
|
||||
for resource in quotas._info.keys():
|
||||
good_name = False
|
||||
for name in _quota_resources:
|
||||
if resource.startswith(name):
|
||||
good_name = True
|
||||
if not good_name:
|
||||
continue
|
||||
quota_info = getattr(quotas, resource, None)
|
||||
quota_info['Type'] = resource
|
||||
quota_info = dict((k.capitalize(), v) for k, v in quota_info.items())
|
||||
quota_list.append(quota_info)
|
||||
utils.print_list(quota_list, _quota_infos)
|
||||
|
||||
|
||||
def _quota_update(manager, identifier, args):
|
||||
updates = {}
|
||||
for resource in _quota_resources:
|
||||
@@ -617,6 +634,15 @@ def do_quota_show(cs, args):
|
||||
_quota_show(cs.quotas.get(args.tenant))
|
||||
|
||||
|
||||
@utils.arg('tenant', metavar='<tenant_id>',
|
||||
help='UUID of tenant to list the quota usage for.')
|
||||
@utils.service_type('volume')
|
||||
def do_quota_usage(cs, args):
|
||||
"""List the quota usage for a tenant."""
|
||||
|
||||
_quota_usage_show(cs.quotas.get(args.tenant, usage=True))
|
||||
|
||||
|
||||
@utils.arg('tenant', metavar='<tenant_id>',
|
||||
help='UUID of tenant to list the default quotas for.')
|
||||
@utils.service_type('volume')
|
||||
|
@@ -30,10 +30,11 @@ class QuotaSet(base.Resource):
|
||||
class QuotaSetManager(base.Manager):
|
||||
resource_class = QuotaSet
|
||||
|
||||
def get(self, tenant_id):
|
||||
def get(self, tenant_id, usage=False):
|
||||
if hasattr(tenant_id, 'tenant_id'):
|
||||
tenant_id = tenant_id.tenant_id
|
||||
return self._get("/os-quota-sets/%s" % (tenant_id), "quota_set")
|
||||
return self._get("/os-quota-sets/%s?usage=%s" % (tenant_id, usage),
|
||||
"quota_set")
|
||||
|
||||
def update(self, tenant_id, **updates):
|
||||
body = {'quota_set': {'tenant_id': tenant_id}}
|
||||
|
@@ -636,6 +636,7 @@ def do_credentials(cs, args):
|
||||
|
||||
|
||||
_quota_resources = ['volumes', 'snapshots', 'gigabytes']
|
||||
_quota_infos = ['Type', 'In_use', 'Reserved', 'Limit']
|
||||
|
||||
|
||||
def _quota_show(quotas):
|
||||
@@ -651,6 +652,22 @@ def _quota_show(quotas):
|
||||
utils.print_dict(quota_dict)
|
||||
|
||||
|
||||
def _quota_usage_show(quotas):
|
||||
quota_list = []
|
||||
for resource in quotas._info.keys():
|
||||
good_name = False
|
||||
for name in _quota_resources:
|
||||
if resource.startswith(name):
|
||||
good_name = True
|
||||
if not good_name:
|
||||
continue
|
||||
quota_info = getattr(quotas, resource, None)
|
||||
quota_info['Type'] = resource
|
||||
quota_info = dict((k.capitalize(), v) for k, v in quota_info.items())
|
||||
quota_list.append(quota_info)
|
||||
utils.print_list(quota_list, _quota_infos)
|
||||
|
||||
|
||||
def _quota_update(manager, identifier, args):
|
||||
updates = {}
|
||||
for resource in _quota_resources:
|
||||
@@ -674,6 +691,15 @@ def do_quota_show(cs, args):
|
||||
_quota_show(cs.quotas.get(args.tenant))
|
||||
|
||||
|
||||
@utils.arg('tenant', metavar='<tenant_id>',
|
||||
help='UUID of tenant to list the quota usage for.')
|
||||
@utils.service_type('volumev2')
|
||||
def do_quota_usage(cs, args):
|
||||
"""List the quota usage for a tenant."""
|
||||
|
||||
_quota_usage_show(cs.quotas.get(args.tenant, usage=True))
|
||||
|
||||
|
||||
@utils.arg('tenant',
|
||||
metavar='<tenant_id>',
|
||||
help='UUID of tenant to list the default quotas for.')
|
||||
|
Reference in New Issue
Block a user