|
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 |
|
@@ -143,6 +98,48 @@ def take_action(self, parsed_args): |
143 | 98 | return zip(*sorted(six.iteritems(consistency_group._info))) |
144 | 99 |
|
145 | 100 |
|
| 101 | +class DeleteConsistencyGroup(command.Command): |
| 102 | + _description = _("Delete consistency group(s).") |
| 103 | + |
| 104 | + def get_parser(self, prog_name): |
| 105 | + parser = super(DeleteConsistencyGroup, self).get_parser(prog_name) |
| 106 | + parser.add_argument( |
| 107 | + 'consistency_groups', |
| 108 | + metavar='<consistency-group>', |
| 109 | + nargs="+", |
| 110 | + help=_('Consistency group(s) to delete (name or ID)'), |
| 111 | + ) |
| 112 | + parser.add_argument( |
| 113 | + '--force', |
| 114 | + action='store_true', |
| 115 | + default=False, |
| 116 | + help=_("Allow delete in state other than error or available"), |
| 117 | + ) |
| 118 | + return parser |
| 119 | + |
| 120 | + def take_action(self, parsed_args): |
| 121 | + volume_client = self.app.client_manager.volume |
| 122 | + result = 0 |
| 123 | + |
| 124 | + for i in parsed_args.consistency_groups: |
| 125 | + try: |
| 126 | + consistency_group_id = utils.find_resource( |
| 127 | + volume_client.consistencygroups, i).id |
| 128 | + volume_client.consistencygroups.delete( |
| 129 | + consistency_group_id, parsed_args.force) |
| 130 | + except Exception as e: |
| 131 | + result += 1 |
| 132 | + LOG.error(_("Failed to delete consistency group with " |
| 133 | + "name or ID '%(consistency_group)s':%(e)s") |
| 134 | + % {'consistency_group': i, 'e': e}) |
| 135 | + |
| 136 | + if result > 0: |
| 137 | + total = len(parsed_args.consistency_groups) |
| 138 | + msg = (_("%(result)s of %(total)s consistency groups failed " |
| 139 | + "to delete.") % {'result': result, 'total': total}) |
| 140 | + raise exceptions.CommandError(msg) |
| 141 | + |
| 142 | + |
146 | 143 | class ListConsistencyGroup(command.Lister): |
147 | 144 | _description = _("List consistency groups.") |
148 | 145 |
|
|
0 commit comments