Skip to content

Commit 99ba4f8

Browse files
author
zhiyong.dai
committed
Adjust the code sequence in consistency_group.py
Place "CreateConsistencyGroup" above "DeleteConsistencyGroup" Change-Id: I554a8e445fee0760450b2da3b5c4a4f3b2434d60
1 parent e05c8d7 commit 99ba4f8

1 file changed

Lines changed: 42 additions & 45 deletions

File tree

openstackclient/volume/v2/consistency_group.py

Lines changed: 42 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -27,51 +27,6 @@
2727
LOG = logging.getLogger(__name__)
2828

2929

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-
7530
class CreateConsistencyGroup(command.ShowOne):
7631
_description = _("Create new consistency group.")
7732

@@ -143,6 +98,48 @@ def take_action(self, parsed_args):
14398
return zip(*sorted(six.iteritems(consistency_group._info)))
14499

145100

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+
146143
class ListConsistencyGroup(command.Lister):
147144
_description = _("List consistency groups.")
148145

0 commit comments

Comments
 (0)