diff options
| author | Huanxuan Ao <huanxuan.ao@easystack.cn> | 2016-06-20 15:42:40 +0800 |
|---|---|---|
| committer | Huanxuan Ao <huanxuan.ao@easystack.cn> | 2016-06-21 11:04:13 +0800 |
| commit | 640014fa91b939e802f261346473d3ec025f2acb (patch) | |
| tree | 98af9ac80e7458d29772dd4e892bbf31485015c8 /openstackclient/compute/v2/flavor.py | |
| parent | ba825a4d5c04e2e6fd8a82ebbfb2f71a85e683aa (diff) | |
| download | python-openstackclient-640014fa91b939e802f261346473d3ec025f2acb.tar.gz | |
Support bulk deletion for "flavor/aggregate delete"
Support bulk deletion and error handling for "aggregate delete"
and "flavor delete" commands.
Change-Id: I3f6105cbeeab1c9f8cd571c63ce0e7ac3d4252b3
Partially-Implements: blueprint multi-argument-compute
Partial-Bug: #1592906
Diffstat (limited to 'openstackclient/compute/v2/flavor.py')
| -rw-r--r-- | openstackclient/compute/v2/flavor.py | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/openstackclient/compute/v2/flavor.py b/openstackclient/compute/v2/flavor.py index ab2bc85d..dc276109 100644 --- a/openstackclient/compute/v2/flavor.py +++ b/openstackclient/compute/v2/flavor.py @@ -15,6 +15,8 @@ """Flavor action implementations""" +import logging + from osc_lib.cli import parseractions from osc_lib.command import command from osc_lib import exceptions @@ -25,6 +27,9 @@ from openstackclient.i18n import _ from openstackclient.identity import common as identity_common +LOG = logging.getLogger(__name__) + + def _find_flavor(compute_client, flavor): try: return compute_client.flavors.get(flavor) @@ -140,21 +145,36 @@ class CreateFlavor(command.ShowOne): class DeleteFlavor(command.Command): - """Delete flavor""" + """Delete flavor(s)""" def get_parser(self, prog_name): parser = super(DeleteFlavor, self).get_parser(prog_name) parser.add_argument( "flavor", metavar="<flavor>", - help=_("Flavor to delete (name or ID)") + nargs='+', + help=_("Flavor(s) to delete (name or ID)") ) return parser def take_action(self, parsed_args): compute_client = self.app.client_manager.compute - flavor = _find_flavor(compute_client, parsed_args.flavor) - compute_client.flavors.delete(flavor.id) + result = 0 + for f in parsed_args.flavor: + try: + flavor = _find_flavor(compute_client, f) + compute_client.flavors.delete(flavor.id) + except Exception as e: + result += 1 + LOG.error(_("Failed to delete flavor with name or " + "ID '%(flavor)s': %(e)s") + % {'flavor': f, 'e': e}) + + if result > 0: + total = len(parsed_args.flavor) + msg = (_("%(result)s of %(total)s flavors failed " + "to delete.") % {'result': result, 'total': total}) + raise exceptions.CommandError(msg) class ListFlavor(command.Lister): |
