Merge "Adds quota usage support for the V3 API"
This commit is contained in:
commit
77bde21154
novaclient
@ -293,6 +293,12 @@ class FakeHTTPClient(fakes_v1_1.FakeHTTPClient):
|
||||
'security_groups': 1,
|
||||
'security_group_rules': 1}})
|
||||
|
||||
def get_os_quota_sets_test_detail(self, **kw):
|
||||
return (200, {}, {'quota_set': {
|
||||
'cores': {'reserved': 0, 'in_use': 0, 'limit': 10},
|
||||
'instances': {'reserved': 0, 'in_use': 4, 'limit': 50},
|
||||
'ram': {'reserved': 0, 'in_use': 1024, 'limit': 51200}}})
|
||||
|
||||
#
|
||||
# Hypervisors
|
||||
#
|
||||
|
@ -31,3 +31,15 @@ class QuotaSetsTest(test_quotas.QuotaSetsTest):
|
||||
'PUT', '/os-quota-sets/97f4c221bff44578b0300df4ef119353',
|
||||
{'quota_set': {'force': True,
|
||||
'cores': 2}})
|
||||
|
||||
def test_tenant_quotas_get_detail(self):
|
||||
tenant_id = 'test'
|
||||
self.cs.quotas.get(tenant_id, detail=True)
|
||||
self.cs.assert_called('GET', '/os-quota-sets/%s/detail' % tenant_id)
|
||||
|
||||
def test_user_quotas_get_detail(self):
|
||||
tenant_id = 'test'
|
||||
user_id = 'fake_user'
|
||||
self.cs.quotas.get(tenant_id, user_id=user_id, detail=True)
|
||||
url = '/os-quota-sets/%s/detail?user_id=%s' % (tenant_id, user_id)
|
||||
self.cs.assert_called('GET', url)
|
||||
|
@ -23,5 +23,20 @@ class QuotaSet(quotas.QuotaSet):
|
||||
class QuotaSetManager(quotas.QuotaSetManager):
|
||||
resource_class = QuotaSet
|
||||
|
||||
def get(self, tenant_id, user_id=None, detail=False):
|
||||
if detail:
|
||||
detail_string = '/detail'
|
||||
else:
|
||||
detail_string = ''
|
||||
|
||||
if hasattr(tenant_id, 'tenant_id'):
|
||||
tenant_id = tenant_id.tenant_id
|
||||
if user_id:
|
||||
url = '/os-quota-sets/%s%s?user_id=%s' % (tenant_id, detail_string,
|
||||
user_id)
|
||||
else:
|
||||
url = '/os-quota-sets/%s%s' % (tenant_id, detail_string)
|
||||
return self._get(url, "quota_set")
|
||||
|
||||
def _update_body(self, tenant_id, **kwargs):
|
||||
return {'quota_set': kwargs}
|
||||
|
@ -27,6 +27,8 @@ import os
|
||||
import sys
|
||||
import time
|
||||
|
||||
import six
|
||||
|
||||
from novaclient import exceptions
|
||||
from novaclient.openstack.common import strutils
|
||||
from novaclient.openstack.common import timeutils
|
||||
@ -2204,31 +2206,6 @@ def do_keypair_show(cs, args):
|
||||
_print_keypair(keypair)
|
||||
|
||||
|
||||
@utils.arg('--tenant',
|
||||
#nova db searches by project_id
|
||||
dest='tenant',
|
||||
metavar='<tenant>',
|
||||
nargs='?',
|
||||
help='Display information from single tenant (Admin only).')
|
||||
@utils.arg('--reserved',
|
||||
dest='reserved',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help='Include reservations count.')
|
||||
def do_absolute_limits(cs, args):
|
||||
"""Print a list of absolute limits for a user"""
|
||||
limits = cs.limits.get(args.reserved, args.tenant).absolute
|
||||
columns = ['Name', 'Value']
|
||||
utils.print_list(limits, columns)
|
||||
|
||||
|
||||
def do_rate_limits(cs, args):
|
||||
"""Print a list of rate limits for a user"""
|
||||
limits = cs.limits.get().rate
|
||||
columns = ['Verb', 'URI', 'Value', 'Remain', 'Unit', 'Next_Available']
|
||||
utils.print_list(limits, columns)
|
||||
|
||||
|
||||
@utils.arg('--start', metavar='<start>',
|
||||
help='Usage range start date ex 2012-01-20 (default: 4 weeks ago)',
|
||||
default=None)
|
||||
@ -2871,6 +2848,23 @@ def _quota_show(quotas):
|
||||
utils.print_dict(quota_dict)
|
||||
|
||||
|
||||
def _quota_usage(quotas):
|
||||
class QuotaObj(object):
|
||||
def __init__(self, resource, quota_dict):
|
||||
setattr(self, 'resource', resource)
|
||||
for (k, v) in six.iteritems(quota_dict):
|
||||
setattr(self, k, v)
|
||||
|
||||
quota_list = []
|
||||
for resource in _quota_resources:
|
||||
try:
|
||||
quota_list.append(QuotaObj(resource, getattr(quotas, resource)))
|
||||
except AttributeError:
|
||||
pass
|
||||
utils.print_list(quota_list, ['resource', 'in use', 'limit'],
|
||||
sortby_index=0)
|
||||
|
||||
|
||||
def _quota_update(manager, identifier, args):
|
||||
updates = {}
|
||||
for resource in _quota_resources:
|
||||
@ -2897,6 +2891,21 @@ def do_quota_show(cs, args):
|
||||
_quota_show(cs.quotas.get(args.tenant))
|
||||
|
||||
|
||||
@utils.arg('--tenant',
|
||||
metavar='<tenant-id>',
|
||||
default=None,
|
||||
help='ID of tenant to list the quotas for.')
|
||||
@utils.arg('--user',
|
||||
metavar='<user-id>',
|
||||
default=None,
|
||||
help='ID of user to list the quotas for.')
|
||||
def do_quota_usage(cs, args):
|
||||
"""List the quotas for a tenant."""
|
||||
|
||||
tenant = args.tenant or cs.client.tenant_id
|
||||
_quota_usage(cs.quotas.get(tenant, user_id=args.user, detail=True))
|
||||
|
||||
|
||||
@utils.arg('--tenant',
|
||||
metavar='<tenant-id>',
|
||||
default=None,
|
||||
|
Loading…
x
Reference in New Issue
Block a user