diff options
| author | Huanxuan Ao <huanxuan.ao@easystack.cn> | 2016-06-27 11:04:05 +0800 |
|---|---|---|
| committer | Steve Martinelli <s.martinelli@gmail.com> | 2016-06-27 20:39:23 +0000 |
| commit | af7ab03693a5708102cf6746563da289e4c1e3b7 (patch) | |
| tree | 9d87de733c25d044deab1732e595f9f1adee454c /openstackclient/compute/v2/service.py | |
| parent | 044a46ed5f040020cf80adc1ace987802344e87d (diff) | |
| download | python-openstackclient-af7ab03693a5708102cf6746563da289e4c1e3b7.tar.gz | |
Support bulk deletion for delete commands in computev2
Support bulk deletion and error handling for "keypair delete"
and "service delete" commands in computev2.
Up to now, all the delete commands in computev2 support bulk
deletion.
Change-Id: I6d5c960e9716188e56615514d0921618a15a88ec
Partially-Implements: blueprint multi-argument-compute
Partial-Bug: #1592906
Diffstat (limited to 'openstackclient/compute/v2/service.py')
| -rw-r--r-- | openstackclient/compute/v2/service.py | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/openstackclient/compute/v2/service.py b/openstackclient/compute/v2/service.py index 2e40dd7f..0b5b1cfb 100644 --- a/openstackclient/compute/v2/service.py +++ b/openstackclient/compute/v2/service.py @@ -29,21 +29,35 @@ LOG = logging.getLogger(__name__) class DeleteService(command.Command): - """Delete service command""" + """Delete compute service(s)""" def get_parser(self, prog_name): parser = super(DeleteService, self).get_parser(prog_name) parser.add_argument( "service", metavar="<service>", - help=_("Compute service to delete (ID only)") + nargs='+', + help=_("Compute service(s) to delete (ID only)") ) return parser def take_action(self, parsed_args): compute_client = self.app.client_manager.compute + result = 0 + for s in parsed_args.service: + try: + compute_client.services.delete(s) + except Exception as e: + result += 1 + LOG.error(_("Failed to delete compute service with " + "ID '%(service)s': %(e)s") + % {'service': s, 'e': e}) - compute_client.services.delete(parsed_args.service) + if result > 0: + total = len(parsed_args.service) + msg = (_("%(result)s of %(total)s compute services failed " + "to delete.") % {'result': result, 'total': total}) + raise exceptions.CommandError(msg) class ListService(command.Lister): |
