libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pque...@apache.org
Subject svn commit: r951573 - in /incubator/libcloud/trunk: libcloud/drivers/gogrid.py test/fixtures/gogrid/server_add.json test/test_gogrid.py
Date Fri, 04 Jun 2010 21:15:30 GMT
Author: pquerna
Date: Fri Jun  4 21:15:28 2010
New Revision: 951573

URL: http://svn.apache.org/viewvc?rev=951573&view=rev
Log:
Make gogrid's create_node blocking to wait while GoGrid assigns an id to a server.

Submitted by: Roman Bogorodskiy <bogorodskiy gmail.com>

Modified:
    incubator/libcloud/trunk/libcloud/drivers/gogrid.py
    incubator/libcloud/trunk/test/fixtures/gogrid/server_add.json
    incubator/libcloud/trunk/test/test_gogrid.py

Modified: incubator/libcloud/trunk/libcloud/drivers/gogrid.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/drivers/gogrid.py?rev=951573&r1=951572&r2=951573&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/drivers/gogrid.py (original)
+++ incubator/libcloud/trunk/libcloud/drivers/gogrid.py Fri Jun  4 21:15:28 2010
@@ -150,8 +150,6 @@ class GoGridNodeDriver(NodeDriver):
         state = self._get_state(element)
         ip = self._get_ip(element)
         id = self._get_id(element)
-        if id == None:
-          raise Exception("ID is missing from Node response: "+ element)
         n = GoGridNode(id=id,
                  name=element['name'],
                  state=state,
@@ -210,7 +208,7 @@ class GoGridNodeDriver(NodeDriver):
         return self.connection.request("/api/grid/server/delete", params)
 
     def _get_first_ip(self):
-        params = {'ip.state': 'Unassigned', 'ip.type':'public'}
+        params = {'ip.state': 'Unassigned', 'ip.type': 'public'}
         object = self.connection.request("/api/grid/ip/list", params).object
         return object['list'][0]['ip']
 
@@ -235,12 +233,27 @@ class GoGridNodeDriver(NodeDriver):
         first_ip = self._get_first_ip()
         params = {'name': name,
                   'image': image.id,
-                  'description': kwargs.get('ex_description',''),
+                  'description': kwargs.get('ex_description', ''),
                   'server.ram': size.id,
-                  'ip':first_ip}
+                  'ip': first_ip}
 
         object = self.connection.request('/api/grid/server/add',
                                          params=params).object
         node = self._to_node(object['list'][0])
 
+        timeout = 60 * 20
+        waittime = 0
+        interval = 2 * 60
+
+        while node.id is None and waittime < timeout:
+            nodes = self.list_nodes()
+
+            for i in nodes:
+                if i.public_ip[0] == node.public_ip[0] and i.id is not None:
+                    node.id = i.id
+                    return node
+
+            waittime += interval
+            time.sleep(interval)
+
         return node

Modified: incubator/libcloud/trunk/test/fixtures/gogrid/server_add.json
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/test/fixtures/gogrid/server_add.json?rev=951573&r1=951572&r2=951573&view=diff
==============================================================================
--- incubator/libcloud/trunk/test/fixtures/gogrid/server_add.json (original)
+++ incubator/libcloud/trunk/test/fixtures/gogrid/server_add.json Fri Jun  4 21:15:28 2010
@@ -1,7 +1,6 @@
 {
     "list": [
         {
-            "id": 90967,
             "image": {
                 "billingtokens": [
                     {

Modified: incubator/libcloud/trunk/test/test_gogrid.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/test/test_gogrid.py?rev=951573&r1=951572&r2=951573&view=diff
==============================================================================
--- incubator/libcloud/trunk/test/test_gogrid.py (original)
+++ incubator/libcloud/trunk/test/test_gogrid.py Fri Jun  4 21:15:28 2010
@@ -38,8 +38,9 @@ class GoGridTests(unittest.TestCase, Tes
         image = NodeImage(1531, None, self.driver)
         size = NodeSize('512Mb', None, None, None, None, None, driver=self.driver)
 
-        node = self.driver.create_node(name='foo', image=image, size=size)
-        self.assertEqual(node.id, 90967)
+        node = self.driver.create_node(name='test1', image=image, size=size)
+        self.assertEqual(node.name, 'test1')
+        self.assertTrue(node.id is not None)
 
     def test_list_nodes(self):
         node = self.driver.list_nodes()[0]



Mime
View raw message