Skip to content

Commit df5f12b

Browse files
namnh68Ha Van Tu
andcommitted
Add "dns-name" option to "os port create" and "os port set"
This patch added a "dns-name" option to "os port create" and "os port set" command. Change-Id: I360e2c9a1970e64fe17e4561d7618f860b937373 Co-Authored-By: Ha Van Tu <tuhv@vn.fujitsu.com> Partial-Bug: #1612136 Partially-Implements: blueprint network-commands-options
1 parent c0dd808 commit df5f12b

4 files changed

Lines changed: 75 additions & 0 deletions

File tree

doc/source/command-objects/port.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Create new port
2828
[--enable | --disable]
2929
[--mac-address <mac-address>]
3030
[--security-group <security-group> | --no-security-group]
31+
[--dns-name <dns-name>]
3132
[--project <project> [--project-domain <project-domain>]]
3233
[--enable-port-security | --disable-port-security]
3334
<name>
@@ -91,6 +92,11 @@ Create new port
9192
9293
Associate no security groups with this port
9394
95+
.. option:: --dns-name <dns-name>
96+
97+
Set DNS name to this port
98+
(requires DNS integration extension)
99+
94100
.. option:: --project <project>
95101
96102
Owner's project (name or ID)
@@ -192,6 +198,7 @@ Set port properties
192198
[--security-group <security-group>]
193199
[--no-security-group]
194200
[--enable-port-security | --disable-port-security]
201+
[--dns-name <dns-name>]
195202
<port>
196203
197204
.. option:: --description <description>
@@ -269,6 +276,11 @@ Set port properties
269276
270277
Disable port security for this port
271278
279+
.. option:: --dns-name <dns-name>
280+
281+
Set DNS name to this port
282+
(requires DNS integration extension)
283+
272284
.. _port_set-port:
273285
.. describe:: <port>
274286

openstackclient/network/v2/port.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ def _get_attrs(client_manager, parsed_args):
128128
if parsed_args.host:
129129
attrs['binding:host_id'] = parsed_args.host
130130

131+
if parsed_args.dns_name is not None:
132+
attrs['dns_name'] = parsed_args.dns_name
131133
# It is possible that name is not updated during 'port set'
132134
if parsed_args.name is not None:
133135
attrs['name'] = str(parsed_args.name)
@@ -233,6 +235,12 @@ def _add_updatable_args(parser):
233235
metavar='<host-id>',
234236
help=argparse.SUPPRESS,
235237
)
238+
parser.add_argument(
239+
'--dns-name',
240+
metavar='dns-name',
241+
help=_("Set DNS name to this port "
242+
"(requires DNS integration extension)")
243+
)
236244

237245

238246
class CreatePort(command.ShowOne):

openstackclient/tests/unit/network/v2/test_port.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ def test_create_full_options(self):
140140
'--binding-profile', 'foo=bar',
141141
'--binding-profile', 'foo2=bar2',
142142
'--network', self._port.network_id,
143+
'--dns-name', '8.8.8.8',
143144
'test-port',
144145

145146
]
@@ -156,6 +157,7 @@ def test_create_full_options(self):
156157
('vnic_type', 'macvtap'),
157158
('binding_profile', {'foo': 'bar', 'foo2': 'bar2'}),
158159
('network', self._port.network_id),
160+
('dns_name', '8.8.8.8'),
159161
('name', 'test-port'),
160162

161163
]
@@ -174,6 +176,7 @@ def test_create_full_options(self):
174176
'binding:vnic_type': 'macvtap',
175177
'binding:profile': {'foo': 'bar', 'foo2': 'bar2'},
176178
'network_id': self._port.network_id,
179+
'dns_name': '8.8.8.8',
177180
'name': 'test-port',
178181
})
179182

@@ -241,6 +244,7 @@ def test_create_with_security_group(self):
241244
'--security-group', secgroup.id,
242245
'test-port',
243246
]
247+
244248
verifylist = [
245249
('network', self._port.network_id,),
246250
('enable', True),
@@ -262,6 +266,33 @@ def test_create_with_security_group(self):
262266
self.assertEqual(ref_columns, columns)
263267
self.assertEqual(ref_data, data)
264268

269+
def test_create_port_with_dns_name(self):
270+
arglist = [
271+
'--network', self._port.network_id,
272+
'--dns-name', '8.8.8.8',
273+
'test-port',
274+
]
275+
verifylist = [
276+
('network', self._port.network_id,),
277+
('enable', True),
278+
('dns_name', '8.8.8.8'),
279+
('name', 'test-port'),
280+
]
281+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
282+
283+
columns, data = (self.cmd.take_action(parsed_args))
284+
285+
self.network.create_port.assert_called_once_with(**{
286+
'admin_state_up': True,
287+
'network_id': self._port.network_id,
288+
'dns_name': '8.8.8.8',
289+
'name': 'test-port',
290+
})
291+
292+
ref_columns, ref_data = self._get_common_cols_data(self._port)
293+
self.assertEqual(ref_columns, columns)
294+
self.assertEqual(ref_data, data)
295+
265296
def test_create_with_security_groups(self):
266297
sg_1 = network_fakes.FakeSecurityGroup.create_one_security_group()
267298
sg_2 = network_fakes.FakeSecurityGroup.create_one_security_group()
@@ -676,6 +707,25 @@ def test_set_fixed_ip(self):
676707
self.network.update_port.assert_called_once_with(self._port, **attrs)
677708
self.assertIsNone(result)
678709

710+
def test_set_dns_name(self):
711+
arglist = [
712+
'--dns-name', '8.8.8.8',
713+
self._port.name,
714+
]
715+
verifylist = [
716+
('dns_name', '8.8.8.8'),
717+
('port', self._port.name),
718+
]
719+
720+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
721+
result = self.cmd.take_action(parsed_args)
722+
723+
attrs = {
724+
'dns_name': '8.8.8.8',
725+
}
726+
self.network.update_port.assert_called_once_with(self._port, **attrs)
727+
self.assertIsNone(result)
728+
679729
def test_append_fixed_ip(self):
680730
_testport = network_fakes.FakePort.create_one_port(
681731
{'fixed_ips': [{'ip_address': '0.0.0.1'}]})
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
features:
3+
- |
4+
Add ``--dns-name`` option to ``os port create`` and ``os port set`` commands.
5+
[Bug `1612136 <https://bugs.launchpad.net/python-openstackclient/+bug/1612136>`_]

0 commit comments

Comments
 (0)