summaryrefslogtreecommitdiff
path: root/openstackclient/compute/v2/aggregate.py
diff options
context:
space:
mode:
authorHuanxuan Ao <huanxuan.ao@easystack.cn>2016-06-20 15:42:40 +0800
committerHuanxuan Ao <huanxuan.ao@easystack.cn>2016-06-21 11:04:13 +0800
commit640014fa91b939e802f261346473d3ec025f2acb (patch)
tree98af9ac80e7458d29772dd4e892bbf31485015c8 /openstackclient/compute/v2/aggregate.py
parentba825a4d5c04e2e6fd8a82ebbfb2f71a85e683aa (diff)
downloadpython-openstackclient-640014fa91b939e802f261346473d3ec025f2acb.tar.gz
Support bulk deletion for "flavor/aggregate delete"
Support bulk deletion and error handling for "aggregate delete" and "flavor delete" commands. Change-Id: I3f6105cbeeab1c9f8cd571c63ce0e7ac3d4252b3 Partially-Implements: blueprint multi-argument-compute Partial-Bug: #1592906
Diffstat (limited to 'openstackclient/compute/v2/aggregate.py')
-rw-r--r--openstackclient/compute/v2/aggregate.py34
1 files changed, 26 insertions, 8 deletions
diff --git a/openstackclient/compute/v2/aggregate.py b/openstackclient/compute/v2/aggregate.py
index 8000c93a..2e2838c5 100644
--- a/openstackclient/compute/v2/aggregate.py
+++ b/openstackclient/compute/v2/aggregate.py
@@ -16,14 +16,20 @@
"""Compute v2 Aggregate 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
import six
from openstackclient.i18n import _
+LOG = logging.getLogger(__name__)
+
+
class AddAggregateHost(command.ShowOne):
"""Add host to aggregate"""
@@ -99,25 +105,37 @@ class CreateAggregate(command.ShowOne):
class DeleteAggregate(command.Command):
- """Delete an existing aggregate"""
+ """Delete existing aggregate(s)"""
def get_parser(self, prog_name):
parser = super(DeleteAggregate, self).get_parser(prog_name)
parser.add_argument(
'aggregate',
metavar='<aggregate>',
- help=_("Aggregate to delete (name or ID)")
+ nargs='+',
+ help=_("Aggregate(s) to delete (name or ID)")
)
return parser
def take_action(self, parsed_args):
-
compute_client = self.app.client_manager.compute
- data = utils.find_resource(
- compute_client.aggregates,
- parsed_args.aggregate,
- )
- compute_client.aggregates.delete(data.id)
+ result = 0
+ for a in parsed_args.aggregate:
+ try:
+ data = utils.find_resource(
+ compute_client.aggregates, a)
+ compute_client.aggregates.delete(data.id)
+ except Exception as e:
+ result += 1
+ LOG.error(_("Failed to delete aggregate with name or "
+ "ID '%(aggregate)s': %(e)s")
+ % {'aggregate': a, 'e': e})
+
+ if result > 0:
+ total = len(parsed_args.aggregate)
+ msg = (_("%(result)s of %(total)s aggregates failed "
+ "to delete.") % {'result': result, 'total': total})
+ raise exceptions.CommandError(msg)
class ListAggregate(command.Lister):