Author: tomaz
Date: Mon Jan 28 02:10:35 2013
New Revision: 1439222
URL: http://svn.apache.org/viewvc?rev=1439222&view=rev
Log:
Improve error handling in the Brightbox driver.
Modified:
libcloud/trunk/CHANGES
libcloud/trunk/libcloud/common/brightbox.py
libcloud/trunk/libcloud/compute/drivers/brightbox.py
Modified: libcloud/trunk/CHANGES
URL:
http://svn.apache.org/viewvc/libcloud/trunk/CHANGES?rev=1439222&r1=1439221&r2=1439222&view=diff
==============================================================================
--- libcloud/trunk/CHANGES (original)
+++ libcloud/trunk/CHANGES Mon Jan 28 02:10:35 2013
@@ -146,6 +146,9 @@ Changes with Apache Libcloud in developm
(LIBCLOUD-269)
[Mahendra M]
+ - Improve error handling in the Brightbox driver.
+ [Tomaz Muraus]
+
*) DNS
- Update 'if type' checks in the update_record methods to behave correctly
Modified: libcloud/trunk/libcloud/common/brightbox.py
URL:
http://svn.apache.org/viewvc/libcloud/trunk/libcloud/common/brightbox.py?rev=1439222&r1=1439221&r2=1439222&view=diff
==============================================================================
--- libcloud/trunk/libcloud/common/brightbox.py (original)
+++ libcloud/trunk/libcloud/common/brightbox.py Mon Jan 28 02:10:35 2013
@@ -19,6 +19,7 @@ from libcloud.common.base import Connect
from libcloud.compute.types import InvalidCredsError
from libcloud.utils.py3 import b
+from libcloud.utils.py3 import httplib
try:
import simplejson as json
@@ -28,10 +29,10 @@ except ImportError:
class BrightboxResponse(JsonResponse):
def success(self):
- return self.status >= 200 and self.status < 400
+ return self.status >= httplib.OK and self.status < httplib.BAD_REQUEST
def parse_body(self):
- if self.headers['content-type'].split('; ')[0] == 'application/json':
+ if self.headers['content-type'].split(';')[0] == 'application/json':
return super(BrightboxResponse, self).parse_body()
else:
return self.body
@@ -39,7 +40,15 @@ class BrightboxResponse(JsonResponse):
def parse_error(self):
response = super(BrightboxResponse, self).parse_body()
- return '%s: %s' % (response['error_name'], response['errors'][0])
+ if 'error' in response:
+ if response['error'] in ['invalid_client', 'unauthorized_client']:
+ raise InvalidCredsError(response['error'])
+
+ return response['error']
+ elif 'error_name' in response:
+ return '%s: %s' % (response['error_name'], response['errors'][0])
+
+ return self.body
class BrightboxConnection(ConnectionUserAndKey):
@@ -54,7 +63,7 @@ class BrightboxConnection(ConnectionUser
body = json.dumps({'client_id': self.user_id, 'grant_type': 'none'})
authorization = 'Basic ' + str(base64.encodestring(b('%s:%s' %
- (self.user_id, self.key)))).rstrip()
+ (self.user_id, self.key)))).rstrip()
self.connect()
@@ -69,12 +78,11 @@ class BrightboxConnection(ConnectionUser
response = self.connection.getresponse()
- if response.status == 200:
+ if response.status == httplib.OK:
return json.loads(response.read())['access_token']
else:
- message = '%s (%s)' % (json.loads(response.read())['error'],
- response.status)
-
+ responseCls = BrightboxResponse(response=response, connection=self)
+ message = responseCls.parse_error()
raise InvalidCredsError(message)
def add_default_headers(self, headers):
Modified: libcloud/trunk/libcloud/compute/drivers/brightbox.py
URL:
http://svn.apache.org/viewvc/libcloud/trunk/libcloud/compute/drivers/brightbox.py?rev=1439222&r1=1439221&r2=1439222&view=diff
==============================================================================
--- libcloud/trunk/libcloud/compute/drivers/brightbox.py (original)
+++ libcloud/trunk/libcloud/compute/drivers/brightbox.py Mon Jan 28 02:10:35
2013
@@ -80,7 +80,7 @@ class BrightboxNodeDriver(NodeDriver):
public_ips=[cloud_ip['public_ip']
for cloud_ip in data['cloud_ips']] +
- [interface['ipv6_address']
+ [interface['ipv6_address']
for interface in data['interfaces']
if 'ipv6_address' in interface],