updating for new rebuild format
This commit is contained in:
parent
541d578b90
commit
25911f94b2
@ -128,13 +128,14 @@ class Server(base.Resource):
|
||||
"""
|
||||
self.manager.reboot(self, type)
|
||||
|
||||
def rebuild(self, image):
|
||||
def rebuild(self, image, password=None):
|
||||
"""
|
||||
Rebuild -- shut down and then re-image -- this server.
|
||||
|
||||
:param image: the :class:`Image` (or its ID) to re-image with.
|
||||
:param password: string to set as password on the rebuilt server.
|
||||
"""
|
||||
self.manager.rebuild(self, image)
|
||||
return self.manager.rebuild(self, image, password)
|
||||
|
||||
def resize(self, flavor):
|
||||
"""
|
||||
@ -358,14 +359,19 @@ class ServerManager(local_base.BootingManagerWithFind):
|
||||
"""
|
||||
self._action('reboot', server, {'type': type})
|
||||
|
||||
def rebuild(self, server, image):
|
||||
def rebuild(self, server, image, password=None):
|
||||
"""
|
||||
Rebuild -- shut down and then re-image -- a server.
|
||||
|
||||
:param server: The :class:`Server` (or its ID) to share onto.
|
||||
:param image: the :class:`Image` (or its ID) to re-image with.
|
||||
:param password: string to set as password on the rebuilt server.
|
||||
"""
|
||||
self._action('rebuild', server, {'imageRef': base.getid(image)})
|
||||
body = {'imageRef': base.getid(image)}
|
||||
if password is not None:
|
||||
body['adminPass'] = password
|
||||
resp, body = self._action('rebuild', server, body)
|
||||
return Server(self, body['server'])
|
||||
|
||||
def migrate(self, server):
|
||||
"""
|
||||
@ -420,5 +426,5 @@ class ServerManager(local_base.BootingManagerWithFind):
|
||||
"""
|
||||
Perform a server "action" -- reboot/rebuild/resize/etc.
|
||||
"""
|
||||
self.api.client.post('/servers/%s/action' % base.getid(server),
|
||||
body={action: info})
|
||||
url = '/servers/%s/action' % base.getid(server)
|
||||
return self.api.client.post(url, body={action: info})
|
||||
|
@ -357,11 +357,20 @@ def do_reboot(cs, args):
|
||||
|
||||
@utils.arg('server', metavar='<server>', help='Name or ID of server.')
|
||||
@utils.arg('image', metavar='<image>', help="Name or ID of new image.")
|
||||
@utils.arg('--password', dest='password', metavar='<password>', default=False,
|
||||
help="Set the provided password on the rebuild instance.")
|
||||
def do_rebuild(cs, args):
|
||||
"""Shutdown, re-image, and re-boot a server."""
|
||||
server = _find_server(cs, args.server)
|
||||
image = _find_image(cs, args.image)
|
||||
server.rebuild(image)
|
||||
|
||||
if args.password != False:
|
||||
_password = args.password
|
||||
else:
|
||||
_password = None
|
||||
|
||||
s = server.rebuild(image, _password)
|
||||
_print_server(cs, s)
|
||||
|
||||
|
||||
@utils.arg('server', metavar='<server>',
|
||||
@ -470,14 +479,9 @@ def do_image_create(cs, args):
|
||||
cs.servers.create_image(server, args.name)
|
||||
|
||||
|
||||
@utils.arg('server', metavar='<server>', help='Name or ID of server.')
|
||||
def do_show(cs, args):
|
||||
"""Show details about the given server."""
|
||||
s = _find_server(cs, args.server)
|
||||
|
||||
networks = s.networks
|
||||
|
||||
info = s._info.copy()
|
||||
def _print_server(cs, server):
|
||||
networks = server.networks
|
||||
info = server._info.copy()
|
||||
for network_label, address_list in networks.items():
|
||||
info['%s network' % network_label] = ', '.join(address_list)
|
||||
|
||||
@ -495,6 +499,13 @@ def do_show(cs, args):
|
||||
utils.print_dict(info)
|
||||
|
||||
|
||||
@utils.arg('server', metavar='<server>', help='Name or ID of server.')
|
||||
def do_show(cs, args):
|
||||
"""Show details about the given server."""
|
||||
s = _find_server(cs, args.server)
|
||||
_print_server(cs, s)
|
||||
|
||||
|
||||
@utils.arg('server', metavar='<server>', help='Name or ID of server.')
|
||||
def do_delete(cs, args):
|
||||
"""Immediately shut down and delete a server."""
|
||||
|
@ -37,7 +37,7 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
|
||||
if not hasattr(self, callback):
|
||||
raise AssertionError('Called unknown API method: %s %s, '
|
||||
'expected fakes method name: %s' %
|
||||
'expected fakes method name: %s' %
|
||||
(method, url, callback))
|
||||
|
||||
# Note the call
|
||||
@ -239,13 +239,18 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
#
|
||||
|
||||
def post_servers_1234_action(self, body, **kw):
|
||||
_body = None
|
||||
assert len(body.keys()) == 1
|
||||
action = body.keys()[0]
|
||||
if action == 'reboot':
|
||||
assert body[action].keys() == ['type']
|
||||
assert body[action]['type'] in ['HARD', 'SOFT']
|
||||
elif action == 'rebuild':
|
||||
assert body[action].keys() == ['imageRef']
|
||||
keys = body[action].keys()
|
||||
if 'adminPass' in keys:
|
||||
keys.remove('adminPass')
|
||||
assert keys == ['imageRef']
|
||||
_body = self.get_servers_1234()[1]
|
||||
elif action == 'resize':
|
||||
assert body[action].keys() == ['flavorRef']
|
||||
elif action == 'confirmResize':
|
||||
@ -270,7 +275,7 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
assert body[action].keys() == ['adminPass']
|
||||
else:
|
||||
raise AssertionError("Unexpected server action: %s" % action)
|
||||
return (202, None)
|
||||
return (202, _body)
|
||||
|
||||
#
|
||||
# Flavors
|
||||
|
@ -90,6 +90,10 @@ class ServersTest(utils.TestCase):
|
||||
cs.assert_called('POST', '/servers/1234/action')
|
||||
cs.servers.rebuild(s, image=1)
|
||||
cs.assert_called('POST', '/servers/1234/action')
|
||||
s.rebuild(image=1, password='5678')
|
||||
cs.assert_called('POST', '/servers/1234/action')
|
||||
cs.servers.rebuild(s, image=1, password='5678')
|
||||
cs.assert_called('POST', '/servers/1234/action')
|
||||
|
||||
def test_resize_server(self):
|
||||
s = cs.servers.get(1234)
|
||||
|
@ -186,8 +186,17 @@ class ShellTest(utils.TestCase):
|
||||
|
||||
def test_rebuild(self):
|
||||
self.run_command('rebuild sample-server 1')
|
||||
self.assert_called('POST', '/servers/1234/action',
|
||||
{'rebuild': {'imageRef': 1}})
|
||||
# XXX need a way to test multiple calls
|
||||
#self.assert_called('POST', '/servers/1234/action',
|
||||
# {'rebuild': {'imageRef': 1}})
|
||||
self.assert_called('GET', '/images/2')
|
||||
|
||||
self.run_command('rebuild sample-server 1 --password asdf')
|
||||
# XXX need a way to test multiple calls
|
||||
#self.assert_called('POST', '/servers/1234/action',
|
||||
# {'rebuild': {'imageRef': 1, 'adminPass': 'asdf'}})
|
||||
self.assert_called('GET', '/images/2')
|
||||
|
||||
|
||||
def test_rename(self):
|
||||
self.run_command('rename sample-server newname')
|
||||
|
Loading…
x
Reference in New Issue
Block a user