Merge "Expose the rebuild preserve-ephemeral extension"

This commit is contained in:
Jenkins 2014-01-02 21:22:55 +00:00 committed by Gerrit Code Review
commit 9521c63646
4 changed files with 46 additions and 3 deletions

View File

@ -261,6 +261,15 @@ class ServersTest(utils.TestCase):
def test_rebuild_server_disk_config_manual(self):
self._rebuild_resize_disk_config('MANUAL')
def test_rebuild_server_preserve_ephemeral(self):
s = cs.servers.get(1234)
s.rebuild(image=1, preserve_ephemeral=True)
cs.assert_called('POST', '/servers/1234/action')
body = cs.client.callstack[-1][-1]
d = body['rebuild']
self.assertIn('preserve_ephemeral', d)
self.assertEqual(d['preserve_ephemeral'], True)
def test_resize_server(self):
s = cs.servers.get(1234)
s.resize(flavor=1)

View File

@ -733,6 +733,27 @@ class ShellTest(utils.TestCase):
self.assert_called('GET', '/flavors/1', pos=-2)
self.assert_called('GET', '/images/2')
def test_rebuild_preserve_ephemeral(self):
self.run_command('rebuild sample-server 1 --preserve-ephemeral')
self.assert_called('GET', '/servers', pos=-8)
self.assert_called('GET', '/servers/1234', pos=-7)
self.assert_called('GET', '/images/1', pos=-6)
self.assert_called('POST', '/servers/1234/action',
{'rebuild': {'imageRef': 1,
'preserve_ephemeral': True}}, pos=-5)
self.assert_called('GET', '/flavors/1', pos=-2)
self.assert_called('GET', '/images/2')
self.run_command('rebuild sample-server 1 --rebuild-password asdf')
self.assert_called('GET', '/servers', pos=-8)
self.assert_called('GET', '/servers/1234', pos=-7)
self.assert_called('GET', '/images/1', pos=-6)
self.assert_called('POST', '/servers/1234/action',
{'rebuild': {'imageRef': 1, 'adminPass': 'asdf'}},
pos=-5)
self.assert_called('GET', '/flavors/1', pos=-2)
self.assert_called('GET', '/images/2')
def test_start(self):
self.run_command('start sample-server')
self.assert_called('POST', '/servers/1234/action', {'os-start': None})

View File

@ -241,14 +241,18 @@ class Server(base.Resource):
"""
self.manager.reboot(self, reboot_type)
def rebuild(self, image, password=None, **kwargs):
def rebuild(self, image, password=None, preserve_ephemeral=False,
**kwargs):
"""
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.
:param preserve_ephemeral: If True, request that any ephemeral device
be preserved when rebuilding the instance. Defaults to False.
"""
return self.manager.rebuild(self, image, password=password, **kwargs)
return self.manager.rebuild(self, image, password=password,
preserve_ephemeral=preserve_ephemeral, **kwargs)
def resize(self, flavor, **kwargs):
"""
@ -748,7 +752,7 @@ class ServerManager(base.BootingManagerWithFind):
self._action('reboot', server, {'type': reboot_type})
def rebuild(self, server, image, password=None, disk_config=None,
**kwargs):
preserve_ephemeral=False, **kwargs):
"""
Rebuild -- shut down and then re-image -- a server.
@ -757,12 +761,16 @@ class ServerManager(base.BootingManagerWithFind):
:param password: string to set as password on the rebuilt server.
:param disk_config: partitioning mode to use on the rebuilt server.
Valid values are 'AUTO' or 'MANUAL'
:param preserve_ephemeral: If True, request that any ephemeral device
be preserved when rebuilding the instance. Defaults to False.
"""
body = {'imageRef': base.getid(image)}
if password is not None:
body['adminPass'] = password
if disk_config is not None:
body['OS-DCF:diskConfig'] = disk_config
if preserve_ephemeral is not False:
body['preserve_ephemeral'] = True
_resp, body = self._action('rebuild', server, body, **kwargs)
return Server(self, body['server'])

View File

@ -1206,6 +1206,10 @@ def do_reboot(cs, args):
action="store_true",
default=False,
help='Skips flavor/image lookups when showing servers')
@utils.arg('--preserve-ephemeral',
action="store_true",
default=False,
help='Preserve the default ephemeral storage partition on rebuild.')
def do_rebuild(cs, args):
"""Shutdown, re-image, and re-boot a server."""
server = _find_server(cs, args.server)
@ -1217,6 +1221,7 @@ def do_rebuild(cs, args):
_password = None
kwargs = utils.get_resource_manager_extra_kwargs(do_rebuild, args)
kwargs['preserve_ephemeral'] = args.preserve_ephemeral
server.rebuild(image, _password, **kwargs)
_print_server(cs, args)