summaryrefslogtreecommitdiff
path: root/openstackclient/network
diff options
context:
space:
mode:
authorHuanxuan Ao <huanxuan.ao@easystack.cn>2016-06-03 17:29:41 +0800
committerHuanxuan Ao <huanxuan.ao@easystack.cn>2016-06-07 16:00:54 +0800
commiteb421f6dabead63318139e2db5d0d11498c40a68 (patch)
treef64a725b57568e4cda397e1446bd2ad12bca654b /openstackclient/network
parent48ffd8cf4b05b6836f48b8b509af61cb09550ae9 (diff)
downloadpython-openstackclient-eb421f6dabead63318139e2db5d0d11498c40a68.tar.gz
Support error handling for "port delete" command
"Port delete" command supported deleting multi ports before but didn't support error handing, This patch add the error handling following the rules in doc/source/command-errors.rst. Change-Id: I4ea69f2279763626d6a27cad1ca0ee99822d016d Partially-Implements: blueprint multi-argument-network
Diffstat (limited to 'openstackclient/network')
-rw-r--r--openstackclient/network/v2/port.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/openstackclient/network/v2/port.py b/openstackclient/network/v2/port.py
index ca02281f..7ef3964b 100644
--- a/openstackclient/network/v2/port.py
+++ b/openstackclient/network/v2/port.py
@@ -284,10 +284,23 @@ class DeletePort(command.Command):
def take_action(self, parsed_args):
client = self.app.client_manager.network
+ result = 0
for port in parsed_args.port:
- res = client.find_port(port)
- client.delete_port(res)
+ try:
+ obj = client.find_port(port, ignore_missing=False)
+ client.delete_port(obj)
+ except Exception as e:
+ result += 1
+ self.app.log.error(_("Failed to delete port with "
+ "name or ID '%(port)s': %(e)s")
+ % {'port': port, 'e': e})
+
+ if result > 0:
+ total = len(parsed_args.port)
+ msg = (_("%(result)s of %(total)s ports failed "
+ "to delete.") % {'result': result, 'total': total})
+ raise exceptions.CommandError(msg)
class ListPort(command.Lister):