|
15 | 15 |
|
16 | 16 | """Volume v1 Type action implementations""" |
17 | 17 |
|
| 18 | +import logging |
| 19 | + |
18 | 20 | from osc_lib.cli import parseractions |
19 | 21 | from osc_lib.command import command |
| 22 | +from osc_lib import exceptions |
20 | 23 | from osc_lib import utils |
21 | 24 | import six |
22 | 25 |
|
23 | 26 | from openstackclient.i18n import _ |
24 | 27 |
|
25 | 28 |
|
| 29 | +LOG = logging.getLogger(__name__) |
| 30 | + |
| 31 | + |
26 | 32 | class CreateVolumeType(command.ShowOne): |
27 | 33 | """Create new volume type""" |
28 | 34 |
|
@@ -56,22 +62,39 @@ def take_action(self, parsed_args): |
56 | 62 |
|
57 | 63 |
|
58 | 64 | class DeleteVolumeType(command.Command): |
59 | | - """Delete volume type""" |
| 65 | + """Delete volume type(s)""" |
60 | 66 |
|
61 | 67 | def get_parser(self, prog_name): |
62 | 68 | parser = super(DeleteVolumeType, self).get_parser(prog_name) |
63 | 69 | parser.add_argument( |
64 | | - 'volume_type', |
| 70 | + 'volume_types', |
65 | 71 | metavar='<volume-type>', |
66 | | - help=_('Volume type to delete (name or ID)'), |
| 72 | + nargs='+', |
| 73 | + help=_('Volume type(s) to delete (name or ID)'), |
67 | 74 | ) |
68 | 75 | return parser |
69 | 76 |
|
70 | 77 | def take_action(self, parsed_args): |
71 | 78 | volume_client = self.app.client_manager.volume |
72 | | - volume_type_id = utils.find_resource( |
73 | | - volume_client.volume_types, parsed_args.volume_type).id |
74 | | - volume_client.volume_types.delete(volume_type_id) |
| 79 | + result = 0 |
| 80 | + |
| 81 | + for volume_type in parsed_args.volume_types: |
| 82 | + try: |
| 83 | + vol_type = utils.find_resource(volume_client.volume_types, |
| 84 | + volume_type) |
| 85 | + |
| 86 | + volume_client.volume_types.delete(vol_type) |
| 87 | + except Exception as e: |
| 88 | + result += 1 |
| 89 | + LOG.error(_("Failed to delete volume type with " |
| 90 | + "name or ID '%(volume_type)s': %(e)s") |
| 91 | + % {'volume_type': volume_type, 'e': e}) |
| 92 | + |
| 93 | + if result > 0: |
| 94 | + total = len(parsed_args.volume_types) |
| 95 | + msg = (_("%(result)s of %(total)s volume types failed " |
| 96 | + "to delete.") % {'result': result, 'total': total}) |
| 97 | + raise exceptions.CommandError(msg) |
75 | 98 |
|
76 | 99 |
|
77 | 100 | class ListVolumeType(command.Lister): |
|
0 commit comments