You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by rb...@apache.org on 2010/07/20 19:35:25 UTC

svn commit: r965926 - in /incubator/libcloud/trunk: CHANGES libcloud/drivers/gogrid.py test/fixtures/gogrid/password_list.json test/test_gogrid.py

Author: rbogorodskiy
Date: Tue Jul 20 17:35:24 2010
New Revision: 965926

URL: http://svn.apache.org/viewvc?rev=965926&view=rev
Log:
Implement password handling and add deployment support for GoGrid (LIBCLOUD-39).

Added:
    incubator/libcloud/trunk/test/fixtures/gogrid/password_list.json
Modified:
    incubator/libcloud/trunk/CHANGES
    incubator/libcloud/trunk/libcloud/drivers/gogrid.py
    incubator/libcloud/trunk/test/test_gogrid.py

Modified: incubator/libcloud/trunk/CHANGES
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/CHANGES?rev=965926&r1=965925&r2=965926&view=diff
==============================================================================
--- incubator/libcloud/trunk/CHANGES (original)
+++ incubator/libcloud/trunk/CHANGES Tue Jul 20 17:35:24 2010
@@ -2,12 +2,16 @@
 
 Changes with Apache Libcloud 0.4.0 [In Development]
 
+    *) Implement password handling and add deployment support
+       for GoGrid nodes.
+       [Roman Bogorodskiy]
+
     *) Fix behavior of GoGrid's create_node to wait for a Node ID.
        [Roman Bogorodskiy]
 
-   *) Add ex_create_node_nowait to GoGrid driver if you don't need to 
-      wait for a Node ID when creating a node.
-      [Roman Bogorodskiy]
+    *) Add ex_create_node_nowait to GoGrid driver if you don't need to 
+       wait for a Node ID when creating a node.
+       [Roman Bogorodskiy]
 
     *) Removed libcloud.interfaces module.
        [Paul Querna]

Modified: incubator/libcloud/trunk/libcloud/drivers/gogrid.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/drivers/gogrid.py?rev=965926&r1=965925&r2=965926&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/drivers/gogrid.py (original)
+++ incubator/libcloud/trunk/libcloud/drivers/gogrid.py Tue Jul 20 17:35:24 2010
@@ -130,6 +130,7 @@ class GoGridNodeDriver(NodeDriver):
     connectionCls = GoGridConnection
     type = Provider.GOGRID
     name = 'GoGrid API'
+    features = {"create_node": ["generates_password"]}
 
     _instance_types = GOGRID_INSTANCE_TYPES
 
@@ -146,7 +147,7 @@ class GoGridNodeDriver(NodeDriver):
     def _get_id(self, element):
         return element.get('id')
 
-    def _to_node(self, element):
+    def _to_node(self, element, password=None):
         state = self._get_state(element)
         ip = self._get_ip(element)
         id = self._get_id(element)
@@ -155,8 +156,11 @@ class GoGridNodeDriver(NodeDriver):
                  state=state,
                  public_ip=[ip],
                  private_ip=[],
-                 extra={'ram':element.get('ram').get('name')},
+                 extra={'ram': element.get('ram').get('name')},
                  driver=self.connection.driver)
+        if password:
+            n.extra['password'] = password
+
         return n
 
     def _to_image(self, element):
@@ -175,8 +179,16 @@ class GoGridNodeDriver(NodeDriver):
         return images
 
     def list_nodes(self):
+        passwords_map = {}
+
         res = self._server_list()
-        return [ self._to_node(el)
+        for password in self._password_list()['list']:
+            try:
+                passwords_map[password['server']['id']] = password['password']
+            except KeyError:
+                pass
+
+        return [ self._to_node(el, passwords_map.get(el.get('id')))
                  for el
                  in res['list'] ]
 
@@ -198,6 +210,9 @@ class GoGridNodeDriver(NodeDriver):
     def _server_list(self):
         return self.connection.request('/api/grid/server/list').object
 
+    def _password_list(self):
+        return self.connection.request('/api/support/password/list').object
+
     def _server_power(self, id, power):
         # power in ['start', 'stop', 'restart']
         params = {'id': id, 'power': power}
@@ -261,8 +276,7 @@ class GoGridNodeDriver(NodeDriver):
 
             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
+                    return i
 
             waittime += interval
             time.sleep(interval)

Added: incubator/libcloud/trunk/test/fixtures/gogrid/password_list.json
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/test/fixtures/gogrid/password_list.json?rev=965926&view=auto
==============================================================================
--- incubator/libcloud/trunk/test/fixtures/gogrid/password_list.json (added)
+++ incubator/libcloud/trunk/test/fixtures/gogrid/password_list.json Tue Jul 20 17:35:24 2010
@@ -0,0 +1,102 @@
+{
+    "list": [
+        {
+            "password": "bebebe",
+            "object": "password",
+            "username": "root",
+            "server": {
+		    "id": 90967,
+		    "image": {
+			"billingtokens": [
+			    {
+				"id": 46,
+				"name": "CentOS 5.3 32bit",
+				"price": 0
+			    }
+			],
+			"description": "CentOS 5.3 (32-bit) w/ None",
+			"friendlyName": "CentOS 5.3 (32-bit) w/ None",
+			"id": 1531,
+			"isActive": true,
+			"isPublic": true,
+			"location": "gogrid/GSI-2c4c6672-69e1-4928-ac9d-a564521d55fe.img",
+			"name": "centos5.3_32_base",
+			"object": "serverimage",
+			"os": {
+			    "description": "CentOS 5.3 (32-bit)",
+			    "id": 16,
+			    "name": "CentOS 5.3 (32-bit)",
+			    "object": "option"
+			},
+			"owner": {
+			    "id": -1,
+			    "name": "GoGrid",
+			    "object": "customer"
+			},
+			"price": 0,
+			"state": {
+			    "description": "Image is available for adds",
+			    "id": 2,
+			    "name": "Available",
+			    "object": "option"
+			},
+			"type": {
+			    "description": "Web or Application Server",
+			    "id": 1,
+			    "name": "Web Server",
+			    "object": "option"
+			},
+			"updatedTime": 1257789046453
+		    },
+		    "ip": {
+			"id": 1659927,
+			"ip": "192.168.0.202",
+			"object": "ip",
+			"public": true,
+			"state": {
+			    "description": "IP is reserved or in use",
+			    "id": 2,
+			    "name": "Assigned",
+			    "object": "option"
+			},
+			"subnet": "192.168.0.192/255.255.255.240"
+		    },
+		    "isSandbox": false,
+		    "name": "test1",
+		    "object": "server",
+		    "os": {
+			"description": "CentOS 5.3 (32-bit)",
+			"id": 16,
+			"name": "CentOS 5.3 (32-bit)",
+			"object": "option"
+		    },
+		    "ram": {
+			"description": "Server with 512MB RAM",
+			"id": 1,
+			"name": "512MB",
+			"object": "option"
+		    },
+		    "state": {
+			"description": "Server is in active state.",
+			"id": 1,
+			"name": "On",
+			"object": "option"
+		    },
+		    "type": {
+			"description": "Web or Application Server",
+			"id": 1,
+			"name": "Web Server",
+			"object": "option"
+		    }
+		}
+         }   
+    ],
+    "method": "/grid/server/list",
+    "status": "success",
+    "summary": {
+        "numpages": 0,
+        "returned": 1,
+        "start": 0,
+        "total": 1
+    }
+}

Modified: incubator/libcloud/trunk/test/test_gogrid.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/test/test_gogrid.py?rev=965926&r1=965925&r2=965926&view=diff
==============================================================================
--- incubator/libcloud/trunk/test/test_gogrid.py (original)
+++ incubator/libcloud/trunk/test/test_gogrid.py Tue Jul 20 17:35:24 2010
@@ -41,10 +41,13 @@ class GoGridTests(unittest.TestCase, Tes
         node = self.driver.create_node(name='test1', image=image, size=size)
         self.assertEqual(node.name, 'test1')
         self.assertTrue(node.id is not None)
+        self.assertEqual(node.extra['password'], 'bebebe')
 
     def test_list_nodes(self):
         node = self.driver.list_nodes()[0]
+
         self.assertEqual(node.id, 90967)
+        self.assertEqual(node.extra['password'], 'bebebe')
 
     def test_reboot_node(self):
         node = Node(90967, None, None, None, None, self.driver)
@@ -91,5 +94,9 @@ class GoGridMockHttp(MockHttp):
         body = self.fixtures.load('server_delete.json')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
+    def _api_support_password_list(self, method, url, body, headers):
+        body = self.fixtures.load('password_list.json')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
 if __name__ == '__main__':
     sys.exit(unittest.main())