You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by je...@apache.org on 2010/12/25 04:59:57 UTC

svn commit: r1052749 - /incubator/libcloud/trunk/libcloud/drivers/cloudsigma.py

Author: jerry
Date: Sat Dec 25 03:59:56 2010
New Revision: 1052749

URL: http://svn.apache.org/viewvc?rev=1052749&view=rev
Log:
Destroy created drive and throw an exception if the node creation fails because of insufficient funds.

Submitted By: Tomaž Muraus <ka...@k5-storitve.net>

Modified:
    incubator/libcloud/trunk/libcloud/drivers/cloudsigma.py

Modified: incubator/libcloud/trunk/libcloud/drivers/cloudsigma.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/drivers/cloudsigma.py?rev=1052749&r1=1052748&r2=1052749&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/drivers/cloudsigma.py (original)
+++ incubator/libcloud/trunk/libcloud/drivers/cloudsigma.py Sat Dec 25 03:59:56 2010
@@ -142,6 +142,10 @@ class CloudSigmaException(Exception):
     def __repr__(self):
         return "<CloudSigmaException '%s'>" % (self.args[0])
 
+class CloudSigmaInsufficientFundsException(Exception):
+    def __repr__(self):
+        return "<CloudSigmaInsufficientFundsException '%s'>" % (self.args[0])
+
 class CloudSigmaResponse(Response):
     def success(self):
         if self.status == 401:
@@ -335,10 +339,14 @@ class CloudSigmaBaseNodeDriver(NodeDrive
         response = self.connection.request(action = '/servers/create', data = dict2str(node_data),
                                            method = 'POST').object
 
-        if isinstance(response, list):
-            nodes = [self._to_node(node) for node in response]
-        else:
-            nodes = [self._to_node(response)]
+        if not isinstance(response, list):
+            response = [ response ]
+
+        node = self._to_node(response[0])
+        if node is None:
+            # Insufficient funds, destroy created drive
+            self.ex_drive_destroy(drive_uuid)
+            raise CloudSigmaInsufficientFundsException('Insufficient funds, node creation failed')
 
         # Start the node after it has been created
         node = nodes[0]
@@ -484,6 +492,11 @@ class CloudSigmaBaseNodeDriver(NodeDrive
             except KeyError:
                 state = NodeState.UNKNOWN
 
+            if 'server' not in data:
+                # Response does not contain server UUID if the server
+                # creation failed because of insufficient funds.
+                return None
+
             public_ip = []
             if data.has_key('nic:0:dhcp'):
                 if isinstance(data['nic:0:dhcp'], list):