diff --git a/openstackclient/network/v2/port.py b/openstackclient/network/v2/port.py index 078e0982e4..16072bc026 100644 --- a/openstackclient/network/v2/port.py +++ b/openstackclient/network/v2/port.py @@ -820,6 +820,17 @@ class SetPort(common.NeutronCommandWithExtraArgs): "(Specify both --allowed-address and --no-allowed-address " "to overwrite the current allowed-address pairs)") ) + parser.add_argument( + '--extra-dhcp-option', + metavar='name=[,value=,ip-version={4,6}]', + default=[], + action=parseractions.MultiKeyValueCommaAction, + dest='extra_dhcp_options', + required_keys=['name'], + optional_keys=['value', "ip-version"], + help=_('Extra DHCP options to be assigned to this port: ' + 'name=[,value=,ip-version={4,6}] ' + '(repeat option to set multiple extra DHCP options)')) parser.add_argument( '--data-plane-status', metavar='', @@ -882,6 +893,10 @@ class SetPort(common.NeutronCommandWithExtraArgs): attrs['allowed_address_pairs'].extend( _convert_address_pairs(parsed_args) ) + + if parsed_args.extra_dhcp_options: + attrs["extra_dhcp_opts"] = _convert_extra_dhcp_options(parsed_args) + if parsed_args.data_plane_status: attrs['data_plane_status'] = parsed_args.data_plane_status diff --git a/openstackclient/tests/unit/network/v2/test_port.py b/openstackclient/tests/unit/network/v2/test_port.py index 3c18f362fc..6f830aa6c5 100644 --- a/openstackclient/tests/unit/network/v2/test_port.py +++ b/openstackclient/tests/unit/network/v2/test_port.py @@ -1727,6 +1727,27 @@ class TestSetPort(TestPort): self.network.update_port.assert_called_once_with(self._port, **attrs) self.assertIsNone(result) + def test_set_port_extra_dhcp_option(self): + arglist = [ + '--extra-dhcp-option', 'name=foo,value=bar', + self._port.name, + ] + verifylist = [ + ('extra_dhcp_options', [{'name': 'foo', + 'value': 'bar'}]), + ('port', self._port.name), + ] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + result = self.cmd.take_action(parsed_args) + + attrs = { + 'extra_dhcp_opts': [{'opt_name': 'foo', + 'opt_value': 'bar'}], + } + self.network.update_port.assert_called_once_with(self._port, **attrs) + self.assertIsNone(result) + def test_set_port_security_enabled(self): arglist = [ '--enable-port-security',