diff options
| author | sunyajing <yajing.sun@easystack.cn> | 2016-06-23 12:55:54 +0800 |
|---|---|---|
| committer | Steve Martinelli <s.martinelli@gmail.com> | 2016-06-23 23:57:49 -0400 |
| commit | 6df09fd377f872388d4f855b001a6578ae6fba46 (patch) | |
| tree | df8bba22d73bf72444a184433fb41c084e26bd0a /openstackclient/identity | |
| parent | 5b144334bf526c8d368e592019fbb80c072911dc (diff) | |
| download | python-openstackclient-6df09fd377f872388d4f855b001a6578ae6fba46.tar.gz | |
Support multi-delete for commands in identity V2
Commands are "ec2 credentials delete", "service delete", "endpoint delete".
Also update their unit tests and functional tests.
Partial-Bug: #1592906
Change-Id: I1a0b7160b803a523646d09d030e6f112c81c4c24
Diffstat (limited to 'openstackclient/identity')
| -rw-r--r-- | openstackclient/identity/v2_0/ec2creds.py | 27 | ||||
| -rw-r--r-- | openstackclient/identity/v2_0/endpoint.py | 30 | ||||
| -rw-r--r-- | openstackclient/identity/v2_0/service.py | 26 |
3 files changed, 71 insertions, 12 deletions
diff --git a/openstackclient/identity/v2_0/ec2creds.py b/openstackclient/identity/v2_0/ec2creds.py index 78f65824..058b5772 100644 --- a/openstackclient/identity/v2_0/ec2creds.py +++ b/openstackclient/identity/v2_0/ec2creds.py @@ -16,13 +16,19 @@ """Identity v2 EC2 Credentials action implementations""" +import logging + 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 CreateEC2Creds(command.ShowOne): """Create EC2 credentials""" @@ -85,9 +91,10 @@ class DeleteEC2Creds(command.Command): def get_parser(self, prog_name): parser = super(DeleteEC2Creds, self).get_parser(prog_name) parser.add_argument( - 'access_key', + 'access_keys', metavar='<access-key>', - help=_('Credentials access key'), + nargs='+', + help=_('Credentials access keys'), ) parser.add_argument( '--user', @@ -108,7 +115,21 @@ class DeleteEC2Creds(command.Command): # Get the user from the current auth user = self.app.client_manager.auth_ref.user_id - identity_client.ec2.delete(user, parsed_args.access_key) + result = 0 + for access_key in parsed_args.access_keys: + try: + identity_client.ec2.delete(user, access_key) + except Exception as e: + result += 1 + LOG.error(_("Failed to delete EC2 keys with " + "access key '%(access_key)s': %(e)s") + % {'access_key': access_key, 'e': e}) + + if result > 0: + total = len(parsed_args.access_keys) + msg = (_("%(result)s of %(total)s EC2 keys failed " + "to delete.") % {'result': result, 'total': total}) + raise exceptions.CommandError(msg) class ListEC2Creds(command.Lister): diff --git a/openstackclient/identity/v2_0/endpoint.py b/openstackclient/identity/v2_0/endpoint.py index ee2bab6f..5a3b3186 100644 --- a/openstackclient/identity/v2_0/endpoint.py +++ b/openstackclient/identity/v2_0/endpoint.py @@ -15,7 +15,10 @@ """Endpoint action implementations""" +import logging + from osc_lib.command import command +from osc_lib import exceptions from osc_lib import utils import six @@ -23,6 +26,9 @@ from openstackclient.i18n import _ from openstackclient.identity import common +LOG = logging.getLogger(__name__) + + class CreateEndpoint(command.ShowOne): """Create new endpoint""" @@ -74,20 +80,36 @@ class CreateEndpoint(command.ShowOne): class DeleteEndpoint(command.Command): - """Delete endpoint""" + """Delete endpoint(s)""" def get_parser(self, prog_name): parser = super(DeleteEndpoint, self).get_parser(prog_name) parser.add_argument( - 'endpoint', + 'endpoints', metavar='<endpoint-id>', - help=_('Endpoint to delete (ID only)'), + nargs='+', + help=_('Endpoint(s) to delete (ID only)'), ) return parser def take_action(self, parsed_args): identity_client = self.app.client_manager.identity - identity_client.endpoints.delete(parsed_args.endpoint) + + result = 0 + for endpoint in parsed_args.endpoints: + try: + identity_client.endpoints.delete(endpoint) + except Exception as e: + result += 1 + LOG.error(_("Failed to delete endpoint with " + "ID '%(endpoint)s': %(e)s") + % {'endpoint': endpoint, 'e': e}) + + if result > 0: + total = len(parsed_args.endpoints) + msg = (_("%(result)s of %(total)s endpoints failed " + "to delete.") % {'result': result, 'total': total}) + raise exceptions.CommandError(msg) class ListEndpoint(command.Lister): diff --git a/openstackclient/identity/v2_0/service.py b/openstackclient/identity/v2_0/service.py index df332eb6..e318643c 100644 --- a/openstackclient/identity/v2_0/service.py +++ b/openstackclient/identity/v2_0/service.py @@ -91,21 +91,37 @@ class CreateService(command.ShowOne): class DeleteService(command.Command): - """Delete service""" + """Delete service(s)""" def get_parser(self, prog_name): parser = super(DeleteService, self).get_parser(prog_name) parser.add_argument( - 'service', + 'services', metavar='<service>', - help=_('Service to delete (type, name or ID)'), + nargs='+', + help=_('Service(s) to delete (type, name or ID)'), ) return parser def take_action(self, parsed_args): identity_client = self.app.client_manager.identity - service = common.find_service(identity_client, parsed_args.service) - identity_client.services.delete(service.id) + + result = 0 + for service in parsed_args.services: + try: + service = common.find_service(identity_client, service) + identity_client.services.delete(service.id) + except Exception as e: + result += 1 + LOG.error(_("Failed to delete service with " + "name or ID '%(service)s': %(e)s") + % {'service': service, 'e': e}) + + if result > 0: + total = len(parsed_args.services) + msg = (_("%(result)s of %(total)s services failed " + "to delete.") % {'result': result, 'total': total}) + raise exceptions.CommandError(msg) class ListService(command.Lister): |
