|
27 | 27 | LOG = logging.getLogger(__name__) |
28 | 28 |
|
29 | 29 |
|
30 | | -class DeleteConsistencyGroup(command.Command): |
31 | | - _description = _("Delete consistency group(s).") |
32 | | - |
33 | | - def get_parser(self, prog_name): |
34 | | - parser = super(DeleteConsistencyGroup, self).get_parser(prog_name) |
35 | | - parser.add_argument( |
36 | | - 'consistency_groups', |
37 | | - metavar='<consistency-group>', |
38 | | - nargs="+", |
39 | | - help=_('Consistency group(s) to delete (name or ID)'), |
40 | | - ) |
41 | | - parser.add_argument( |
42 | | - '--force', |
43 | | - action='store_true', |
44 | | - default=False, |
45 | | - help=_("Allow delete in state other than error or available"), |
46 | | - ) |
47 | | - return parser |
48 | | - |
49 | | - def take_action(self, parsed_args): |
50 | | - volume_client = self.app.client_manager.volume |
51 | | - result = 0 |
52 | | - |
53 | | - for i in parsed_args.consistency_groups: |
54 | | - try: |
55 | | - consistency_group_id = utils.find_resource( |
56 | | - volume_client.consistencygroups, i).id |
57 | | - volume_client.consistencygroups.delete( |
58 | | - consistency_group_id, parsed_args.force) |
59 | | - except Exception as e: |
60 | | - result += 1 |
61 | | - LOG.error(_("Failed to delete consistency group with " |
62 | | - "name or ID '%(consistency_group)s':%(e)s") |
63 | | - % {'consistency_group': i, 'e': e}) |
64 | | - |
65 | | - if result > 0: |
66 | | - total = len(parsed_args.consistency_groups) |
67 | | - msg = (_("%(result)s of %(total)s consistency groups failed " |
68 | | - "to delete.") % {'result': result, 'total': total}) |
69 | | - raise exceptions.CommandError(msg) |
70 | | - |
71 | | - |
72 | | -LOG = logging.getLogger(__name__) |
73 | | - |
74 | | - |
75 | 30 | class CreateConsistencyGroup(command.ShowOne): |
76 | 31 | _description = _("Create new consistency group.") |
77 | 32 |
|
@@ -154,6 +109,48 @@ def take_action(self, parsed_args): |
154 | 109 | return zip(*sorted(six.iteritems(consistency_group._info))) |
155 | 110 |
|
156 | 111 |
|
| 112 | +class DeleteConsistencyGroup(command.Command): |
| 113 | + _description = _("Delete consistency group(s).") |
| 114 | + |
| 115 | + def get_parser(self, prog_name): |
| 116 | + parser = super(DeleteConsistencyGroup, self).get_parser(prog_name) |
| 117 | + parser.add_argument( |
| 118 | + 'consistency_groups', |
| 119 | + metavar='<consistency-group>', |
| 120 | + nargs="+", |
| 121 | + help=_('Consistency group(s) to delete (name or ID)'), |
| 122 | + ) |
| 123 | + parser.add_argument( |
| 124 | + '--force', |
| 125 | + action='store_true', |
| 126 | + default=False, |
| 127 | + help=_("Allow delete in state other than error or available"), |
| 128 | + ) |
| 129 | + return parser |
| 130 | + |
| 131 | + def take_action(self, parsed_args): |
| 132 | + volume_client = self.app.client_manager.volume |
| 133 | + result = 0 |
| 134 | + |
| 135 | + for i in parsed_args.consistency_groups: |
| 136 | + try: |
| 137 | + consistency_group_id = utils.find_resource( |
| 138 | + volume_client.consistencygroups, i).id |
| 139 | + volume_client.consistencygroups.delete( |
| 140 | + consistency_group_id, parsed_args.force) |
| 141 | + except Exception as e: |
| 142 | + result += 1 |
| 143 | + LOG.error(_("Failed to delete consistency group with " |
| 144 | + "name or ID '%(consistency_group)s':%(e)s") |
| 145 | + % {'consistency_group': i, 'e': e}) |
| 146 | + |
| 147 | + if result > 0: |
| 148 | + total = len(parsed_args.consistency_groups) |
| 149 | + msg = (_("%(result)s of %(total)s consistency groups failed " |
| 150 | + "to delete.") % {'result': result, 'total': total}) |
| 151 | + raise exceptions.CommandError(msg) |
| 152 | + |
| 153 | + |
157 | 154 | class ListConsistencyGroup(command.Lister): |
158 | 155 | _description = _("List consistency groups.") |
159 | 156 |
|
|
0 commit comments