From 909bab1e07ec564055dd7dab578af9970a8e648e Mon Sep 17 00:00:00 2001 From: sunyajing Date: Wed, 1 Jun 2016 16:43:57 +0800 Subject: Support multiple argument for compute agent delete command Change-Id: I3b19e4914d475b86d7e8aa8d76e62a2ac811272f Partially-Implements: blueprint multi-argument-compute --- openstackclient/compute/v2/agent.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'openstackclient/compute') diff --git a/openstackclient/compute/v2/agent.py b/openstackclient/compute/v2/agent.py index e358399d..064fe5a6 100644 --- a/openstackclient/compute/v2/agent.py +++ b/openstackclient/compute/v2/agent.py @@ -18,6 +18,7 @@ import six from openstackclient.common import command +from openstackclient.common import exceptions from openstackclient.common import utils from openstackclient.i18n import _ @@ -75,20 +76,35 @@ class CreateAgent(command.ShowOne): class DeleteAgent(command.Command): - """Delete compute agent command""" + """Delete compute agent(s)""" def get_parser(self, prog_name): parser = super(DeleteAgent, self).get_parser(prog_name) parser.add_argument( "id", metavar="", - help=_("ID of agent to delete") + nargs='+', + help=_("ID of agent(s) to delete") ) return parser def take_action(self, parsed_args): compute_client = self.app.client_manager.compute - compute_client.agents.delete(parsed_args.id) + result = 0 + for id in parsed_args.id: + try: + compute_client.agents.delete(id) + except Exception as e: + result += 1 + self.app.log.error(_("Failed to delete agent with " + "ID '%(id)s': %(e)s") + % {'id': id, 'e': e}) + + if result > 0: + total = len(parsed_args.id) + msg = (_("%(result)s of %(total)s agents failed " + "to delete.") % {'result': result, 'total': total}) + raise exceptions.CommandError(msg) class ListAgent(command.Lister): -- cgit v1.2.1