From 094e5189b7bd4a84b124d17a7c70e4f9aaf7ebc7 Mon Sep 17 00:00:00 2001 From: "zhiyong.dai" Date: Thu, 24 Nov 2016 21:09:55 +0800 Subject: Add "consistency group delete" command Add "consistency group delete" command in volume v2 (v2 only). Change-Id: Ieebc2417df0d45a578d5617bad245d7863f09190 Implements: bp cinder-command-support Partial-Bug: #1613964 --- openstackclient/volume/v2/consistency_group.py | 45 ++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'openstackclient/volume') diff --git a/openstackclient/volume/v2/consistency_group.py b/openstackclient/volume/v2/consistency_group.py index 9316f287..a90091a6 100644 --- a/openstackclient/volume/v2/consistency_group.py +++ b/openstackclient/volume/v2/consistency_group.py @@ -17,11 +17,56 @@ import logging from osc_lib.command import command +from osc_lib import exceptions from osc_lib import utils import six from openstackclient.i18n import _ +LOG = logging.getLogger(__name__) + + +class DeleteConsistencyGroup(command.Command): + _description = _("Delete consistency group(s).") + + def get_parser(self, prog_name): + parser = super(DeleteConsistencyGroup, self).get_parser(prog_name) + parser.add_argument( + 'consistency_groups', + metavar='', + nargs="+", + help=_('Consistency group(s) to delete (name or ID)'), + ) + parser.add_argument( + '--force', + action='store_true', + default=False, + help=_("Allow delete in state other than error or available"), + ) + return parser + + def take_action(self, parsed_args): + volume_client = self.app.client_manager.volume + result = 0 + + for i in parsed_args.consistency_groups: + try: + consistency_group_id = utils.find_resource( + volume_client.consistencygroups, i).id + volume_client.consistencygroups.delete( + consistency_group_id, parsed_args.force) + except Exception as e: + result += 1 + LOG.error(_("Failed to delete consistency group with " + "name or ID '%(consistency_group)s':%(e)s") + % {'consistency_group': i, 'e': e}) + + if result > 0: + total = len(parsed_args.consistency_groups) + msg = (_("%(result)s of %(total)s consistency groups failed " + "to delete.") % {'result': result, 'total': total}) + raise exceptions.CommandError(msg) + LOG = logging.getLogger(__name__) -- cgit v1.2.1