summaryrefslogtreecommitdiff
path: root/openstackclient/network
diff options
context:
space:
mode:
authorBrian Haley <brian.haley@hpe.com>2016-07-15 13:20:10 -0400
committerBrian Haley <brian.haley@hpe.com>2016-08-19 11:05:33 -0400
commitcf9ad08ab6fd5e6ed5f68208a39b0014b0af5f8a (patch)
treee3748429db13d716dc8d96f55453c4ead387c8e5 /openstackclient/network
parent34f5515a329d7bdd9b945e256729cd4c97595201 (diff)
downloadpython-openstackclient-cf9ad08ab6fd5e6ed5f68208a39b0014b0af5f8a.tar.gz
Add Subnet service-types to subnets
Add '--service-type' to subnet arguments to support Subnet service-types. Change-Id: I215d83e4d4cf53e03fa35041c5e41a328641b3a9 Partially-implements: blueprint service-subnets
Diffstat (limited to 'openstackclient/network')
-rw-r--r--openstackclient/network/v2/subnet.py50
1 files changed, 48 insertions, 2 deletions
diff --git a/openstackclient/network/v2/subnet.py b/openstackclient/network/v2/subnet.py
index 22452809..6feb8aa0 100644
--- a/openstackclient/network/v2/subnet.py
+++ b/openstackclient/network/v2/subnet.py
@@ -48,6 +48,7 @@ _formatters = {
'allocation_pools': _format_allocation_pools,
'dns_nameservers': utils.format_list,
'host_routes': _format_host_routes,
+ 'service_types': utils.format_list,
}
@@ -82,6 +83,16 @@ def _get_common_parse_arguments(parser):
"gateway: nexthop IP address "
"(repeat option to add multiple routes)")
)
+ parser.add_argument(
+ '--service-type',
+ metavar='<service-type>',
+ action='append',
+ dest='service_types',
+ help=_("Service type for this subnet "
+ "e.g.: network:floatingip_agent_gateway. "
+ "Must be a valid device owner value for a network port "
+ "(repeat option to set multiple service types)")
+ )
def _get_columns(item):
@@ -177,6 +188,9 @@ def _get_attrs(client_manager, parsed_args, is_create=True):
# Change 'gateway' entry to 'nexthop' to match the API
attrs['host_routes'] = convert_entries_to_nexthop(
parsed_args.host_routes)
+ if ('service_types' in parsed_args and
+ parsed_args.service_types is not None):
+ attrs['service_types'] = parsed_args.service_types
return attrs
@@ -352,6 +366,16 @@ class ListSubnet(command.Lister):
action='store_true',
help=_("List subnets which have DHCP disabled")
)
+ parser.add_argument(
+ '--service-type',
+ metavar='<service-type>',
+ action='append',
+ dest='service_types',
+ help=_("List only subnets of a given service type in output "
+ "e.g.: network:floatingip_agent_gateway. "
+ "Must be a valid device owner value for a network port "
+ "(repeat option to list multiple service types)")
+ )
return parser
def take_action(self, parsed_args):
@@ -362,6 +386,8 @@ class ListSubnet(command.Lister):
filters['enable_dhcp'] = True
elif parsed_args.no_dhcp:
filters['enable_dhcp'] = False
+ if parsed_args.service_types:
+ filters['service_types'] = parsed_args.service_types
data = self.app.client_manager.network.subnets(**filters)
headers = ('ID', 'Name', 'Network', 'Subnet')
@@ -369,10 +395,10 @@ class ListSubnet(command.Lister):
if parsed_args.long:
headers += ('Project', 'DHCP', 'Name Servers',
'Allocation Pools', 'Host Routes', 'IP Version',
- 'Gateway')
+ 'Gateway', 'Service Types')
columns += ('tenant_id', 'enable_dhcp', 'dns_nameservers',
'allocation_pools', 'host_routes', 'ip_version',
- 'gateway_ip')
+ 'gateway_ip', 'service_types')
return (headers,
(utils.get_item_properties(
@@ -430,6 +456,8 @@ class SetSubnet(command.Command):
attrs['host_routes'] += obj.host_routes
if 'allocation_pools' in attrs:
attrs['allocation_pools'] += obj.allocation_pools
+ if 'service_types' in attrs:
+ attrs['service_types'] += obj.service_types
client.update_subnet(obj, **attrs)
return
@@ -490,6 +518,16 @@ class UnsetSubnet(command.Command):
'(repeat option to unset multiple host routes)')
)
parser.add_argument(
+ '--service-type',
+ metavar='<service-type>',
+ action='append',
+ dest='service_types',
+ help=_('Service type to be removed from this subnet '
+ 'e.g.: network:floatingip_agent_gateway. '
+ 'Must be a valid device owner value for a network port '
+ '(repeat option to unset multiple service types)')
+ )
+ parser.add_argument(
'subnet',
metavar="<subnet>",
help=_("Subnet to modify (name or ID)")
@@ -528,5 +566,13 @@ class UnsetSubnet(command.Command):
str(error))
raise exceptions.CommandError(msg)
attrs['allocation_pools'] = tmp_obj.allocation_pools
+ if parsed_args.service_types:
+ try:
+ _update_arguments(tmp_obj.service_types,
+ parsed_args.service_types)
+ except ValueError as error:
+ msg = (_("%s not in service-types") % str(error))
+ raise exceptions.CommandError(msg)
+ attrs['service_types'] = tmp_obj.service_types
if attrs:
client.update_subnet(obj, **attrs)