summaryrefslogtreecommitdiff
path: root/openstackclient/network
diff options
context:
space:
mode:
Diffstat (limited to 'openstackclient/network')
-rw-r--r--openstackclient/network/v2/network.py97
-rw-r--r--openstackclient/network/v2/network_segment.py161
-rw-r--r--openstackclient/network/v2/port.py29
-rw-r--r--openstackclient/network/v2/router.py19
-rw-r--r--openstackclient/network/v2/subnet.py150
-rw-r--r--openstackclient/network/v2/subnet_pool.py116
6 files changed, 484 insertions, 88 deletions
diff --git a/openstackclient/network/v2/network.py b/openstackclient/network/v2/network.py
index ccc02fd8..dbf1b601 100644
--- a/openstackclient/network/v2/network.py
+++ b/openstackclient/network/v2/network.py
@@ -78,6 +78,10 @@ def _get_attrs(client_manager, parsed_args):
parsed_args.availability_zone_hints is not None:
attrs['availability_zone_hints'] = parsed_args.availability_zone_hints
+ # set description
+ if parsed_args.description:
+ attrs['description'] = parsed_args.description
+
# update_external_network_options
if parsed_args.internal:
attrs['router:external'] = False
@@ -191,6 +195,11 @@ class CreateNetwork(common.NetworkAndComputeShowOne):
metavar='<project>',
help=_("Owner's project (name or ID)")
)
+ parser.add_argument(
+ '--description',
+ metavar='<description>',
+ help=_("Set network description")
+ )
identity_common.add_project_domain_option_to_parser(parser)
parser.add_argument(
'--availability-zone-hint',
@@ -295,21 +304,66 @@ class ListNetwork(common.NetworkAndComputeLister):
"""List networks"""
def update_parser_common(self, parser):
- parser.add_argument(
+ router_ext_group = parser.add_mutually_exclusive_group()
+ router_ext_group.add_argument(
'--external',
action='store_true',
- default=False,
help=_("List external networks")
)
+ router_ext_group.add_argument(
+ '--internal',
+ action='store_true',
+ help=_("List internal networks")
+ )
parser.add_argument(
'--long',
action='store_true',
- default=False,
help=_("List additional fields in output")
)
+ parser.add_argument(
+ '--name',
+ metavar='<name>',
+ help=_("List networks according to their name")
+ )
+ admin_state_group = parser.add_mutually_exclusive_group()
+ admin_state_group.add_argument(
+ '--enable',
+ action='store_true',
+ help=_("List enabled networks")
+ )
+ admin_state_group.add_argument(
+ '--disable',
+ action='store_true',
+ help=_("List disabled networks")
+ )
+ parser.add_argument(
+ '--project',
+ metavar='<project>',
+ help=_("List networks according to their project (name or ID)")
+ )
+ identity_common.add_project_domain_option_to_parser(parser)
+ shared_group = parser.add_mutually_exclusive_group()
+ shared_group.add_argument(
+ '--share',
+ action='store_true',
+ help=_("List networks shared between projects")
+ )
+ shared_group.add_argument(
+ '--no-share',
+ action='store_true',
+ help=_("List networks not shared between projects")
+ )
+ parser.add_argument(
+ '--status',
+ metavar='<status>',
+ choices=['ACTIVE', 'BUILD', 'DOWN', 'ERROR'],
+ help=_("List networks according to their status "
+ "('ACTIVE', 'BUILD', 'DOWN', 'ERROR')")
+ )
return parser
def take_action_network(self, client, parsed_args):
+ identity_client = self.app.client_manager.identity
if parsed_args.long:
columns = (
'id',
@@ -347,10 +401,36 @@ class ListNetwork(common.NetworkAndComputeLister):
'Subnets',
)
+ args = {}
+
if parsed_args.external:
- args = {'router:external': True}
- else:
- args = {}
+ args['router:external'] = True
+ elif parsed_args.internal:
+ args['router:external'] = False
+
+ if parsed_args.name is not None:
+ args['name'] = parsed_args.name
+
+ if parsed_args.enable:
+ args['admin_state_up'] = True
+ elif parsed_args.disable:
+ args['admin_state_up'] = False
+
+ if parsed_args.project:
+ project = identity_common.find_project(
+ identity_client,
+ parsed_args.project,
+ parsed_args.project_domain,
+ )
+ args['tenant_id'] = project.id
+
+ if parsed_args.share:
+ args['shared'] = True
+ elif parsed_args.no_share:
+ args['shared'] = False
+
+ if parsed_args.status:
+ args['status'] = parsed_args.status
data = client.networks(**args)
@@ -420,6 +500,11 @@ class SetNetwork(command.Command):
action='store_true',
help=_("Do not share the network between projects")
)
+ parser.add_argument(
+ '--description',
+ metavar="<description",
+ help=_("Set network description")
+ )
port_security_group = parser.add_mutually_exclusive_group()
port_security_group.add_argument(
'--enable-port-security',
diff --git a/openstackclient/network/v2/network_segment.py b/openstackclient/network/v2/network_segment.py
index bedf15f7..34cac0e0 100644
--- a/openstackclient/network/v2/network_segment.py
+++ b/openstackclient/network/v2/network_segment.py
@@ -13,14 +13,129 @@
"""Network segment action implementations"""
-# TODO(rtheis): Add description and name properties when support is available.
+import logging
from osc_lib.command import command
+from osc_lib import exceptions
from osc_lib import utils
from openstackclient.i18n import _
+LOG = logging.getLogger(__name__)
+
+
+class CreateNetworkSegment(command.ShowOne):
+ """Create new network segment
+
+ (Caution: This is a beta command and subject to change.
+ Use global option --os-beta-command to enable
+ this command)
+ """
+
+ def get_parser(self, prog_name):
+ parser = super(CreateNetworkSegment, self).get_parser(prog_name)
+ parser.add_argument(
+ 'name',
+ metavar='<name>',
+ help=_('New network segment name')
+ )
+ parser.add_argument(
+ '--description',
+ metavar='<description>',
+ help=_('Network segment description'),
+ )
+ parser.add_argument(
+ '--physical-network',
+ metavar='<physical-network>',
+ help=_('Physical network name of this network segment'),
+ )
+ parser.add_argument(
+ '--segment',
+ metavar='<segment>',
+ type=int,
+ help=_('Segment identifier for this network segment which is '
+ 'based on the network type, VLAN ID for vlan network '
+ 'type and tunnel ID for geneve, gre and vxlan network '
+ 'types'),
+ )
+ parser.add_argument(
+ '--network',
+ metavar='<network>',
+ required=True,
+ help=_('Network this network segment belongs to (name or ID)'),
+ )
+ parser.add_argument(
+ '--network-type',
+ metavar='<network-type>',
+ choices=['flat', 'geneve', 'gre', 'local', 'vlan', 'vxlan'],
+ required=True,
+ help=_('Network type of this network segment '
+ '(flat, geneve, gre, local, vlan or vxlan)'),
+ )
+ return parser
+
+ def take_action(self, parsed_args):
+ self.validate_os_beta_command_enabled()
+ client = self.app.client_manager.network
+ attrs = {}
+ attrs['name'] = parsed_args.name
+ attrs['network_id'] = client.find_network(parsed_args.network,
+ ignore_missing=False).id
+ attrs['network_type'] = parsed_args.network_type
+ if parsed_args.description is not None:
+ attrs['description'] = parsed_args.description
+ if parsed_args.physical_network is not None:
+ attrs['physical_network'] = parsed_args.physical_network
+ if parsed_args.segment is not None:
+ attrs['segmentation_id'] = parsed_args.segment
+ obj = client.create_segment(**attrs)
+ columns = tuple(sorted(obj.keys()))
+ data = utils.get_item_properties(obj, columns)
+ return (columns, data)
+
+
+class DeleteNetworkSegment(command.Command):
+ """Delete network segment(s)
+
+ (Caution: This is a beta command and subject to change.
+ Use global option --os-beta-command to enable
+ this command)
+ """
+
+ def get_parser(self, prog_name):
+ parser = super(DeleteNetworkSegment, self).get_parser(prog_name)
+ parser.add_argument(
+ 'network_segment',
+ metavar='<network-segment>',
+ nargs='+',
+ help=_('Network segment(s) to delete (name or ID)'),
+ )
+ return parser
+
+ def take_action(self, parsed_args):
+ self.validate_os_beta_command_enabled()
+ client = self.app.client_manager.network
+
+ result = 0
+ for network_segment in parsed_args.network_segment:
+ try:
+ obj = client.find_segment(network_segment,
+ ignore_missing=False)
+ client.delete_segment(obj)
+ except Exception as e:
+ result += 1
+ LOG.error(_("Failed to delete network segment with "
+ "ID '%(network_segment)s': %(e)s")
+ % {'network_segment': network_segment, 'e': e})
+
+ if result > 0:
+ total = len(parsed_args.network_segment)
+ msg = (_("%(result)s of %(total)s network segments failed "
+ "to delete.") % {'result': result, 'total': total})
+ raise exceptions.CommandError(msg)
+
+
class ListNetworkSegment(command.Lister):
"""List network segments
@@ -61,12 +176,14 @@ class ListNetworkSegment(command.Lister):
headers = (
'ID',
+ 'Name',
'Network',
'Network Type',
'Segment',
)
columns = (
'id',
+ 'name',
'network_id',
'network_type',
'segmentation_id',
@@ -86,6 +203,46 @@ class ListNetworkSegment(command.Lister):
) for s in data))
+class SetNetworkSegment(command.Command):
+ """Set network segment properties
+
+ (Caution: This is a beta command and subject to change.
+ Use global option --os-beta-command to enable
+ this command)
+ """
+
+ def get_parser(self, prog_name):
+ parser = super(SetNetworkSegment, self).get_parser(prog_name)
+ parser.add_argument(
+ 'network_segment',
+ metavar='<network-segment>',
+ help=_('Network segment to modify (name or ID)'),
+ )
+ parser.add_argument(
+ '--description',
+ metavar='<description>',
+ help=_('Set network segment description'),
+ )
+ parser.add_argument(
+ '--name',
+ metavar='<name>',
+ help=_('Set network segment name'),
+ )
+ return parser
+
+ def take_action(self, parsed_args):
+ self.validate_os_beta_command_enabled()
+ client = self.app.client_manager.network
+ obj = client.find_segment(parsed_args.network_segment,
+ ignore_missing=False)
+ attrs = {}
+ if parsed_args.description is not None:
+ attrs['description'] = parsed_args.description
+ if parsed_args.name is not None:
+ attrs['name'] = parsed_args.name
+ client.update_segment(obj, **attrs)
+
+
class ShowNetworkSegment(command.ShowOne):
"""Display network segment details
@@ -99,7 +256,7 @@ class ShowNetworkSegment(command.ShowOne):
parser.add_argument(
'network_segment',
metavar='<network-segment>',
- help=_('Network segment to display (ID only)'),
+ help=_('Network segment to display (name or ID)'),
)
return parser
diff --git a/openstackclient/network/v2/port.py b/openstackclient/network/v2/port.py
index b3634eb7..92b286a9 100644
--- a/openstackclient/network/v2/port.py
+++ b/openstackclient/network/v2/port.py
@@ -345,15 +345,26 @@ class ListPort(command.Lister):
"network:dhcp).")
)
parser.add_argument(
+ '--network',
+ metavar='<network>',
+ help=_("List only ports connected to this network (name or ID)"))
+ device_group = parser.add_mutually_exclusive_group()
+ device_group.add_argument(
'--router',
metavar='<router>',
dest='router',
help=_("List only ports attached to this router (name or ID)")
)
+ device_group.add_argument(
+ '--server',
+ metavar='<server>',
+ help=_("List only ports attached to this server (name or ID)"),
+ )
return parser
def take_action(self, parsed_args):
- client = self.app.client_manager.network
+ network_client = self.app.client_manager.network
+ compute_client = self.app.client_manager.compute
columns = (
'id',
@@ -372,11 +383,19 @@ class ListPort(command.Lister):
if parsed_args.device_owner is not None:
filters['device_owner'] = parsed_args.device_owner
if parsed_args.router:
- _router = client.find_router(parsed_args.router,
- ignore_missing=False)
+ _router = network_client.find_router(parsed_args.router,
+ ignore_missing=False)
filters['device_id'] = _router.id
-
- data = client.ports(**filters)
+ if parsed_args.server:
+ server = utils.find_resource(compute_client.servers,
+ parsed_args.server)
+ filters['device_id'] = server.id
+ if parsed_args.network:
+ network = network_client.find_network(parsed_args.network,
+ ignore_missing=False)
+ filters['network_id'] = network.id
+
+ data = network_client.ports(**filters)
return (column_headers,
(utils.get_item_properties(
diff --git a/openstackclient/network/v2/router.py b/openstackclient/network/v2/router.py
index f6d96d03..03134b8c 100644
--- a/openstackclient/network/v2/router.py
+++ b/openstackclient/network/v2/router.py
@@ -119,7 +119,7 @@ class AddPortToRouter(command.Command):
def take_action(self, parsed_args):
client = self.app.client_manager.network
port = client.find_port(parsed_args.port, ignore_missing=False)
- client.router_add_interface(client.find_router(
+ client.add_interface_to_router(client.find_router(
parsed_args.router, ignore_missing=False), port_id=port.id)
@@ -144,7 +144,7 @@ class AddSubnetToRouter(command.Command):
client = self.app.client_manager.network
subnet = client.find_subnet(parsed_args.subnet,
ignore_missing=False)
- client.router_add_interface(
+ client.add_interface_to_router(
client.find_router(parsed_args.router,
ignore_missing=False),
subnet_id=subnet.id)
@@ -281,13 +281,20 @@ class ListRouter(command.Lister):
columns = columns + (
'routes',
'external_gateway_info',
- 'availability_zones'
)
column_headers = column_headers + (
'Routes',
'External gateway info',
- 'Availability zones'
)
+ # availability zone will be available only when
+ # router_availability_zone extension is enabled
+ if client.find_extension("router_availability_zone"):
+ columns = columns + (
+ 'availability_zones',
+ )
+ column_headers = column_headers + (
+ 'Availability zones',
+ )
data = client.routers()
return (column_headers,
@@ -317,7 +324,7 @@ class RemovePortFromRouter(command.Command):
def take_action(self, parsed_args):
client = self.app.client_manager.network
port = client.find_port(parsed_args.port, ignore_missing=False)
- client.router_remove_interface(client.find_router(
+ client.remove_interface_from_router(client.find_router(
parsed_args.router, ignore_missing=False), port_id=port.id)
@@ -342,7 +349,7 @@ class RemoveSubnetFromRouter(command.Command):
client = self.app.client_manager.network
subnet = client.find_subnet(parsed_args.subnet,
ignore_missing=False)
- client.router_remove_interface(
+ client.remove_interface_from_router(
client.find_router(parsed_args.router,
ignore_missing=False),
subnet_id=subnet.id)
diff --git a/openstackclient/network/v2/subnet.py b/openstackclient/network/v2/subnet.py
index 6feb8aa0..2021d9f0 100644
--- a/openstackclient/network/v2/subnet.py
+++ b/openstackclient/network/v2/subnet.py
@@ -28,9 +28,14 @@ from openstackclient.identity import common as identity_common
LOG = logging.getLogger(__name__)
-def _update_arguments(obj_list, parsed_args_list):
+def _update_arguments(obj_list, parsed_args_list, option):
for item in parsed_args_list:
- obj_list.remove(item)
+ try:
+ obj_list.remove(item)
+ except ValueError:
+ msg = (_("Subnet does not contain %(option)s %(value)s") %
+ {'option': option, 'value': item})
+ raise exceptions.CommandError(msg)
def _format_allocation_pools(data):
@@ -52,7 +57,7 @@ _formatters = {
}
-def _get_common_parse_arguments(parser):
+def _get_common_parse_arguments(parser, is_create=True):
parser.add_argument(
'--allocation-pool',
metavar='start=<ip-address>,end=<ip-address>',
@@ -63,6 +68,14 @@ def _get_common_parse_arguments(parser):
"e.g.: start=192.168.199.2,end=192.168.199.254 "
"(repeat option to add multiple IP addresses)")
)
+ if not is_create:
+ parser.add_argument(
+ '--no-allocation-pool',
+ action='store_true',
+ help=_("Clear associated allocation-pools from the subnet. "
+ "Specify both --allocation-pool and --no-allocation-pool "
+ "to overwrite the current allocation pool information.")
+ )
parser.add_argument(
'--dns-nameserver',
metavar='<dns-nameserver>',
@@ -83,6 +96,14 @@ def _get_common_parse_arguments(parser):
"gateway: nexthop IP address "
"(repeat option to add multiple routes)")
)
+ if not is_create:
+ parser.add_argument(
+ '--no-host-route',
+ action='store_true',
+ help=_("Clear associated host-routes from the subnet. "
+ "Specify both --host-route and --no-host-route "
+ "to overwrite the current host route information.")
+ )
parser.add_argument(
'--service-type',
metavar='<service-type>',
@@ -191,6 +212,8 @@ def _get_attrs(client_manager, parsed_args, is_create=True):
if ('service_types' in parsed_args and
parsed_args.service_types is not None):
attrs['service_types'] = parsed_args.service_types
+ if parsed_args.description is not None:
+ attrs['description'] = parsed_args.description
return attrs
@@ -289,6 +312,11 @@ class CreateSubnet(command.ShowOne):
metavar='<network>',
help=_("Network this subnet belongs to (name or ID)")
)
+ parser.add_argument(
+ '--description',
+ metavar='<description>',
+ help=_("Set subnet description")
+ )
_get_common_parse_arguments(parser)
return parser
@@ -376,9 +404,41 @@ class ListSubnet(command.Lister):
"Must be a valid device owner value for a network port "
"(repeat option to list multiple service types)")
)
+ parser.add_argument(
+ '--project',
+ metavar='<project>',
+ help=_("List only subnets which belong to a given project "
+ "(name or ID) in output")
+ )
+ identity_common.add_project_domain_option_to_parser(parser)
+ parser.add_argument(
+ '--network',
+ metavar='<network>',
+ help=_("List only subnets which belong to a given network "
+ "(name or ID) in output")
+ )
+ parser.add_argument(
+ '--gateway',
+ metavar='<gateway>',
+ help=_("List only subnets of given gateway IP in output")
+ )
+ parser.add_argument(
+ '--name',
+ metavar='<name>',
+ help=_("List only subnets of given name in output")
+ )
+ parser.add_argument(
+ '--subnet-range',
+ metavar='<subnet-range>',
+ help=_("List only subnets of given subnet range "
+ "(in CIDR notation) in output "
+ "e.g.: --subnet-range 10.10.0.0/16")
+ )
return parser
def take_action(self, parsed_args):
+ identity_client = self.app.client_manager.identity
+ network_client = self.app.client_manager.network
filters = {}
if parsed_args.ip_version:
filters['ip_version'] = parsed_args.ip_version
@@ -388,7 +448,24 @@ class ListSubnet(command.Lister):
filters['enable_dhcp'] = False
if parsed_args.service_types:
filters['service_types'] = parsed_args.service_types
- data = self.app.client_manager.network.subnets(**filters)
+ if parsed_args.project:
+ project_id = identity_common.find_project(
+ identity_client,
+ parsed_args.project,
+ parsed_args.project_domain,
+ ).id
+ filters['tenant_id'] = project_id
+ if parsed_args.network:
+ network_id = network_client.find_network(parsed_args.network,
+ ignore_missing=False).id
+ filters['network_id'] = network_id
+ if parsed_args.gateway:
+ filters['gateway_ip'] = parsed_args.gateway
+ if parsed_args.name:
+ filters['name'] = parsed_args.name
+ if parsed_args.subnet_range:
+ filters['cidr'] = parsed_args.subnet_range
+ data = network_client.subnets(**filters)
headers = ('ID', 'Name', 'Network', 'Subnet')
columns = ('id', 'name', 'network_id', 'cidr')
@@ -442,7 +519,12 @@ class SetSubnet(command.Command):
"'none': This subnet will not use a gateway, "
"e.g.: --gateway 192.168.9.1, --gateway none.")
)
- _get_common_parse_arguments(parser)
+ parser.add_argument(
+ '--description',
+ metavar='<description>',
+ help=_("Set subnet description")
+ )
+ _get_common_parse_arguments(parser, is_create=False)
return parser
def take_action(self, parsed_args):
@@ -453,9 +535,15 @@ class SetSubnet(command.Command):
if 'dns_nameservers' in attrs:
attrs['dns_nameservers'] += obj.dns_nameservers
if 'host_routes' in attrs:
- attrs['host_routes'] += obj.host_routes
+ if not parsed_args.no_host_route:
+ attrs['host_routes'] += obj.host_routes
+ elif parsed_args.no_host_route:
+ attrs['host_routes'] = ''
if 'allocation_pools' in attrs:
- attrs['allocation_pools'] += obj.allocation_pools
+ if not parsed_args.no_allocation_pool:
+ attrs['allocation_pools'] += obj.allocation_pools
+ elif parsed_args.no_allocation_pool:
+ attrs['allocation_pools'] = ''
if 'service_types' in attrs:
attrs['service_types'] += obj.service_types
client.update_subnet(obj, **attrs)
@@ -493,9 +581,9 @@ class UnsetSubnet(command.Command):
dest='allocation_pools',
action=parseractions.MultiKeyValueAction,
required_keys=['start', 'end'],
- help=_('Allocation pool to be removed from this subnet '
- 'e.g.: start=192.168.199.2,end=192.168.199.254 '
- '(repeat option to unset multiple Allocation pools)')
+ help=_('Allocation pool IP addresses to be removed from this '
+ 'subnet e.g.: start=192.168.199.2,end=192.168.199.254 '
+ '(repeat option to unset multiple allocation pools)')
)
parser.add_argument(
'--dns-nameserver',
@@ -503,7 +591,7 @@ class UnsetSubnet(command.Command):
action='append',
dest='dns_nameservers',
help=_('DNS server to be removed from this subnet '
- '(repeat option to set multiple DNS servers)')
+ '(repeat option to unset multiple DNS servers)')
)
parser.add_argument(
'--host-route',
@@ -540,39 +628,25 @@ class UnsetSubnet(command.Command):
tmp_obj = copy.deepcopy(obj)
attrs = {}
if parsed_args.dns_nameservers:
- try:
- _update_arguments(tmp_obj.dns_nameservers,
- parsed_args.dns_nameservers)
- except ValueError as error:
- msg = (_("%s not in dns-nameservers") % str(error))
- raise exceptions.CommandError(msg)
+ _update_arguments(tmp_obj.dns_nameservers,
+ parsed_args.dns_nameservers,
+ 'dns-nameserver')
attrs['dns_nameservers'] = tmp_obj.dns_nameservers
if parsed_args.host_routes:
- try:
- _update_arguments(
- tmp_obj.host_routes,
- convert_entries_to_nexthop(parsed_args.host_routes))
- except ValueError as error:
- msg = (_("Subnet does not have %s in host-routes") %
- str(error))
- raise exceptions.CommandError(msg)
+ _update_arguments(
+ tmp_obj.host_routes,
+ convert_entries_to_nexthop(parsed_args.host_routes),
+ 'host-route')
attrs['host_routes'] = tmp_obj.host_routes
if parsed_args.allocation_pools:
- try:
- _update_arguments(tmp_obj.allocation_pools,
- parsed_args.allocation_pools)
- except ValueError as error:
- msg = (_("Subnet does not have %s in allocation-pools") %
- str(error))
- raise exceptions.CommandError(msg)
+ _update_arguments(tmp_obj.allocation_pools,
+ parsed_args.allocation_pools,
+ 'allocation-pool')
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)
+ _update_arguments(tmp_obj.service_types,
+ parsed_args.service_types,
+ 'service-type')
attrs['service_types'] = tmp_obj.service_types
if attrs:
client.update_subnet(obj, **attrs)
diff --git a/openstackclient/network/v2/subnet_pool.py b/openstackclient/network/v2/subnet_pool.py
index d3fab8ac..a01d2f7b 100644
--- a/openstackclient/network/v2/subnet_pool.py
+++ b/openstackclient/network/v2/subnet_pool.py
@@ -81,6 +81,9 @@ def _get_attrs(client_manager, parsed_args):
).id
attrs['tenant_id'] = project_id
+ if parsed_args.description is not None:
+ attrs['description'] = parsed_args.description
+
return attrs
@@ -167,6 +170,11 @@ class CreateSubnetPool(command.ShowOne):
action='store_true',
help=_("Set this subnet pool as not shared"),
)
+ parser.add_argument(
+ '--description',
+ metavar='<description>',
+ help=_("Set subnet pool description")
+ )
return parser
def take_action(self, parsed_args):
@@ -226,41 +234,82 @@ class ListSubnetPool(command.Lister):
default=False,
help=_("List additional fields in output")
)
+ shared_group = parser.add_mutually_exclusive_group()
+ shared_group.add_argument(
+ '--share',
+ action='store_true',
+ help=_("List subnets shared between projects"),
+ )
+ shared_group.add_argument(
+ '--no-share',
+ action='store_true',
+ help=_("List subnets not shared between projects"),
+ )
+ default_group = parser.add_mutually_exclusive_group()
+ default_group.add_argument(
+ '--default',
+ action='store_true',
+ help=_("List subnets used as the default external subnet pool"),
+ )
+ default_group.add_argument(
+ '--no-default',
+ action='store_true',
+ help=_("List subnets not used as the default external subnet pool")
+ )
+ parser.add_argument(
+ '--project',
+ metavar='<project>',
+ help=_("List subnets according to their project (name or ID)")
+ )
+ identity_common.add_project_domain_option_to_parser(parser)
+ parser.add_argument(
+ '--name',
+ metavar='<name>',
+ help=_("List only subnets of given name in output")
+ )
+ parser.add_argument(
+ '--address-scope',
+ metavar='<address-scope>',
+ help=_("List only subnets of given address scope (name or ID) "
+ "in output")
+ )
return parser
def take_action(self, parsed_args):
- data = self.app.client_manager.network.subnet_pools()
-
+ identity_client = self.app.client_manager.identity
+ network_client = self.app.client_manager.network
+ filters = {}
+ if parsed_args.share:
+ filters['shared'] = True
+ elif parsed_args.no_share:
+ filters['shared'] = False
+ if parsed_args.default:
+ filters['is_default'] = True
+ elif parsed_args.no_default:
+ filters['is_default'] = False
+ if parsed_args.project:
+ project_id = identity_common.find_project(
+ identity_client,
+ parsed_args.project,
+ parsed_args.project_domain,
+ ).id
+ filters['tenant_id'] = project_id
+ if parsed_args.name is not None:
+ filters['name'] = parsed_args.name
+ if parsed_args.address_scope:
+ address_scope = network_client.find_address_scope(
+ parsed_args.address_scope,
+ ignore_missing=False)
+ filters['address_scope_id'] = address_scope.id
+ data = network_client.subnet_pools(**filters)
+
+ headers = ('ID', 'Name', 'Prefixes')
+ columns = ('id', 'name', 'prefixes')
if parsed_args.long:
- headers = (
- 'ID',
- 'Name',
- 'Prefixes',
- 'Default Prefix Length',
- 'Address Scope',
- 'Default Subnet Pool',
- 'Shared',
- )
- columns = (
- 'id',
- 'name',
- 'prefixes',
- 'default_prefixlen',
- 'address_scope_id',
- 'is_default',
- 'shared',
- )
- else:
- headers = (
- 'ID',
- 'Name',
- 'Prefixes',
- )
- columns = (
- 'id',
- 'name',
- 'prefixes',
- )
+ headers += ('Default Prefix Length', 'Address Scope',
+ 'Default Subnet Pool', 'Shared')
+ columns += ('default_prefixlen', 'address_scope_id',
+ 'is_default', 'shared')
return (headers,
(utils.get_item_properties(
@@ -299,6 +348,11 @@ class SetSubnetPool(command.Command):
help=_("Remove address scope associated with the subnet pool")
)
_add_default_options(parser)
+ parser.add_argument(
+ '--description',
+ metavar='<description>',
+ help=_("Set subnet pool description")
+ )
return parser