diff --git a/novaclient/tests/unit/v2/test_shell.py b/novaclient/tests/unit/v2/test_shell.py index b1b9b8085..5d1d20d9b 100644 --- a/novaclient/tests/unit/v2/test_shell.py +++ b/novaclient/tests/unit/v2/test_shell.py @@ -1998,6 +1998,20 @@ class ShellTest(utils.TestCase): self.run_command('absolute-limits --tenant 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): self.run_command('evacuate sample-server new_host') self.assert_called('POST', '/servers/1234/action', diff --git a/novaclient/v2/shell.py b/novaclient/v2/shell.py index 7e3a53100..a6c7228a2 100644 --- a/novaclient/v2/shell.py +++ b/novaclient/v2/shell.py @@ -2935,9 +2935,13 @@ def _find_keypair(cs, keypair): default=False, help=_('Include reservations count.')) 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 + _print_absolute_limits(limits) + +def _print_absolute_limits(limits): + """Prints absolute limits.""" class Limit(object): def __init__(self, name, used, max, other): self.name = name @@ -2999,12 +3003,37 @@ def do_absolute_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 + _print_rate_limits(limits) + + +def _print_rate_limits(limits): + """print rate limits.""" columns = ['Verb', 'URI', 'Value', 'Remain', 'Unit', 'Next_Available'] utils.print_list(limits, columns) +@cliutils.arg( + '--tenant', + # nova db searches by project_id + dest='tenant', + metavar='', + 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( '--start', metavar='',