summaryrefslogtreecommitdiff
path: root/openstackclient/network
diff options
context:
space:
mode:
authorHuanxuan Ao <huanxuan.ao@easystack.cn>2016-06-20 18:05:20 +0800
committerHuanxuan Ao <huanxuan.ao@easystack.cn>2016-06-20 18:05:20 +0800
commit8b6626e9b60abb15a94c6c2eac2d1536f6a1918b (patch)
tree8f486cdd528c7818df6a18460e2cf5a5ad146b48 /openstackclient/network
parentba825a4d5c04e2e6fd8a82ebbfb2f71a85e683aa (diff)
downloadpython-openstackclient-8b6626e9b60abb15a94c6c2eac2d1536f6a1918b.tar.gz
Error handling of "router delete" command
"Router delete" command supports multi deletion but no error handling. This patch add the error handling follow the rule in doc/source/command-error.rst Change-Id: I3376d957b4dc28d8282599dc909ecc5ed2b5f46a
Diffstat (limited to 'openstackclient/network')
-rw-r--r--openstackclient/network/v2/router.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/openstackclient/network/v2/router.py b/openstackclient/network/v2/router.py
index 92ecf84d..6271a878 100644
--- a/openstackclient/network/v2/router.py
+++ b/openstackclient/network/v2/router.py
@@ -19,6 +19,7 @@ import logging
from osc_lib.cli import parseractions
from osc_lib.command import command
+from osc_lib import exceptions
from osc_lib import utils
from openstackclient.i18n import _
@@ -222,9 +223,23 @@ class DeleteRouter(command.Command):
def take_action(self, parsed_args):
client = self.app.client_manager.network
+ result = 0
+
for router in parsed_args.router:
- obj = client.find_router(router)
- client.delete_router(obj)
+ try:
+ obj = client.find_router(router, ignore_missing=False)
+ client.delete_router(obj)
+ except Exception as e:
+ result += 1
+ LOG.error(_("Failed to delete router with "
+ "name or ID '%(router)s': %(e)s")
+ % {'router': router, 'e': e})
+
+ if result > 0:
+ total = len(parsed_args.router)
+ msg = (_("%(result)s of %(total)s routers failed "
+ "to delete.") % {'result': result, 'total': total})
+ raise exceptions.CommandError(msg)
class ListRouter(command.Lister):