summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNam Nguyen Hoai <namnh@vn.fujitsu.com>2016-08-12 16:00:52 +0700
committerNam Nguyen Hoai <namnh@vn.fujitsu.com>2016-12-03 17:08:17 +0700
commitdf5f12b135f273e3916e7bf300fa7688a180ea02 (patch)
tree6f57083a6d85dd5bb5f6115a1080e7dac03f389f
parentc0dd8086e5d811f2ca7d634fd730f8703bbe7924 (diff)
downloadpython-openstackclient-df5f12b135f273e3916e7bf300fa7688a180ea02.tar.gz
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
-rw-r--r--doc/source/command-objects/port.rst12
-rw-r--r--openstackclient/network/v2/port.py8
-rw-r--r--openstackclient/tests/unit/network/v2/test_port.py50
-rw-r--r--releasenotes/notes/bug-1612136-63aac6377209db38.yaml5
4 files changed, 75 insertions, 0 deletions
diff --git a/doc/source/command-objects/port.rst b/doc/source/command-objects/port.rst
index 3aff2f77..73c53290 100644
--- a/doc/source/command-objects/port.rst
+++ b/doc/source/command-objects/port.rst
@@ -28,6 +28,7 @@ Create new port
[--enable | --disable]
[--mac-address <mac-address>]
[--security-group <security-group> | --no-security-group]
+ [--dns-name <dns-name>]
[--project <project> [--project-domain <project-domain>]]
[--enable-port-security | --disable-port-security]
<name>
@@ -91,6 +92,11 @@ Create new port
Associate no security groups with this port
+.. option:: --dns-name <dns-name>
+
+ Set DNS name to this port
+ (requires DNS integration extension)
+
.. option:: --project <project>
Owner's project (name or ID)
@@ -192,6 +198,7 @@ Set port properties
[--security-group <security-group>]
[--no-security-group]
[--enable-port-security | --disable-port-security]
+ [--dns-name <dns-name>]
<port>
.. option:: --description <description>
@@ -269,6 +276,11 @@ Set port properties
Disable port security for this port
+.. option:: --dns-name <dns-name>
+
+ Set DNS name to this port
+ (requires DNS integration extension)
+
.. _port_set-port:
.. describe:: <port>
diff --git a/openstackclient/network/v2/port.py b/openstackclient/network/v2/port.py
index 6cae87ee..c960ba25 100644
--- a/openstackclient/network/v2/port.py
+++ b/openstackclient/network/v2/port.py
@@ -128,6 +128,8 @@ def _get_attrs(client_manager, parsed_args):
if parsed_args.host:
attrs['binding:host_id'] = parsed_args.host
+ if parsed_args.dns_name is not None:
+ attrs['dns_name'] = parsed_args.dns_name
# It is possible that name is not updated during 'port set'
if parsed_args.name is not None:
attrs['name'] = str(parsed_args.name)
@@ -233,6 +235,12 @@ def _add_updatable_args(parser):
metavar='<host-id>',
help=argparse.SUPPRESS,
)
+ parser.add_argument(
+ '--dns-name',
+ metavar='dns-name',
+ help=_("Set DNS name to this port "
+ "(requires DNS integration extension)")
+ )
class CreatePort(command.ShowOne):
diff --git a/openstackclient/tests/unit/network/v2/test_port.py b/openstackclient/tests/unit/network/v2/test_port.py
index 9312a897..aeb9884a 100644
--- a/openstackclient/tests/unit/network/v2/test_port.py
+++ b/openstackclient/tests/unit/network/v2/test_port.py
@@ -140,6 +140,7 @@ class TestCreatePort(TestPort):
'--binding-profile', 'foo=bar',
'--binding-profile', 'foo2=bar2',
'--network', self._port.network_id,
+ '--dns-name', '8.8.8.8',
'test-port',
]
@@ -156,6 +157,7 @@ class TestCreatePort(TestPort):
('vnic_type', 'macvtap'),
('binding_profile', {'foo': 'bar', 'foo2': 'bar2'}),
('network', self._port.network_id),
+ ('dns_name', '8.8.8.8'),
('name', 'test-port'),
]
@@ -174,6 +176,7 @@ class TestCreatePort(TestPort):
'binding:vnic_type': 'macvtap',
'binding:profile': {'foo': 'bar', 'foo2': 'bar2'},
'network_id': self._port.network_id,
+ 'dns_name': '8.8.8.8',
'name': 'test-port',
})
@@ -241,6 +244,7 @@ class TestCreatePort(TestPort):
'--security-group', secgroup.id,
'test-port',
]
+
verifylist = [
('network', self._port.network_id,),
('enable', True),
@@ -262,6 +266,33 @@ class TestCreatePort(TestPort):
self.assertEqual(ref_columns, columns)
self.assertEqual(ref_data, data)
+ def test_create_port_with_dns_name(self):
+ arglist = [
+ '--network', self._port.network_id,
+ '--dns-name', '8.8.8.8',
+ 'test-port',
+ ]
+ verifylist = [
+ ('network', self._port.network_id,),
+ ('enable', True),
+ ('dns_name', '8.8.8.8'),
+ ('name', 'test-port'),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ columns, data = (self.cmd.take_action(parsed_args))
+
+ self.network.create_port.assert_called_once_with(**{
+ 'admin_state_up': True,
+ 'network_id': self._port.network_id,
+ 'dns_name': '8.8.8.8',
+ 'name': 'test-port',
+ })
+
+ ref_columns, ref_data = self._get_common_cols_data(self._port)
+ self.assertEqual(ref_columns, columns)
+ self.assertEqual(ref_data, data)
+
def test_create_with_security_groups(self):
sg_1 = network_fakes.FakeSecurityGroup.create_one_security_group()
sg_2 = network_fakes.FakeSecurityGroup.create_one_security_group()
@@ -676,6 +707,25 @@ class TestSetPort(TestPort):
self.network.update_port.assert_called_once_with(self._port, **attrs)
self.assertIsNone(result)
+ def test_set_dns_name(self):
+ arglist = [
+ '--dns-name', '8.8.8.8',
+ self._port.name,
+ ]
+ verifylist = [
+ ('dns_name', '8.8.8.8'),
+ ('port', self._port.name),
+ ]
+
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ result = self.cmd.take_action(parsed_args)
+
+ attrs = {
+ 'dns_name': '8.8.8.8',
+ }
+ self.network.update_port.assert_called_once_with(self._port, **attrs)
+ self.assertIsNone(result)
+
def test_append_fixed_ip(self):
_testport = network_fakes.FakePort.create_one_port(
{'fixed_ips': [{'ip_address': '0.0.0.1'}]})
diff --git a/releasenotes/notes/bug-1612136-63aac6377209db38.yaml b/releasenotes/notes/bug-1612136-63aac6377209db38.yaml
new file mode 100644
index 00000000..51eaa76d
--- /dev/null
+++ b/releasenotes/notes/bug-1612136-63aac6377209db38.yaml
@@ -0,0 +1,5 @@
+---
+features:
+ - |
+ Add ``--dns-name`` option to ``os port create`` and ``os port set`` commands.
+ [Bug `1612136 <https://bugs.launchpad.net/python-openstackclient/+bug/1612136>`_]