Skip to content

Commit b4307b1

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add Subnet service-types to subnets"
2 parents 085bc52 + cf9ad08 commit b4307b1

6 files changed

Lines changed: 185 additions & 4 deletions

File tree

doc/source/command-objects/subnet.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Create new subnet
2929
[--ipv6-ra-mode {dhcpv6-stateful,dhcpv6-stateless,slaac}]
3030
[--ipv6-address-mode {dhcpv6-stateful,dhcpv6-stateless,slaac}]
3131
[--network-segment <network-segment>]
32+
[--service-type <service-type>]
3233
--network <network>
3334
<name>
3435
@@ -116,6 +117,13 @@ Create new subnet
116117
to change. Use global option ``--os-beta-command``
117118
to enable this command option.
118119
120+
.. option:: --service-type <service-type>
121+
122+
Service type for this subnet e.g.:
123+
``network:floatingip_agent_gateway``.
124+
Must be a valid device owner value for a network port
125+
(repeat option to set multiple service types)
126+
119127
.. option:: --network <network>
120128
121129
Network this subnet belongs to (name or ID)
@@ -171,6 +179,13 @@ List subnets
171179
172180
List subnets which have DHCP disabled
173181
182+
.. option:: --service-type <service-type>
183+
184+
List only subnets of a given service type in output
185+
e.g.: ``network:floatingip_agent_gateway``.
186+
Must be a valid device owner value for a network port
187+
(repeat option to list multiple service types)
188+
174189
subnet set
175190
----------
176191
@@ -185,6 +200,7 @@ Set subnet properties
185200
[--dns-nameserver <dns-nameserver>]
186201
[--gateway <gateway-ip>]
187202
[--host-route destination=<subnet>,gateway=<ip-address>]
203+
[--service-type <service-type>]
188204
[--name <new-name>]
189205
<subnet>
190206
@@ -221,6 +237,13 @@ Set subnet properties
221237
gateway: nexthop IP address
222238
(repeat option to add multiple routes)
223239
240+
.. option:: --service-type <service-type>
241+
242+
Service type for this subnet e.g.:
243+
``network:floatingip_agent_gateway``.
244+
Must be a valid device owner value for a network port
245+
(repeat option to set multiple service types)
246+
224247
.. option:: --name
225248
226249
Updated name of the subnet
@@ -259,6 +282,7 @@ Unset subnet properties
259282
[--allocation-pool start=<ip-address>,end=<ip-address> [...]]
260283
[--dns-nameserver <dns-nameserver> [...]]
261284
[--host-route destination=<subnet>,gateway=<ip-address> [...]]
285+
[--service-type <service-type>]
262286
<subnet>
263287
264288
.. option:: --dns-nameserver <dns-nameserver>
@@ -280,6 +304,13 @@ Unset subnet properties
280304
gateway: nexthop IP address
281305
(repeat option to unset multiple host routes)
282306
307+
.. option:: --service-type <service-type>
308+
309+
Service type to be removed from this subnet e.g.:
310+
``network:floatingip_agent_gateway``.
311+
Must be a valid device owner value for a network port
312+
(repeat option to unset multiple service types)
313+
283314
.. _subnet_unset-subnet:
284315
.. describe:: <subnet>
285316

functional/tests/network/v2/test_subnet.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ def test_subnet_set(self):
5353
raw_output = self.openstack('subnet show ' + self.NAME + opts)
5454
self.assertEqual("False\n" + self.NAME + "\n", raw_output)
5555

56+
def test_subnet_set_service_type(self):
57+
TYPE = 'network:floatingip_agent_gateway'
58+
self.openstack('subnet set --service-type ' + TYPE + ' ' + self.NAME)
59+
opts = self.get_opts(['name', 'service_types'])
60+
raw_output = self.openstack('subnet show ' + self.NAME + opts)
61+
self.assertEqual(self.NAME + "\n" + TYPE + "\n", raw_output)
62+
5663
def test_subnet_show(self):
5764
opts = self.get_opts(self.FIELDS)
5865
raw_output = self.openstack('subnet show ' + self.NAME + opts)

openstackclient/network/v2/subnet.py

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def _format_host_routes(data):
4848
'allocation_pools': _format_allocation_pools,
4949
'dns_nameservers': utils.format_list,
5050
'host_routes': _format_host_routes,
51+
'service_types': utils.format_list,
5152
}
5253

5354

@@ -82,6 +83,16 @@ def _get_common_parse_arguments(parser):
8283
"gateway: nexthop IP address "
8384
"(repeat option to add multiple routes)")
8485
)
86+
parser.add_argument(
87+
'--service-type',
88+
metavar='<service-type>',
89+
action='append',
90+
dest='service_types',
91+
help=_("Service type for this subnet "
92+
"e.g.: network:floatingip_agent_gateway. "
93+
"Must be a valid device owner value for a network port "
94+
"(repeat option to set multiple service types)")
95+
)
8596

8697

8798
def _get_columns(item):
@@ -177,6 +188,9 @@ def _get_attrs(client_manager, parsed_args, is_create=True):
177188
# Change 'gateway' entry to 'nexthop' to match the API
178189
attrs['host_routes'] = convert_entries_to_nexthop(
179190
parsed_args.host_routes)
191+
if ('service_types' in parsed_args and
192+
parsed_args.service_types is not None):
193+
attrs['service_types'] = parsed_args.service_types
180194
return attrs
181195

182196

@@ -352,6 +366,16 @@ def get_parser(self, prog_name):
352366
action='store_true',
353367
help=_("List subnets which have DHCP disabled")
354368
)
369+
parser.add_argument(
370+
'--service-type',
371+
metavar='<service-type>',
372+
action='append',
373+
dest='service_types',
374+
help=_("List only subnets of a given service type in output "
375+
"e.g.: network:floatingip_agent_gateway. "
376+
"Must be a valid device owner value for a network port "
377+
"(repeat option to list multiple service types)")
378+
)
355379
return parser
356380

357381
def take_action(self, parsed_args):
@@ -362,17 +386,19 @@ def take_action(self, parsed_args):
362386
filters['enable_dhcp'] = True
363387
elif parsed_args.no_dhcp:
364388
filters['enable_dhcp'] = False
389+
if parsed_args.service_types:
390+
filters['service_types'] = parsed_args.service_types
365391
data = self.app.client_manager.network.subnets(**filters)
366392

367393
headers = ('ID', 'Name', 'Network', 'Subnet')
368394
columns = ('id', 'name', 'network_id', 'cidr')
369395
if parsed_args.long:
370396
headers += ('Project', 'DHCP', 'Name Servers',
371397
'Allocation Pools', 'Host Routes', 'IP Version',
372-
'Gateway')
398+
'Gateway', 'Service Types')
373399
columns += ('tenant_id', 'enable_dhcp', 'dns_nameservers',
374400
'allocation_pools', 'host_routes', 'ip_version',
375-
'gateway_ip')
401+
'gateway_ip', 'service_types')
376402

377403
return (headers,
378404
(utils.get_item_properties(
@@ -430,6 +456,8 @@ def take_action(self, parsed_args):
430456
attrs['host_routes'] += obj.host_routes
431457
if 'allocation_pools' in attrs:
432458
attrs['allocation_pools'] += obj.allocation_pools
459+
if 'service_types' in attrs:
460+
attrs['service_types'] += obj.service_types
433461
client.update_subnet(obj, **attrs)
434462
return
435463

@@ -489,6 +517,16 @@ def get_parser(self, prog_name):
489517
'gateway: nexthop IP address '
490518
'(repeat option to unset multiple host routes)')
491519
)
520+
parser.add_argument(
521+
'--service-type',
522+
metavar='<service-type>',
523+
action='append',
524+
dest='service_types',
525+
help=_('Service type to be removed from this subnet '
526+
'e.g.: network:floatingip_agent_gateway. '
527+
'Must be a valid device owner value for a network port '
528+
'(repeat option to unset multiple service types)')
529+
)
492530
parser.add_argument(
493531
'subnet',
494532
metavar="<subnet>",
@@ -528,5 +566,13 @@ def take_action(self, parsed_args):
528566
str(error))
529567
raise exceptions.CommandError(msg)
530568
attrs['allocation_pools'] = tmp_obj.allocation_pools
569+
if parsed_args.service_types:
570+
try:
571+
_update_arguments(tmp_obj.service_types,
572+
parsed_args.service_types)
573+
except ValueError as error:
574+
msg = (_("%s not in service-types") % str(error))
575+
raise exceptions.CommandError(msg)
576+
attrs['service_types'] = tmp_obj.service_types
531577
if attrs:
532578
client.update_subnet(obj, **attrs)

openstackclient/tests/network/v2/fakes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,7 @@ def create_one_subnet(attrs=None):
889889
'ipv6_address_mode': None,
890890
'ipv6_ra_mode': None,
891891
'segment_id': None,
892+
'service_types': [],
892893
'subnetpool_id': None,
893894
}
894895

0 commit comments

Comments
 (0)