Skip to content

Commit c387f83

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Add dns-domain support to Network object"
2 parents a2e1e6b + b8754e1 commit c387f83

7 files changed

Lines changed: 83 additions & 6 deletions

File tree

doc/source/cli/command-objects/network.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Create new network
3333
[--provider-segment <provider-segment>]
3434
[--qos-policy <qos-policy>]
3535
[--transparent-vlan | --no-transparent-vlan]
36+
[--dns-domain <dns-domain>]
3637
[--tag <tag> | --no-tag]
3738
<name>
3839
@@ -173,6 +174,10 @@ Create new network
173174
174175
*Network version 2 only*
175176
177+
.. option:: --dns-domain <dns-domain>
178+
179+
Set DNS domain for this network (requires DNS integration extension).
180+
176181
.. option:: --tag <tag>
177182
178183
Tag to be added to the network (repeat option to set multiple tags)
@@ -367,6 +372,7 @@ Set network properties
367372
[--provider-physical-network <provider-physical-network>]
368373
[--provider-segment <provider-segment>]
369374
[--qos-policy <qos-policy> | --no-qos-policy]
375+
[--dns-domain <dns-domain>]
370376
[--tag <tag>] [--no-tag]
371377
<network>
372378
@@ -446,6 +452,10 @@ Set network properties
446452
447453
Remove the QoS policy attached to this network
448454
455+
.. option:: --dns-domain <dns-domain>
456+
457+
Set DNS domain for this network (requires DNS integration extension).
458+
449459
.. option:: --tag <tag>
450460
451461
Tag to be added to the network (repeat option to set multiple tags)

openstackclient/network/common.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#
1313

1414
import abc
15+
import contextlib
1516
import logging
1617

1718
import openstack.exceptions
@@ -24,6 +25,30 @@
2425

2526
LOG = logging.getLogger(__name__)
2627

28+
_required_opt_extensions_map = {
29+
'allowed_address_pairs': 'allowed-address-pairs',
30+
'dns_domain': 'dns-integration',
31+
'dns_name': 'dns-integration',
32+
'extra_dhcp_opts': 'extra_dhcp_opt',
33+
'qos_policy_id': 'qos',
34+
'security_groups': 'security-groups',
35+
}
36+
37+
38+
@contextlib.contextmanager
39+
def check_missing_extension_if_error(client_manager, attrs):
40+
# If specified option requires extension, then try to
41+
# find out if it exists. If it does not exist,
42+
# then an exception with the appropriate message
43+
# will be thrown from within client.find_extension
44+
try:
45+
yield
46+
except openstack.exceptions.HttpException:
47+
for opt, ext in _required_opt_extensions_map.items():
48+
if opt in attrs:
49+
client_manager.find_extension(ext, ignore_missing=False)
50+
raise
51+
2752

2853
@six.add_metaclass(abc.ABCMeta)
2954
class NetworkAndComputeCommand(command.Command):

openstackclient/network/v2/network.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ def _get_attrs_network(client_manager, parsed_args):
134134
attrs['qos_policy_id'] = _qos_policy.id
135135
if 'no_qos_policy' in parsed_args and parsed_args.no_qos_policy:
136136
attrs['qos_policy_id'] = None
137+
# Update DNS network options
138+
if parsed_args.dns_domain:
139+
attrs['dns_domain'] = parsed_args.dns_domain
137140
return attrs
138141

139142

@@ -171,6 +174,13 @@ def _add_additional_network_options(parser):
171174
dest='segmentation_id',
172175
help=_("VLAN ID for VLAN networks or Tunnel ID for "
173176
"GENEVE/GRE/VXLAN networks"))
177+
parser.add_argument(
178+
'--dns-domain',
179+
metavar='<dns-domain>',
180+
dest='dns_domain',
181+
help=_("Set DNS domain for this network "
182+
"(requires DNS integration extension)")
183+
)
174184

175185

176186
# TODO(sindhu): Use the SDK resource mapped attribute names once the
@@ -308,8 +318,10 @@ def take_action_network(self, client, parsed_args):
308318
attrs['vlan_transparent'] = True
309319
if parsed_args.no_transparent_vlan:
310320
attrs['vlan_transparent'] = False
321+
with common.check_missing_extension_if_error(
322+
self.app.client_manager.network, attrs):
323+
obj = client.create_network(**attrs)
311324

312-
obj = client.create_network(**attrs)
313325
# tags cannot be set when created, so tags need to be set later.
314326
_tag.update_tags_for_set(client, obj, parsed_args)
315327
display_columns, columns = _get_columns_network(obj)
@@ -690,7 +702,9 @@ def take_action(self, parsed_args):
690702

691703
attrs = _get_attrs_network(self.app.client_manager, parsed_args)
692704
if attrs:
693-
client.update_network(obj, **attrs)
705+
with common.check_missing_extension_if_error(
706+
self.app.client_manager.network, attrs):
707+
client.update_network(obj, **attrs)
694708

695709
# tags is a subresource and it needs to be updated separately.
696710
_tag.update_tags_for_set(client, obj, parsed_args)

openstackclient/network/v2/port.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
from openstackclient.i18n import _
2727
from openstackclient.identity import common as identity_common
28+
from openstackclient.network import common
2829
from openstackclient.network import sdk_utils
2930
from openstackclient.network.v2 import _tag
3031

@@ -281,8 +282,8 @@ def _add_updatable_args(parser):
281282
)
282283
parser.add_argument(
283284
'--dns-name',
284-
metavar='dns-name',
285-
help=_("Set DNS name to this port "
285+
metavar='<dns-name>',
286+
help=_("Set DNS name for this port "
286287
"(requires DNS integration extension)")
287288
)
288289

@@ -437,7 +438,10 @@ def take_action(self, parsed_args):
437438
if parsed_args.qos_policy:
438439
attrs['qos_policy_id'] = client.find_qos_policy(
439440
parsed_args.qos_policy, ignore_missing=False).id
440-
obj = client.create_port(**attrs)
441+
with common.check_missing_extension_if_error(
442+
self.app.client_manager.network, attrs):
443+
obj = client.create_port(**attrs)
444+
441445
# tags cannot be set when created, so tags need to be set later.
442446
_tag.update_tags_for_set(client, obj, parsed_args)
443447
display_columns, columns = _get_columns(obj)
@@ -790,7 +794,9 @@ def take_action(self, parsed_args):
790794
attrs['data_plane_status'] = parsed_args.data_plane_status
791795

792796
if attrs:
793-
client.update_port(obj, **attrs)
797+
with common.check_missing_extension_if_error(
798+
self.app.client_manager.network, attrs):
799+
client.update_port(obj, **attrs)
794800

795801
# tags is a subresource and it needs to be updated separately.
796802
_tag.update_tags_for_set(client, obj, parsed_args)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ def create_one_network(attrs=None):
335335
'name': 'network-name-' + uuid.uuid4().hex,
336336
'status': 'ACTIVE',
337337
'description': 'network-description-' + uuid.uuid4().hex,
338+
'dns_domain': 'example.org.',
338339
'mtu': '1350',
339340
'tenant_id': 'project-id-' + uuid.uuid4().hex,
340341
'admin_state_up': True,

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class TestCreateNetworkIdentityV3(TestNetwork):
6060
'availability_zone_hints',
6161
'availability_zones',
6262
'description',
63+
'dns_domain',
6364
'id',
6465
'ipv4_address_scope',
6566
'ipv6_address_scope',
@@ -84,6 +85,7 @@ class TestCreateNetworkIdentityV3(TestNetwork):
8485
utils.format_list(_network.availability_zone_hints),
8586
utils.format_list(_network.availability_zones),
8687
_network.description,
88+
_network.dns_domain,
8789
_network.id,
8890
_network.ipv4_address_scope_id,
8991
_network.ipv6_address_scope_id,
@@ -162,6 +164,7 @@ def test_create_all_options(self):
162164
"--qos-policy", self.qos_policy.id,
163165
"--transparent-vlan",
164166
"--enable-port-security",
167+
"--dns-domain", "example.org.",
165168
self._network.name,
166169
]
167170
verifylist = [
@@ -181,6 +184,7 @@ def test_create_all_options(self):
181184
('transparent_vlan', True),
182185
('enable_port_security', True),
183186
('name', self._network.name),
187+
('dns_domain', 'example.org.'),
184188
]
185189

186190
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -204,6 +208,7 @@ def test_create_all_options(self):
204208
'qos_policy_id': self.qos_policy.id,
205209
'vlan_transparent': True,
206210
'port_security_enabled': True,
211+
'dns_domain': 'example.org.',
207212
})
208213
self.assertEqual(self.columns, columns)
209214
self.assertEqual(self.data, data)
@@ -287,6 +292,7 @@ class TestCreateNetworkIdentityV2(TestNetwork):
287292
'availability_zone_hints',
288293
'availability_zones',
289294
'description',
295+
'dns_domain',
290296
'id',
291297
'ipv4_address_scope',
292298
'ipv6_address_scope',
@@ -311,6 +317,7 @@ class TestCreateNetworkIdentityV2(TestNetwork):
311317
utils.format_list(_network.availability_zone_hints),
312318
utils.format_list(_network.availability_zones),
313319
_network.description,
320+
_network.dns_domain,
314321
_network.id,
315322
_network.ipv4_address_scope_id,
316323
_network.ipv6_address_scope_id,
@@ -901,6 +908,7 @@ def test_set_this(self):
901908
'--name', 'noob',
902909
'--share',
903910
'--description', self._network.description,
911+
'--dns-domain', 'example.org.',
904912
'--external',
905913
'--default',
906914
'--provider-network-type', 'vlan',
@@ -922,6 +930,7 @@ def test_set_this(self):
922930
('segmentation_id', '400'),
923931
('enable_port_security', True),
924932
('qos_policy', self.qos_policy.name),
933+
('dns_domain', 'example.org.'),
925934
]
926935

927936
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -939,6 +948,7 @@ def test_set_this(self):
939948
'provider:segmentation_id': '400',
940949
'port_security_enabled': True,
941950
'qos_policy_id': self.qos_policy.id,
951+
'dns_domain': 'example.org.',
942952
}
943953
self.network.update_network.assert_called_once_with(
944954
self._network, **attrs)
@@ -1026,6 +1036,7 @@ class TestShowNetwork(TestNetwork):
10261036
'availability_zone_hints',
10271037
'availability_zones',
10281038
'description',
1039+
'dns_domain',
10291040
'id',
10301041
'ipv4_address_scope',
10311042
'ipv6_address_scope',
@@ -1050,6 +1061,7 @@ class TestShowNetwork(TestNetwork):
10501061
utils.format_list(_network.availability_zone_hints),
10511062
utils.format_list(_network.availability_zones),
10521063
_network.description,
1064+
_network.dns_domain,
10531065
_network.id,
10541066
_network.ipv4_address_scope_id,
10551067
_network.ipv6_address_scope_id,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
features:
3+
- |
4+
Add dns-domain support for network commands.
5+
The new parameter ``--dns-domain`` is added to the ``network create``
6+
and ``network set`` commands. This parameter sets
7+
the domain name for the network.
8+
Check backend available extension and return an error
9+
message if it is missing (instead of a Bad Request HTTP 400).

0 commit comments

Comments
 (0)