Add {set,get}_boot_device and get_supported_boot_devices

Add set_boot_device, get_boot_device and get_supported_boot_devices
commands to the client library.

Implements: blueprint new-management-interface
Change-Id: Ib8ba6ef0da9113967f4135dea6e20284eda9d825
This commit is contained in:
Lucas Alvares Gomes 2014-07-25 14:18:28 +01:00
parent 1ce8722e04
commit 31ac1c9f82
4 changed files with 128 additions and 0 deletions

@ -64,6 +64,9 @@ CONSOLE_DATA_ENABLED = {'console_enabled': True,
'console_info': {'test-console': 'test-console-data'}}
CONSOLE_DATA_DISABLED = {'console_enabled': False, 'console_info': None}
BOOT_DEVICE = {'boot_device': 'pxe', 'persistent': False}
SUPPORTED_BOOT_DEVICE = {'supported_boot_devices': ['pxe']}
CREATE_NODE = copy.deepcopy(NODE1)
del CREATE_NODE['id']
del CREATE_NODE['uuid']
@ -202,6 +205,24 @@ fake_responses = {
CONSOLE_DATA_DISABLED,
),
},
'/v1/nodes/%s/management/boot_device' % NODE1['uuid']:
{
'GET': (
{},
BOOT_DEVICE,
),
'PUT': (
{},
None,
),
},
'/v1/nodes/%s/management/boot_device/supported' % NODE1['uuid']:
{
'GET': (
{},
SUPPORTED_BOOT_DEVICE,
),
},
}
fake_responses_pagination = {
@ -494,3 +515,36 @@ class NodeManagerTest(testtools.TestCase):
update_mock.assert_once_called_with(final_path,
vendor_passthru_args,
method='POST')
def _test_node_set_boot_device(self, boot_device, persistent=False):
self.mgr.set_boot_device(NODE1['uuid'], boot_device, persistent)
body = {'boot_device': boot_device, 'persistent': persistent}
expect = [
('PUT', '/v1/nodes/%s/management/boot_device' % NODE1['uuid'],
{}, body),
]
self.assertEqual(expect, self.api.calls)
def test_node_set_boot_device(self):
self._test_node_set_boot_device('pxe')
def test_node_set_boot_device_persistent(self):
self._test_node_set_boot_device('pxe', persistent=True)
def test_node_get_boot_device(self):
boot_device = self.mgr.get_boot_device(NODE1['uuid'])
expect = [
('GET', '/v1/nodes/%s/management/boot_device' % NODE1['uuid'],
{}, None),
]
self.assertEqual(expect, self.api.calls)
self.assertEqual(BOOT_DEVICE, boot_device)
def test_node_get_supported_boot_devices(self):
boot_device = self.mgr.get_supported_boot_devices(NODE1['uuid'])
expect = [
('GET', '/v1/nodes/%s/management/boot_device/supported' %
NODE1['uuid'], {}, None),
]
self.assertEqual(expect, self.api.calls)
self.assertEqual(SUPPORTED_BOOT_DEVICE, boot_device)

@ -78,3 +78,31 @@ class NodeShellTest(utils.BaseTestCase):
'args': {}
}
client_mock.node.vendor_passthru.assert_called_once_with(**kwargs)
def test_do_node_set_boot_device(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
args.node = 'node_uuid'
args.persistent = False
args.device = 'pxe'
n_shell.do_node_set_boot_device(client_mock, args)
client_mock.node.set_boot_device.assert_called_once_with(
'node_uuid', 'pxe', False)
def test_do_node_get_boot_device(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
args.node = 'node_uuid'
n_shell.do_node_get_boot_device(client_mock, args)
client_mock.node.get_boot_device.assert_called_once_with('node_uuid')
def test_do_node_get_supported_boot_devices(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
args.node = 'node_uuid'
n_shell.do_node_get_supported_boot_devices(client_mock, args)
client_mock.node.get_supported_boot_devices.assert_called_once_with(
'node_uuid')

@ -190,3 +190,16 @@ class NodeManager(base.Manager):
path = "%s/states/console" % node_uuid
target = {'enabled': enabled}
return self._update(self._path(path), target, method='PUT')
def set_boot_device(self, node_uuid, boot_device, persistent=False):
path = "%s/management/boot_device" % node_uuid
target = {'boot_device': boot_device, 'persistent': persistent}
return self._update(self._path(path), target, method='PUT')
def get_boot_device(self, node_uuid):
path = "%s/management/boot_device" % node_uuid
return self.get(path).to_dict()
def get_supported_boot_devices(self, node_uuid):
path = "%s/management/boot_device/supported" % node_uuid
return self.get(path).to_dict()

@ -271,3 +271,36 @@ def do_node_get_console(cc, args):
def do_node_set_console_mode(cc, args):
"""Enable or disable serial console access for this node."""
cc.node.set_console_mode(args.node, args.enabled)
@cliutils.arg('node', metavar='<node uuid>', help="UUID of node")
@cliutils.arg(
'device',
metavar='<boot device>',
choices=['pxe', 'disk', 'cdrom', 'bios', 'safe'],
help="Supported boot devices: 'pxe', 'disk', 'cdrom', 'bios', 'safe'")
@cliutils.arg(
'--persistent',
dest='persistent',
action='store_true',
default=False,
help="Make changes persistent for all future boots")
def do_node_set_boot_device(cc, args):
"""Set the boot device for a node."""
cc.node.set_boot_device(args.node, args.device, args.persistent)
@cliutils.arg('node', metavar='<node uuid>', help="UUID of node")
def do_node_get_boot_device(cc, args):
"""Get the current boot device."""
boot_device = cc.node.get_boot_device(args.node)
cliutils.print_dict(boot_device, wrap=72)
@cliutils.arg('node', metavar='<node uuid>', help="UUID of node")
def do_node_get_supported_boot_devices(cc, args):
"""Get the supported boot devices."""
boot_devices = cc.node.get_supported_boot_devices(args.node)
boot_device_list = boot_devices.get('supported_boot_devices', [])
boot_devices['supported_boot_devices'] = ', '.join(boot_device_list)
cliutils.print_dict(boot_devices, wrap=72)