Skip to content

Commit 60a91a6

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add external network options to osc network create"
2 parents 523ab58 + 107bc51 commit 60a91a6

5 files changed

Lines changed: 79 additions & 1 deletion

File tree

doc/source/command-objects/network.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Create new network
1717
[--enable | --disable]
1818
[--share | --no-share]
1919
[--availability-zone-hint <availability-zone>]
20+
[--external [--default | --no-default] | --internal]
2021
<name>
2122
2223
.. option:: --project <project>
@@ -59,6 +60,29 @@ Create new network
5960
IPv4 subnet for fixed IPs (in CIDR notation)
6061
(Compute v2 network only)
6162
63+
.. option:: --external
64+
65+
Set this network as an external network.
66+
Requires the "external-net" extension to be enabled.
67+
(Network v2 only)
68+
69+
.. option:: --internal
70+
71+
Set this network as an internal network (default)
72+
(Network v2 only)
73+
74+
.. option:: --default
75+
76+
Specify if this network should be used as
77+
the default external network
78+
(Network v2 only)
79+
80+
.. option:: --no-default
81+
82+
Do not use the network as the default external network.
83+
By default, no network is set as an external network.
84+
(Network v2 only)
85+
6286
.. _network_create-name:
6387
.. describe:: <name>
6488

openstackclient/network/v2/network.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,27 @@ def update_parser_network(self, parser):
144144
'(requires the Network Availability Zone extension, '
145145
'this option can be repeated).',
146146
)
147+
external_router_grp = parser.add_mutually_exclusive_group()
148+
external_router_grp.add_argument(
149+
'--external',
150+
action='store_true',
151+
help='Set this network as an external network. '
152+
'Requires the "external-net" extension to be enabled.')
153+
external_router_grp.add_argument(
154+
'--internal',
155+
action='store_true',
156+
help='Set this network as an internal network (default)')
157+
default_router_grp = parser.add_mutually_exclusive_group()
158+
default_router_grp.add_argument(
159+
'--default',
160+
action='store_true',
161+
help='Specify if this network should be used as '
162+
'the default external network')
163+
default_router_grp.add_argument(
164+
'--no-default',
165+
action='store_true',
166+
help='Do not use the network as the default external network.'
167+
'By default, no network is set as an external network.')
147168
return parser
148169

149170
def update_parser_compute(self, parser):
@@ -156,6 +177,14 @@ def update_parser_compute(self, parser):
156177

157178
def take_action_network(self, client, parsed_args):
158179
attrs = _get_attrs(self.app.client_manager, parsed_args)
180+
if parsed_args.internal:
181+
attrs['router:external'] = False
182+
if parsed_args.external:
183+
attrs['router:external'] = True
184+
if parsed_args.no_default:
185+
attrs['is_default'] = False
186+
if parsed_args.default:
187+
attrs['is_default'] = True
159188
obj = client.create_network(**attrs)
160189
columns = _get_columns(obj)
161190
data = utils.get_item_properties(obj, columns, formatters=_formatters)

openstackclient/tests/network/v2/fakes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ def create_one_network(attrs={}, methods={}):
152152
'router_external': True,
153153
'availability_zones': [],
154154
'availability_zone_hints': [],
155+
'is_default': False,
155156
}
156157

157158
# Overwrite default attributes.
@@ -161,7 +162,7 @@ def create_one_network(attrs={}, methods={}):
161162
network_methods = {
162163
'keys': ['id', 'name', 'admin_state_up', 'router_external',
163164
'status', 'subnets', 'tenant_id', 'availability_zones',
164-
'availability_zone_hints'],
165+
'availability_zone_hints', 'is_default'],
165166
}
166167

167168
# Overwrite default methods.

openstackclient/tests/network/v2/test_network.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class TestCreateNetworkIdentityV3(TestNetwork):
5151
'availability_zone_hints',
5252
'availability_zones',
5353
'id',
54+
'is_default',
5455
'name',
5556
'project_id',
5657
'router_external',
@@ -63,6 +64,7 @@ class TestCreateNetworkIdentityV3(TestNetwork):
6364
utils.format_list(_network.availability_zone_hints),
6465
utils.format_list(_network.availability_zones),
6566
_network.id,
67+
_network.is_default,
6668
_network.name,
6769
_network.project_id,
6870
network._format_router_external(_network.router_external),
@@ -119,6 +121,7 @@ def test_create_default_options(self):
119121
('enable', True),
120122
('share', None),
121123
('project', None),
124+
('external', False),
122125
]
123126

124127
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -138,6 +141,7 @@ def test_create_all_options(self):
138141
"--project", identity_fakes_v3.project_name,
139142
"--project-domain", identity_fakes_v3.domain_name,
140143
"--availability-zone-hint", "nova",
144+
"--external", "--default",
141145
self._network.name,
142146
]
143147
verifylist = [
@@ -146,6 +150,8 @@ def test_create_all_options(self):
146150
('project', identity_fakes_v3.project_name),
147151
('project_domain', identity_fakes_v3.domain_name),
148152
('availability_zone_hints', ["nova"]),
153+
('external', True),
154+
('default', True),
149155
('name', self._network.name),
150156
]
151157

@@ -158,6 +164,8 @@ def test_create_all_options(self):
158164
'name': self._network.name,
159165
'shared': True,
160166
'tenant_id': identity_fakes_v3.project_id,
167+
'is_default': True,
168+
'router:external': True,
161169
})
162170
self.assertEqual(self.columns, columns)
163171
self.assertEqual(self.data, data)
@@ -172,6 +180,7 @@ def test_create_other_options(self):
172180
('enable', True),
173181
('no_share', True),
174182
('name', self._network.name),
183+
('external', False),
175184
]
176185

177186
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -198,6 +207,7 @@ class TestCreateNetworkIdentityV2(TestNetwork):
198207
'availability_zone_hints',
199208
'availability_zones',
200209
'id',
210+
'is_default',
201211
'name',
202212
'project_id',
203213
'router_external',
@@ -210,6 +220,7 @@ class TestCreateNetworkIdentityV2(TestNetwork):
210220
utils.format_list(_network.availability_zone_hints),
211221
utils.format_list(_network.availability_zones),
212222
_network.id,
223+
_network.is_default,
213224
_network.name,
214225
_network.project_id,
215226
network._format_router_external(_network.router_external),
@@ -253,6 +264,7 @@ def test_create_with_project_identityv2(self):
253264
('share', None),
254265
('name', self._network.name),
255266
('project', identity_fakes_v2.project_name),
267+
('external', False),
256268
]
257269

258270
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -278,6 +290,7 @@ def test_create_with_domain_identityv2(self):
278290
('project', identity_fakes_v3.project_name),
279291
('project_domain', identity_fakes_v3.domain_name),
280292
('name', self._network.name),
293+
('external', False),
281294
]
282295

283296
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -514,6 +527,7 @@ class TestShowNetwork(TestNetwork):
514527
'availability_zone_hints',
515528
'availability_zones',
516529
'id',
530+
'is_default',
517531
'name',
518532
'project_id',
519533
'router_external',
@@ -526,6 +540,7 @@ class TestShowNetwork(TestNetwork):
526540
utils.format_list(_network.availability_zone_hints),
527541
utils.format_list(_network.availability_zones),
528542
_network.id,
543+
_network.is_default,
529544
_network.name,
530545
_network.project_id,
531546
network._format_router_external(_network.router_external),
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
features:
3+
- |
4+
New options have been added to the ``network create`` command
5+
to support external network functionality. The new options are
6+
``--external/--internal`` and suboptions to ``external``:
7+
``--default/--no-default``.
8+
These options are available for Networkv2 only.
9+
[Bug `1545537 <https://bugs.launchpad.net/bugs/1545537>`_]

0 commit comments

Comments
 (0)