summaryrefslogtreecommitdiff
path: root/openstackclient/network
diff options
context:
space:
mode:
Diffstat (limited to 'openstackclient/network')
-rw-r--r--openstackclient/network/v2/subnet.py28
-rw-r--r--openstackclient/network/v2/subnet_pool.py30
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):