nova client now support limits subcommand

Added new subcommand "limits" which displays absolute limits and
rate limits both. do_limits() functions calls get() only once and
then passes limits.rate and limits.absolute to _print_rate_limits
and _print_absolute_limits respectively; these functions then
format the output.

Change-Id: I1344da1a3925a3f3a757e340f11381b69a668bf7
Closes-Bug: #1172254
This commit is contained in:
rajiv.kumar 2015-03-24 03:49:41 +00:00 committed by Rajiv Kumar
parent 025bcfb1e3
commit bf6fbdb8d7
2 changed files with 45 additions and 2 deletions

View File

@ -1998,6 +1998,20 @@ class ShellTest(utils.TestCase):
self.run_command('absolute-limits --tenant 1234') self.run_command('absolute-limits --tenant 1234')
self.assert_called('GET', '/limits?tenant_id=1234') self.assert_called('GET', '/limits?tenant_id=1234')
def test_limits(self):
self.run_command('limits')
self.assert_called('GET', '/limits')
self.run_command('limits --reserved')
self.assert_called('GET', '/limits?reserved=1')
self.run_command('limits --tenant 1234')
self.assert_called('GET', '/limits?tenant_id=1234')
stdout = self.run_command('limits --tenant 1234')
self.assertIn('Verb', stdout)
self.assertIn('Name', stdout)
def test_evacuate(self): def test_evacuate(self):
self.run_command('evacuate sample-server new_host') self.run_command('evacuate sample-server new_host')
self.assert_called('POST', '/servers/1234/action', self.assert_called('POST', '/servers/1234/action',

View File

@ -2935,9 +2935,13 @@ def _find_keypair(cs, keypair):
default=False, default=False,
help=_('Include reservations count.')) help=_('Include reservations count.'))
def do_absolute_limits(cs, args): def do_absolute_limits(cs, args):
"""Print a list of absolute limits for a user""" """DEPRECATED, use limits instead."""
limits = cs.limits.get(args.reserved, args.tenant).absolute limits = cs.limits.get(args.reserved, args.tenant).absolute
_print_absolute_limits(limits)
def _print_absolute_limits(limits):
"""Prints absolute limits."""
class Limit(object): class Limit(object):
def __init__(self, name, used, max, other): def __init__(self, name, used, max, other):
self.name = name self.name = name
@ -2999,12 +3003,37 @@ def do_absolute_limits(cs, args):
def do_rate_limits(cs, args): def do_rate_limits(cs, args):
"""Print a list of rate limits for a user""" """DEPRECATED, use limits instead."""
limits = cs.limits.get().rate limits = cs.limits.get().rate
_print_rate_limits(limits)
def _print_rate_limits(limits):
"""print rate limits."""
columns = ['Verb', 'URI', 'Value', 'Remain', 'Unit', 'Next_Available'] columns = ['Verb', 'URI', 'Value', 'Remain', 'Unit', 'Next_Available']
utils.print_list(limits, columns) utils.print_list(limits, columns)
@cliutils.arg(
'--tenant',
# nova db searches by project_id
dest='tenant',
metavar='<tenant>',
nargs='?',
help=_('Display information from single tenant (Admin only).'))
@cliutils.arg(
'--reserved',
dest='reserved',
action='store_true',
default=False,
help=_('Include reservations count.'))
def do_limits(cs, args):
"""Print rate and absolute limits."""
limits = cs.limits.get(args.reserved, args.tenant)
_print_rate_limits(limits.rate)
_print_absolute_limits(limits.absolute)
@cliutils.arg( @cliutils.arg(
'--start', '--start',
metavar='<start>', metavar='<start>',