diff options
| author | Tang Chen <chen.tang@easystack.cn> | 2016-03-14 14:03:04 +0800 |
|---|---|---|
| committer | Tang Chen <chen.tang@easystack.cn> | 2016-04-14 13:54:14 +0800 |
| commit | 56f9227063cb86594600ccc80c661101f0f0c2c8 (patch) | |
| tree | c682b181aaf6cb831a33cfb383a310ec2f05af48 /doc/source/command-errors.rst | |
| parent | be6027e09b806496d20b833a5f9ed6fcf44156b6 (diff) | |
| download | python-openstackclient-56f9227063cb86594600ccc80c661101f0f0c2c8.tar.gz | |
Enhance exception handling for "network delete" command
This patch rework "network delete" command following the
rules in doc/source/command-errors.rst.
In "network delete" command, there are multiple REST API
calls, and we should make as many of them as possible.
And log error for each one, give a better error message.
Also return a non-zero exit code.
Change-Id: I39ae087dd7bd08d049d513abfa6c5cab2bd13b2b
Partial-Bug: #1556719
Diffstat (limited to 'doc/source/command-errors.rst')
| -rw-r--r-- | doc/source/command-errors.rst | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/doc/source/command-errors.rst b/doc/source/command-errors.rst index 35d7f9d0..a24dc317 100644 --- a/doc/source/command-errors.rst +++ b/doc/source/command-errors.rst @@ -99,8 +99,8 @@ to be handled by having the proper options in a set command available to allow recovery in the case where the primary resource has been created but the subsequent calls did not complete. -Example -~~~~~~~ +Example 1 +~~~~~~~~~ This example is taken from the ``volume snapshot set`` command where ``--property`` arguments are set using the volume manager's ``set_metadata()`` method, @@ -161,3 +161,41 @@ remaining arguments are set using the ``update()`` method. # without aborting prematurely if result > 0: raise SomeNonFatalException + +Example 2 +~~~~~~~~~ + +This example is taken from the ``network delete`` command which takes multiple +networks to delete. All networks will be delete in a loop, which makes multiple +``delete_network()`` calls. + +.. code-block:: python + + class DeleteNetwork(common.NetworkAndComputeCommand): + """Delete network(s)""" + + def update_parser_common(self, parser): + parser.add_argument( + 'network', + metavar="<network>", + nargs="+", + help=("Network(s) to delete (name or ID)") + ) + return parser + + def take_action(self, client, parsed_args): + ret = 0 + + for network in parsed_args.network: + try: + obj = client.find_network(network, ignore_missing=False) + client.delete_network(obj) + except Exception: + self.app.log.error("Failed to delete network with name " + "or ID %s." % network) + ret += 1 + + if ret > 0: + total = len(parsed_args.network) + msg = "Failed to delete %s of %s networks." % (ret, total) + raise exceptions.CommandError(msg) |
