|
15 | 15 |
|
16 | 16 | """Endpoint action implementations""" |
17 | 17 |
|
| 18 | +import logging |
| 19 | + |
18 | 20 | from osc_lib.command import command |
| 21 | +from osc_lib import exceptions |
19 | 22 | from osc_lib import utils |
20 | 23 | import six |
21 | 24 |
|
22 | 25 | from openstackclient.i18n import _ |
23 | 26 | from openstackclient.identity import common |
24 | 27 |
|
25 | 28 |
|
| 29 | +LOG = logging.getLogger(__name__) |
| 30 | + |
| 31 | + |
26 | 32 | class CreateEndpoint(command.ShowOne): |
27 | 33 | """Create new endpoint""" |
28 | 34 |
|
@@ -74,20 +80,36 @@ def take_action(self, parsed_args): |
74 | 80 |
|
75 | 81 |
|
76 | 82 | class DeleteEndpoint(command.Command): |
77 | | - """Delete endpoint""" |
| 83 | + """Delete endpoint(s)""" |
78 | 84 |
|
79 | 85 | def get_parser(self, prog_name): |
80 | 86 | parser = super(DeleteEndpoint, self).get_parser(prog_name) |
81 | 87 | parser.add_argument( |
82 | | - 'endpoint', |
| 88 | + 'endpoints', |
83 | 89 | metavar='<endpoint-id>', |
84 | | - help=_('Endpoint to delete (ID only)'), |
| 90 | + nargs='+', |
| 91 | + help=_('Endpoint(s) to delete (ID only)'), |
85 | 92 | ) |
86 | 93 | return parser |
87 | 94 |
|
88 | 95 | def take_action(self, parsed_args): |
89 | 96 | identity_client = self.app.client_manager.identity |
90 | | - identity_client.endpoints.delete(parsed_args.endpoint) |
| 97 | + |
| 98 | + result = 0 |
| 99 | + for endpoint in parsed_args.endpoints: |
| 100 | + try: |
| 101 | + identity_client.endpoints.delete(endpoint) |
| 102 | + except Exception as e: |
| 103 | + result += 1 |
| 104 | + LOG.error(_("Failed to delete endpoint with " |
| 105 | + "ID '%(endpoint)s': %(e)s") |
| 106 | + % {'endpoint': endpoint, 'e': e}) |
| 107 | + |
| 108 | + if result > 0: |
| 109 | + total = len(parsed_args.endpoints) |
| 110 | + msg = (_("%(result)s of %(total)s endpoints failed " |
| 111 | + "to delete.") % {'result': result, 'total': total}) |
| 112 | + raise exceptions.CommandError(msg) |
91 | 113 |
|
92 | 114 |
|
93 | 115 | class ListEndpoint(command.Lister): |
|
0 commit comments