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 2013/01/28 03:24:49 UTC
svn commit: r1439227 - in /libcloud/branches/0.12.x: ./ CHANGES
libcloud/common/brightbox.py libcloud/compute/drivers/brightbox.py
Author: tomaz
Date: Mon Jan 28 02:24:49 2013
New Revision: 1439227
URL: http://svn.apache.org/viewvc?rev=1439227&view=rev
Log:
Backport commit r1439222 from trunk:
Improve error handling in the Brightbox driver.
Modified:
libcloud/branches/0.12.x/ (props changed)
libcloud/branches/0.12.x/CHANGES
libcloud/branches/0.12.x/libcloud/common/brightbox.py
libcloud/branches/0.12.x/libcloud/compute/drivers/brightbox.py
Propchange: libcloud/branches/0.12.x/
------------------------------------------------------------------------------
Merged /libcloud/trunk:r1439222
Modified: libcloud/branches/0.12.x/CHANGES
URL: http://svn.apache.org/viewvc/libcloud/branches/0.12.x/CHANGES?rev=1439227&r1=1439226&r2=1439227&view=diff
==============================================================================
--- libcloud/branches/0.12.x/CHANGES (original)
+++ libcloud/branches/0.12.x/CHANGES Mon Jan 28 02:24:49 2013
@@ -127,6 +127,9 @@ Changes with Apache Libcloud 0.12.0:
(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/branches/0.12.x/libcloud/common/brightbox.py
URL: http://svn.apache.org/viewvc/libcloud/branches/0.12.x/libcloud/common/brightbox.py?rev=1439227&r1=1439226&r2=1439227&view=diff
==============================================================================
--- libcloud/branches/0.12.x/libcloud/common/brightbox.py (original)
+++ libcloud/branches/0.12.x/libcloud/common/brightbox.py Mon Jan 28 02:24:49 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/branches/0.12.x/libcloud/compute/drivers/brightbox.py
URL: http://svn.apache.org/viewvc/libcloud/branches/0.12.x/libcloud/compute/drivers/brightbox.py?rev=1439227&r1=1439226&r2=1439227&view=diff
==============================================================================
--- libcloud/branches/0.12.x/libcloud/compute/drivers/brightbox.py (original)
+++ libcloud/branches/0.12.x/libcloud/compute/drivers/brightbox.py Mon Jan 28 02:24:49 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],