Merge " Allow to reboot multiple servers"

This commit is contained in:
Jenkins 2015-09-01 15:57:50 +00:00 committed by Gerrit Code Review
commit 893bf9313c
2 changed files with 23 additions and 5 deletions

View File

@ -956,6 +956,13 @@ class ShellTest(utils.TestCase):
self.assert_called('POST', '/servers/1234/action', self.assert_called('POST', '/servers/1234/action',
{'reboot': {'type': 'HARD'}}) {'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): def test_rebuild(self):
output, _ = self.run_command('rebuild sample-server 1') output, _ = self.run_command('rebuild sample-server 1')
self.assert_called('GET', '/servers?name=sample-server', pos=-6) self.assert_called('GET', '/servers?name=sample-server', pos=-6)

View File

@ -1459,7 +1459,10 @@ def do_list(cs, args):
const=servers.REBOOT_HARD, const=servers.REBOOT_HARD,
default=servers.REBOOT_SOFT, default=servers.REBOOT_SOFT,
help=_('Perform a hard reboot (instead of a soft one).')) 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( @cliutils.arg(
'--poll', '--poll',
dest='poll', dest='poll',
@ -1468,12 +1471,20 @@ def do_list(cs, args):
help=_('Poll until reboot is complete.')) help=_('Poll until reboot is complete.'))
def do_reboot(cs, args): def do_reboot(cs, args):
"""Reboot a server.""" """Reboot a server."""
server = _find_server(cs, args.server) servers = [_find_server(cs, s) for s in args.server]
server.reboot(args.reboot_type) 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: if args.poll:
_poll_for_status(cs.servers.get, server.id, 'rebooting', ['active'], utils.do_action_on_many(
show_progress=False) 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.')) @cliutils.arg('server', metavar='<server>', help=_('Name or ID of server.'))