Merge "openstack port create support --extra-dhcp-option"
This commit is contained in:
commit
6f60f833e8
@ -280,6 +280,19 @@ def _convert_address_pairs(parsed_args):
|
||||
return ops
|
||||
|
||||
|
||||
def _convert_extra_dhcp_options(parsed_args):
|
||||
dhcp_options = []
|
||||
for opt in parsed_args.extra_dhcp_options:
|
||||
option = {}
|
||||
option['opt_name'] = opt['name']
|
||||
if 'value' in opt:
|
||||
option['opt_value'] = opt['value']
|
||||
if 'ip-version' in opt:
|
||||
option['ip_version'] = opt['ip-version']
|
||||
dhcp_options.append(option)
|
||||
return dhcp_options
|
||||
|
||||
|
||||
class CreatePort(command.ShowOne):
|
||||
_description = _("Create a new port")
|
||||
|
||||
@ -350,8 +363,18 @@ class CreatePort(command.ShowOne):
|
||||
metavar='<name>',
|
||||
help=_("Name of this port")
|
||||
)
|
||||
# TODO(singhj): Add support for extended options:
|
||||
# dhcp
|
||||
parser.add_argument(
|
||||
'--extra-dhcp-option',
|
||||
metavar='name=<name>[,value=<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=<name>[,value=<value>,ip-version={4,6}] '
|
||||
'(repeat option to set multiple extra DHCP options)'))
|
||||
|
||||
secgroups = parser.add_mutually_exclusive_group()
|
||||
secgroups.add_argument(
|
||||
'--security-group',
|
||||
@ -425,6 +448,9 @@ class CreatePort(command.ShowOne):
|
||||
attrs['allowed_address_pairs'] = (
|
||||
_convert_address_pairs(parsed_args))
|
||||
|
||||
if parsed_args.extra_dhcp_options:
|
||||
attrs["extra_dhcp_opts"] = _convert_extra_dhcp_options(parsed_args)
|
||||
|
||||
if parsed_args.qos_policy:
|
||||
attrs['qos_policy_id'] = client.find_qos_policy(
|
||||
parsed_args.qos_policy, ignore_missing=False).id
|
||||
|
@ -611,6 +611,48 @@ class TestCreatePort(TestPort):
|
||||
def test_create_with_uplink_status_propagation_disabled(self):
|
||||
self._test_create_with_uplink_status_propagation(enable=False)
|
||||
|
||||
def test_create_port_with_extra_dhcp_option(self):
|
||||
extra_dhcp_options = [{'opt_name': 'classless-static-route',
|
||||
'opt_value': '169.254.169.254/32,22.2.0.2,'
|
||||
'0.0.0.0/0,22.2.0.1',
|
||||
'ip_version': '4'},
|
||||
{'opt_name': 'dns-server',
|
||||
'opt_value': '240C::6666',
|
||||
'ip_version': '6'}]
|
||||
arglist = [
|
||||
'--network', self._port.network_id,
|
||||
'--extra-dhcp-option', 'name=classless-static-route,'
|
||||
'value=169.254.169.254/32,22.2.0.2,'
|
||||
'0.0.0.0/0,22.2.0.1,'
|
||||
'ip-version=4',
|
||||
'--extra-dhcp-option', 'name=dns-server,value=240C::6666,'
|
||||
'ip-version=6',
|
||||
'test-port',
|
||||
]
|
||||
|
||||
verifylist = [
|
||||
('network', self._port.network_id,),
|
||||
('extra_dhcp_options', [{'name': 'classless-static-route',
|
||||
'value': '169.254.169.254/32,22.2.0.2,'
|
||||
'0.0.0.0/0,22.2.0.1',
|
||||
'ip-version': '4'},
|
||||
{'name': 'dns-server',
|
||||
'value': '240C::6666',
|
||||
'ip-version': '6'}]),
|
||||
('name', 'test-port'),
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
self.network.create_port.assert_called_once_with(**{
|
||||
'admin_state_up': True,
|
||||
'network_id': self._port.network_id,
|
||||
'extra_dhcp_opts': extra_dhcp_options,
|
||||
'name': 'test-port',
|
||||
})
|
||||
|
||||
|
||||
class TestDeletePort(TestPort):
|
||||
|
||||
|
@ -0,0 +1,6 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Add ``--extra-dhcp-options`` parameter to the ``port create`` command. The
|
||||
neutronclient ``port-create`` command can accept extra DHCP options, add
|
||||
it to the openstackclient in order to be consistent.
|
Loading…
Reference in New Issue
Block a user