diff --git a/ironicclient/osc/v1/baremetal_port.py b/ironicclient/osc/v1/baremetal_port.py index 027416b73..37996bf4b 100644 --- a/ironicclient/osc/v1/baremetal_port.py +++ b/ironicclient/osc/v1/baremetal_port.py @@ -254,12 +254,37 @@ class SetBaremetalPort(command.Command): help=_('Extra to set on this baremetal port ' '(repeat option to set multiple extras)') ) - parser.add_argument( "--port-group", metavar="", dest='portgroup_uuid', help=_('Set UUID of the port group that this port belongs to.')) + parser.add_argument( + "--local-link-connection", + metavar="", + action='append', + help=_("Key/value metadata describing local link connection " + "information. Valid keys are switch_info, switch_id, " + "port_id; switch_id and port_id are obligatory (repeat " + "option to specify multiple keys).") + ) + pxe_enabled_group = parser.add_mutually_exclusive_group(required=False) + pxe_enabled_group.add_argument( + "--pxe-enabled", + dest='pxe_enabled', + default=None, + action='store_true', + help=_("Indicates that this port should be used when " + "PXE booting this node (default)") + ) + pxe_enabled_group.add_argument( + "--pxe-disabled", + dest='pxe_enabled', + default=None, + action='store_false', + help=_("Indicates that this port should not be used when " + "PXE booting this node") + ) return parser @@ -282,6 +307,13 @@ class SetBaremetalPort(command.Command): if parsed_args.portgroup_uuid: portgroup_uuid = ["portgroup_uuid=%s" % parsed_args.portgroup_uuid] properties.extend(utils.args_array_to_patch('add', portgroup_uuid)) + if parsed_args.local_link_connection: + properties.extend(utils.args_array_to_patch( + 'add', ['local_link_connection/' + x for x in + parsed_args.local_link_connection])) + if parsed_args.pxe_enabled is not None: + properties.extend(utils.args_array_to_patch( + 'add', ['pxe_enabled=%s' % parsed_args.pxe_enabled])) if properties: baremetal_client.port.update(parsed_args.port, properties) diff --git a/ironicclient/tests/unit/osc/v1/test_baremetal_port.py b/ironicclient/tests/unit/osc/v1/test_baremetal_port.py index 516585cd0..7b9bc1bb7 100644 --- a/ironicclient/tests/unit/osc/v1/test_baremetal_port.py +++ b/ironicclient/tests/unit/osc/v1/test_baremetal_port.py @@ -431,6 +431,51 @@ class TestBaremetalPortSet(TestBaremetalPort): [{'path': '/portgroup_uuid', 'value': new_portgroup_uuid, 'op': 'add'}]) + def test_baremetal_set_local_link_connection(self): + arglist = [ + baremetal_fakes.baremetal_port_uuid, + '--local-link-connection', 'switch_info=bar'] + verifylist = [('port', baremetal_fakes.baremetal_port_uuid), + ('local_link_connection', ['switch_info=bar'])] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + self.cmd.take_action(parsed_args) + self.baremetal_mock.port.update.assert_called_once_with( + baremetal_fakes.baremetal_port_uuid, + [{'path': '/local_link_connection/switch_info', 'value': 'bar', + 'op': 'add'}]) + + def test_baremetal_port_set_pxe_enabled(self): + arglist = [ + baremetal_fakes.baremetal_port_uuid, + '--pxe-enabled'] + verifylist = [ + ('port', baremetal_fakes.baremetal_port_uuid), + ('pxe_enabled', True)] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + self.cmd.take_action(parsed_args) + self.baremetal_mock.port.update.assert_called_once_with( + baremetal_fakes.baremetal_port_uuid, + [{'path': '/pxe_enabled', 'value': 'True', 'op': 'add'}]) + + def test_baremetal_port_set_pxe_disabled(self): + arglist = [ + baremetal_fakes.baremetal_port_uuid, + '--pxe-disabled'] + verifylist = [ + ('port', baremetal_fakes.baremetal_port_uuid), + ('pxe_enabled', False)] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + self.cmd.take_action(parsed_args) + self.baremetal_mock.port.update.assert_called_once_with( + baremetal_fakes.baremetal_port_uuid, + [{'path': '/pxe_enabled', 'value': 'False', 'op': 'add'}]) + def test_baremetal_port_set_no_options(self): arglist = [] verifylist = [] diff --git a/releasenotes/notes/osc-port-set-llc-pxeenabled-21fd8ea1982af17e.yaml b/releasenotes/notes/osc-port-set-llc-pxeenabled-21fd8ea1982af17e.yaml new file mode 100644 index 000000000..3e5662e4a --- /dev/null +++ b/releasenotes/notes/osc-port-set-llc-pxeenabled-21fd8ea1982af17e.yaml @@ -0,0 +1,13 @@ +--- +features: + - | + For ``openstack baremetal port set``, adds these options: + + * ``--local-link-connection ``: Key/value metadata describing + local link connection information. Valid keys are switch_info, switch_id, + port_id; switch_id and port_id are obligatory (repeat option to specify + multiple keys). + * ``--pxe-enabled``: Indicates that this port should be used when PXE + booting this node (default) + * ``--pxe-disabled``: Indicates that this port should not be used when PXE + booting this node