Add option to specify node uuid in node-create subcommand

- node-create subcommand now includes -u or --uuid
option that allows the user to specify the uuid if
needed.

- The uuid parameter is optional

Change-Id: I1a8332689d6d5f85350877bd4ab64aa173e5d916
Closes-Bug: 1381214
This commit is contained in:
Arun S A G 2014-10-30 17:08:18 -07:00
parent 5958a1fe85
commit 403926334c
2 changed files with 13 additions and 2 deletions

View File

@ -140,6 +140,14 @@ class NodeShellTest(utils.BaseTestCase):
}
client_mock.node.create.assert_called_once_with(**kwargs)
def test_do_node_create_with_uuid(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
args.uuid = 'fef99cb8-a0d1-43df-b084-17b3b42b3cbd'
n_shell.do_node_create(client_mock, args)
client_mock.node.create.assert_called_once_with(uuid=args.uuid)
def test_do_node_show(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()

View File

@ -134,10 +134,14 @@ def do_node_list(cc, args):
action='append',
help="Record arbitrary key/value metadata. "
"Can be specified multiple times")
@cliutils.arg(
'-u', '--uuid',
metavar='<uuid>',
help="Unique UUID for the node")
def do_node_create(cc, args):
"""Register a new node with the Ironic service."""
field_list = ['chassis_uuid', 'driver', 'driver_info',
'properties', 'extra']
'properties', 'extra', 'uuid']
fields = dict((k, v) for (k, v) in vars(args).items()
if k in field_list and not (v is None))
fields = utils.args_array_to_dict(fields, 'driver_info')
@ -145,7 +149,6 @@ def do_node_create(cc, args):
fields = utils.args_array_to_dict(fields, 'properties')
node = cc.node.create(**fields)
field_list.append('uuid')
data = dict([(f, getattr(node, f, '')) for f in field_list])
cliutils.print_dict(data, wrap=72)