diff options
| author | zhiyong.dai <zhiyong.dai@easystack.cn> | 2016-11-24 21:09:55 +0800 |
|---|---|---|
| committer | Dean Troyer <dtroyer@gmail.com> | 2016-12-02 13:21:18 -0600 |
| commit | 094e5189b7bd4a84b124d17a7c70e4f9aaf7ebc7 (patch) | |
| tree | 2cb613b0bbcf972bb6cf83fd286062ad82943c2d /openstackclient/volume | |
| parent | 12442371a8df359bfc412c57430d84ce7b978eb5 (diff) | |
| download | python-openstackclient-094e5189b7bd4a84b124d17a7c70e4f9aaf7ebc7.tar.gz | |
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
Diffstat (limited to 'openstackclient/volume')
| -rw-r--r-- | openstackclient/volume/v2/consistency_group.py | 45 |
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__) |
