diff options
| author | Huanxuan Ao <huanxuan.ao@easystack.cn> | 2016-06-16 13:09:27 +0800 |
|---|---|---|
| committer | Steve Martinelli <s.martinelli@gmail.com> | 2016-06-16 12:46:32 +0000 |
| commit | 041ea4978b94149d5037b5afc7743db939b75331 (patch) | |
| tree | 4565fc45b7ded8a2033dcad7a160de3802424562 /openstackclient/network/v2 | |
| parent | 114eeeb0236d29a325abbf13b41a9a385746b367 (diff) | |
| download | python-openstackclient-041ea4978b94149d5037b5afc7743db939b75331.tar.gz | |
Support bulk deletion for delete commands in networkv2
This patch support bulk deletion for delete commands below:
1.subnet delete
2.subnet pool delete
Up to now, all the delete commands in networkv2 support bulk deletion.
Change-Id: I63f6d1d02bad1fcc26e72b7028b53958a68ce2dc
Partially-Implements: blueprint multi-argument-network
Partial-Bug: #1592906
Diffstat (limited to 'openstackclient/network/v2')
| -rw-r--r-- | openstackclient/network/v2/subnet.py | 28 | ||||
| -rw-r--r-- | openstackclient/network/v2/subnet_pool.py | 30 |
2 files changed, 50 insertions, 8 deletions
diff --git a/openstackclient/network/v2/subnet.py b/openstackclient/network/v2/subnet.py index ceb1cb14..a2e32622 100644 --- a/openstackclient/network/v2/subnet.py +++ b/openstackclient/network/v2/subnet.py @@ -14,6 +14,7 @@ """Subnet action implementations""" import copy +import logging from osc_lib.cli import parseractions from osc_lib.command import command @@ -24,6 +25,9 @@ from openstackclient.i18n import _ from openstackclient.identity import common as identity_common +LOG = logging.getLogger(__name__) + + def _format_allocation_pools(data): pool_formatted = ['%s-%s' % (pool.get('start', ''), pool.get('end', '')) for pool in data] @@ -270,21 +274,37 @@ class CreateSubnet(command.ShowOne): class DeleteSubnet(command.Command): - """Delete subnet""" + """Delete subnet(s)""" def get_parser(self, prog_name): parser = super(DeleteSubnet, self).get_parser(prog_name) parser.add_argument( 'subnet', metavar="<subnet>", - help=_("Subnet to delete (name or ID)") + nargs='+', + help=_("Subnet(s) to delete (name or ID)") ) return parser def take_action(self, parsed_args): client = self.app.client_manager.network - client.delete_subnet( - client.find_subnet(parsed_args.subnet)) + result = 0 + + for subnet in parsed_args.subnet: + try: + obj = client.find_subnet(subnet, ignore_missing=False) + client.delete_subnet(obj) + except Exception as e: + result += 1 + LOG.error(_("Failed to delete subnet with " + "name or ID '%(subnet)s': %(e)s") + % {'subnet': subnet, 'e': e}) + + if result > 0: + total = len(parsed_args.subnet) + msg = (_("%(result)s of %(total)s subnets failed " + "to delete.") % {'result': result, 'total': total}) + raise exceptions.CommandError(msg) class ListSubnet(command.Lister): diff --git a/openstackclient/network/v2/subnet_pool.py b/openstackclient/network/v2/subnet_pool.py index 79f98fd9..55dfed83 100644 --- a/openstackclient/network/v2/subnet_pool.py +++ b/openstackclient/network/v2/subnet_pool.py @@ -13,14 +13,20 @@ """Subnet pool action implementations""" +import logging + from osc_lib.cli import parseractions from osc_lib.command import command +from osc_lib import exceptions from osc_lib import utils from openstackclient.i18n import _ from openstackclient.identity import common as identity_common +LOG = logging.getLogger(__name__) + + def _get_columns(item): columns = list(item.keys()) if 'tenant_id' in columns: @@ -176,21 +182,37 @@ class CreateSubnetPool(command.ShowOne): class DeleteSubnetPool(command.Command): - """Delete subnet pool""" + """Delete subnet pool(s)""" def get_parser(self, prog_name): parser = super(DeleteSubnetPool, self).get_parser(prog_name) parser.add_argument( 'subnet_pool', metavar='<subnet-pool>', - help=_("Subnet pool to delete (name or ID)") + nargs='+', + help=_("Subnet pool(s) to delete (name or ID)") ) return parser def take_action(self, parsed_args): client = self.app.client_manager.network - obj = client.find_subnet_pool(parsed_args.subnet_pool) - client.delete_subnet_pool(obj) + result = 0 + + for pool in parsed_args.subnet_pool: + try: + obj = client.find_subnet_pool(pool, ignore_missing=False) + client.delete_subnet_pool(obj) + except Exception as e: + result += 1 + LOG.error(_("Failed to delete subnet pool with " + "name or ID '%(pool)s': %(e)s") + % {'pool': pool, 'e': e}) + + if result > 0: + total = len(parsed_args.subnet_pool) + msg = (_("%(result)s of %(total)s subnet pools failed " + "to delete.") % {'result': result, 'total': total}) + raise exceptions.CommandError(msg) class ListSubnetPool(command.Lister): |
