summaryrefslogtreecommitdiff
path: root/openstackclient/volume
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-12-02 21:02:40 +0000
committerGerrit Code Review <review@openstack.org>2016-12-02 21:02:40 +0000
commitd2701116d343f7b597d2a21499dcd2768b64291e (patch)
tree0fad9e08bbd4124feec3e3678430cedd86799b21 /openstackclient/volume
parent4debdc6dbb27d88a6b9d5ce929e403e8e1c81ee3 (diff)
parent094e5189b7bd4a84b124d17a7c70e4f9aaf7ebc7 (diff)
downloadpython-openstackclient-d2701116d343f7b597d2a21499dcd2768b64291e.tar.gz
Merge "Add "consistency group delete" command"
Diffstat (limited to 'openstackclient/volume')
-rw-r--r--openstackclient/volume/v2/consistency_group.py45
1 files changed, 45 insertions, 0 deletions
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='<consistency-group>',
+ 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__)