diff options
author | Cedric Brandily <zzelle@gmail.com> | 2015-08-28 14:02:22 +0200 |
---|---|---|
committer | Cedric Brandily <zzelle@gmail.com> | 2015-08-31 23:11:53 +0200 |
commit | 9b7dd38d8fb80a0b8b1152205c6a08cd854c33de (patch) | |
tree | dcd952f47a9b2820726df08a030d431b1e661ba5 | |
parent | d27568eab50b10fc022719172bc15666f3cede0d (diff) | |
download | python-novaclient-9b7dd38d8fb80a0b8b1152205c6a08cd854c33de.tar.gz |
Allow to reboot multiple servers
This change allows to pass multiple server names/ids to nova reboot.
Change-Id: I7ad891beafba019c262f656aa3e78686336e072b
-rw-r--r-- | novaclient/tests/unit/v2/test_shell.py | 7 | ||||
-rw-r--r-- | novaclient/v2/shell.py | 21 |
2 files changed, 23 insertions, 5 deletions
diff --git a/novaclient/tests/unit/v2/test_shell.py b/novaclient/tests/unit/v2/test_shell.py index 3f190a80..cfd81fcc 100644 --- a/novaclient/tests/unit/v2/test_shell.py +++ b/novaclient/tests/unit/v2/test_shell.py @@ -956,6 +956,13 @@ class ShellTest(utils.TestCase): self.assert_called('POST', '/servers/1234/action', {'reboot': {'type': 'HARD'}}) + def test_reboot_many(self): + self.run_command('reboot sample-server sample-server2') + self.assert_called('POST', '/servers/1234/action', + {'reboot': {'type': 'SOFT'}}, pos=-2) + self.assert_called('POST', '/servers/5678/action', + {'reboot': {'type': 'SOFT'}}, pos=-1) + def test_rebuild(self): output, _ = self.run_command('rebuild sample-server 1') self.assert_called('GET', '/servers?name=sample-server', pos=-6) diff --git a/novaclient/v2/shell.py b/novaclient/v2/shell.py index e0f71162..ab15d692 100644 --- a/novaclient/v2/shell.py +++ b/novaclient/v2/shell.py @@ -1459,7 +1459,10 @@ def do_list(cs, args): const=servers.REBOOT_HARD, default=servers.REBOOT_SOFT, help=_('Perform a hard reboot (instead of a soft one).')) -@cliutils.arg('server', metavar='<server>', help=_('Name or ID of server.')) +@cliutils.arg( + 'server', + metavar='<server>', nargs='+', + help=_('Name or ID of server(s).')) @cliutils.arg( '--poll', dest='poll', @@ -1468,12 +1471,20 @@ def do_list(cs, args): help=_('Poll until reboot is complete.')) def do_reboot(cs, args): """Reboot a server.""" - server = _find_server(cs, args.server) - server.reboot(args.reboot_type) + servers = [_find_server(cs, s) for s in args.server] + utils.do_action_on_many( + lambda s: s.reboot(args.reboot_type), + servers, + _("Request to reboot server %s has been accepted."), + _("Unable to reboot the specified server(s).")) if args.poll: - _poll_for_status(cs.servers.get, server.id, 'rebooting', ['active'], - show_progress=False) + utils.do_action_on_many( + lambda s: _poll_for_status(cs.servers.get, s.id, 'rebooting', + ['active'], show_progress=False), + servers, + _("Wait for server %s reboot."), + _("Wait for specified server(s) failed.")) @cliutils.arg('server', metavar='<server>', help=_('Name or ID of server.')) |