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 2011/01/04 13:27:50 UTC

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

Author: rbogorodskiy
Date: Tue Jan  4 12:27:49 2011
New Revision: 1054994

URL: http://svn.apache.org/viewvc?rev=1054994&view=rev
Log:
- Bump GoGrid API version to 1.7
- Implment ex_edit_node() method for GoGrid driver. This
  method allows changing some of the node attributes, like
  RAM and description
- Add a simple test for it
- Update CHANGES

Added:
    incubator/libcloud/trunk/test/fixtures/gogrid/server_edit.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=1054994&r1=1054993&r2=1054994&view=diff
==============================================================================
--- incubator/libcloud/trunk/CHANGES (original)
+++ incubator/libcloud/trunk/CHANGES Tue Jan  4 12:27:49 2011
@@ -2,6 +2,10 @@
 
 Changes with Apache Libcloud 0.4.1 [In Development]
 
+    *) Implement ex_edit_node method for GoGrid driver which allows
+       changing node attributes like amount of RAM or description.
+       [Roman Bogorodskiy]
+
     *) Add ex_set_password and ex_set_server_name to Rackspace driver.
        [Peter Herndon, Paul Querna]
 

Modified: incubator/libcloud/trunk/libcloud/drivers/gogrid.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/drivers/gogrid.py?rev=1054994&r1=1054993&r2=1054994&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/drivers/gogrid.py (original)
+++ incubator/libcloud/trunk/libcloud/drivers/gogrid.py Tue Jan  4 12:27:49 2011
@@ -32,7 +32,7 @@ except ImportError:
 
 HOST = 'api.gogrid.com'
 PORTS_BY_SECURITY = { True: 443, False: 80 }
-API_VERSION = '1.5'
+API_VERSION = '1.7'
 
 STATE = {
     "Starting": NodeState.PENDING,
@@ -89,7 +89,7 @@ class GoGridResponse(Response):
         except ValueError:
             raise MalformedResponseError('Malformed reply', body=self.body, driver=GoGridNodeDriver)
 
-    def parse_body(self):        
+    def parse_body(self):
         if not self.body:
             return None
         return json.loads(self.body)
@@ -348,3 +348,18 @@ class GoGridNodeDriver(NodeDriver):
                                          method='POST').object
 
         return self._to_images(object)[0]
+
+    def ex_edit_node(self, **kwargs):
+        node = kwargs['node']
+        size = kwargs['size']
+
+        params = {'id': node.id,
+                'server.ram': size.id}
+
+        if 'ex_description' in kwargs:
+            params['description'] = kwargs['ex_description']
+
+        object = self.connection.request('/api/grid/server/edit',
+                params=params).object
+
+        return self._to_node(object['list'][0])

Added: incubator/libcloud/trunk/test/fixtures/gogrid/server_edit.json
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/test/fixtures/gogrid/server_edit.json?rev=1054994&view=auto
==============================================================================
--- incubator/libcloud/trunk/test/fixtures/gogrid/server_edit.json (added)
+++ incubator/libcloud/trunk/test/fixtures/gogrid/server_edit.json Tue Jan  4 12:27:49 2011
@@ -0,0 +1,97 @@
+{
+    "list": [
+        {
+            "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/edit",
+    "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=1054994&r1=1054993&r2=1054994&view=diff
==============================================================================
--- incubator/libcloud/trunk/test/test_gogrid.py (original)
+++ incubator/libcloud/trunk/test/test_gogrid.py Tue Jan  4 12:27:49 2011
@@ -118,6 +118,13 @@ class GoGridTests(unittest.TestCase, Tes
         image = self.driver.ex_save_image(node, "testimage")
         self.assertEqual(image.name, "testimage")
 
+    def test_ex_edit_node(self):
+        node = Node(90967, None, None, None, None, self.driver)
+        size = NodeSize('512Mb', None, None, None, None, None, driver=self.driver)
+        ret = self.driver.ex_edit_node(node=node, size=size)
+
+        self.assertTrue(isinstance(ret, Node))
+
 class GoGridMockHttp(MockHttp):
 
     fixtures = FileFixtures('gogrid')
@@ -162,6 +169,10 @@ class GoGridMockHttp(MockHttp):
         body = self.fixtures.load('server_delete.json')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
+    def _api_grid_server_edit(self, method, url, body, headers):
+        body = self.fixtures.load('server_edit.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])