summaryrefslogtreecommitdiff
path: root/novaclient/exceptions.py
diff options
context:
space:
mode:
authorAndrey Kurilin <akurilin@mirantis.com>2016-01-26 12:39:52 +0200
committerAndrey Kurilin <akurilin@mirantis.com>2016-02-04 20:06:43 +0200
commit0d0749d39ffd122387fde6ee5e9b029f93e53459 (patch)
tree7fb3beda66625bbbeb23268862dd582cc5503b4f /novaclient/exceptions.py
parent3baed9ed4806bf79e271cb2f5d69e4995d727808 (diff)
downloadpython-novaclient-0d0749d39ffd122387fde6ee5e9b029f93e53459.tar.gz
Make _poll_for_status more user-friendly
NOTE: _poll_for_status is a private method, which is used only in shell module, so we can modify it without backward compatibility. _poll_for_status is used for various resources with different interfaces. In case of snapshotting, it works with Image resources, which doesn't have "fault" attribute in "error" state. To prevent AttributeError, we should take this into account. Also, an exception raised by _poll_for_status(InstanceInErrorState) should not be hardcoded for one type of resource, so this exception is renamed to ResourceInErrorState. An exception InstanceInDeletedState, which is also can be raised by _poll_for_status, is not modified, since I don't know cases when it can be used with resources other than Server. Change-Id: Ie0ee96999376cbf608caa1cf8521dbef5c939b52 Closes-Bug: #1538073
Diffstat (limited to 'novaclient/exceptions.py')
-rw-r--r--novaclient/exceptions.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/novaclient/exceptions.py b/novaclient/exceptions.py
index 94591f26..b9bdf114 100644
--- a/novaclient/exceptions.py
+++ b/novaclient/exceptions.py
@@ -77,9 +77,15 @@ class ConnectionRefused(Exception):
return "ConnectionRefused: %s" % repr(self.response)
-class InstanceInErrorState(Exception):
- """Instance is in the error state."""
- pass
+class ResourceInErrorState(Exception):
+ """Resource is in the error state."""
+
+ def __init__(self, obj):
+ msg = "`%s` resource is in the error state" % obj.__class__.__name__
+ fault_msg = getattr(obj, "fault", {}).get("message")
+ if fault_msg:
+ msg += "due to '%s'" % fault_msg
+ self.message = "%s." % msg
class VersionNotFoundForAPIMethod(Exception):