summaryrefslogtreecommitdiff
path: root/openstackclient/compute/v2/agent.py
diff options
context:
space:
mode:
authorsunyajing <yajing.sun@easystack.cn>2016-06-01 16:43:57 +0800
committersunyajing <yajing.sun@easystack.cn>2016-06-03 02:14:36 +0000
commit909bab1e07ec564055dd7dab578af9970a8e648e (patch)
treeab7738dfc30668d113000cbd4008aef3edf85b88 /openstackclient/compute/v2/agent.py
parent48ffd8cf4b05b6836f48b8b509af61cb09550ae9 (diff)
downloadpython-openstackclient-909bab1e07ec564055dd7dab578af9970a8e648e.tar.gz
Support multiple argument for compute agent delete command
Change-Id: I3b19e4914d475b86d7e8aa8d76e62a2ac811272f Partially-Implements: blueprint multi-argument-compute
Diffstat (limited to 'openstackclient/compute/v2/agent.py')
-rw-r--r--openstackclient/compute/v2/agent.py22
1 files changed, 19 insertions, 3 deletions
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="<id>",
- 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):