You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2015/03/29 17:27:51 UTC
[4/5] libcloud git commit: Correctly handle error during create_node
and don't throw KeyError on error.
Correctly handle error during create_node and don't throw KeyError on error.
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/24f6f3ae
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/24f6f3ae
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/24f6f3ae
Branch: refs/heads/trunk
Commit: 24f6f3ae966366e4f0bfb113f8b986284e8bf0ae
Parents: dc88ea9
Author: Tomaz Muraus <to...@apache.org>
Authored: Sun Mar 29 17:14:06 2015 +0200
Committer: Tomaz Muraus <to...@apache.org>
Committed: Sun Mar 29 17:14:06 2015 +0200
----------------------------------------------------------------------
libcloud/compute/drivers/digitalocean.py | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/24f6f3ae/libcloud/compute/drivers/digitalocean.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/digitalocean.py b/libcloud/compute/drivers/digitalocean.py
index 0f4beef..32dd199 100644
--- a/libcloud/compute/drivers/digitalocean.py
+++ b/libcloud/compute/drivers/digitalocean.py
@@ -189,6 +189,14 @@ class DigitalOcean_v1_NodeDriver(DigitalOceanNodeDriver):
params['ssh_key_ids'] = ','.join(ex_ssh_key_ids)
data = self.connection.request('/v1/droplets/new', params=params)
+
+ # TODO: Handle this in the response class
+ status = data.object.get('status', 'OK')
+ if status == 'ERROR':
+ message = data.object.get('message', None)
+ error_message = data.object.get('error_message', message)
+ raise ValueError('Failed to create node: %s' % (error_message))
+
return self._to_node(data=data.object['droplet'])
def reboot_node(self, node):
@@ -337,6 +345,14 @@ class DigitalOcean_v2_NodeDriver(DigitalOceanNodeDriver):
data = self.connection.request('/v2/droplets',
params=params, method='POST').object
+
+ # TODO: Handle this in the response class
+ status = data.object.get('status', 'OK')
+ if status == 'ERROR':
+ message = data.object.get('message', None)
+ error_message = data.object.get('error_message', message)
+ raise ValueError('Failed to create node: %s' % (error_message))
+
return self._to_node(data=data['droplet'])
def reboot_node(self, node):