libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rbogorods...@apache.org
Subject svn commit: r1032303 - in /incubator/libcloud/trunk: libcloud/drivers/gogrid.py test/fixtures/gogrid/image_save.json test/test_gogrid.py
Date Sun, 07 Nov 2010 15:47:33 GMT
Author: rbogorodskiy
Date: Sun Nov  7 15:47:32 2010
New Revision: 1032303

URL: http://svn.apache.org/viewvc?rev=1032303&view=rev
Log:
Add several minor features to GoGrid driver:

- allow to create a 'sandbox' node
- add isSandbox boolean extra property to see if a node
  is a sandbox
- add ex_save_image() method for turning node into custom
  image

Added:
    incubator/libcloud/trunk/test/fixtures/gogrid/image_save.json
Modified:
    incubator/libcloud/trunk/libcloud/drivers/gogrid.py
    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=1032303&r1=1032302&r2=1032303&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/drivers/gogrid.py (original)
+++ incubator/libcloud/trunk/libcloud/drivers/gogrid.py Sun Nov  7 15:47:32 2010
@@ -74,6 +74,7 @@ GOGRID_INSTANCE_TYPES = {'512MB': {'id':
 
 
 class GoGridResponse(Response):
+
     def success(self):
         if self.status == 403:
             raise InvalidCredsError('Invalid credentials', GoGridNodeDriver)
@@ -86,15 +87,16 @@ 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)
 
     def parse_error(self):
-        if not self.object:
+        try:
+            return json.loads(self.body)["list"][0]['message']
+        except ValueError:
             return None
-        return self.object['message']
 
 class GoGridConnection(ConnectionUserAndKey):
     """
@@ -162,7 +164,8 @@ class GoGridNodeDriver(NodeDriver):
                  state=state,
                  public_ip=[ip],
                  private_ip=[],
-                 extra={'ram': element.get('ram').get('name')},
+                 extra={'ram': element.get('ram').get('name'),
+                     'isSandbox': element['isSandbox'] == 'true'},
                  driver=self.connection.driver)
         if password:
             n.extra['password'] = password
@@ -264,6 +267,7 @@ class GoGridNodeDriver(NodeDriver):
         params = {'name': name,
                   'image': image.id,
                   'description': kwargs.get('ex_description', ''),
+                  'isSandbox': str(kwargs.get('ex_issandbox', False)).lower(),
                   'server.ram': size.id,
                   'ip': first_ip}
 
@@ -280,6 +284,8 @@ class GoGridNodeDriver(NodeDriver):
 
         @keyword    ex_description: Description of a Node
         @type       ex_description: C{string}
+        @keyword    ex_issandbox: Should server be sendbox?
+        @type       ex_issandbox: C{bool}
         """
         node = self.ex_create_node_nowait(**kwargs)
 
@@ -301,3 +307,23 @@ class GoGridNodeDriver(NodeDriver):
             raise Exception("Wasn't able to wait for id allocation for the node %s" % str(node))
 
         return node
+
+    def ex_save_image(self, node, name):
+        """Create an image for node.
+
+        Please refer to GoGrid documentation to get info
+        how prepare a node for image creation:
+
+        http://wiki.gogrid.com/wiki/index.php/MyGSI
+
+        @keyword    node: node to use as a base for image
+        @param      node: L{Node}
+        @keyword    name: name for new image
+        @param      name: C{string}
+        """
+        params = {'server': node.id,
+                  'friendlyName': name}
+        object = self.connection.request('/api/grid/image/save', params=params,
+                                         method='POST').object
+        
+        return self._to_images(object)[0]

Added: incubator/libcloud/trunk/test/fixtures/gogrid/image_save.json
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/test/fixtures/gogrid/image_save.json?rev=1032303&view=auto
==============================================================================
--- incubator/libcloud/trunk/test/fixtures/gogrid/image_save.json (added)
+++ incubator/libcloud/trunk/test/fixtures/gogrid/image_save.json Sun Nov  7 15:47:32 2010
@@ -0,0 +1,62 @@
+{
+    "list": [
+        {
+            "architecture": {
+                "description": "32 bit OS", 
+                "id": 1, 
+                "name": "32-bit", 
+                "object": "option"
+            }, 
+            "billingtokens": [
+                {
+                    "id": 46, 
+                    "name": "CentOS 5.3 32bit", 
+                    "object": "billingtoken", 
+                    "price": 0
+                }
+            ], 
+            "createdTime": 1289119839685, 
+            "description": "", 
+            "friendlyName": "testimage", 
+            "id": 5050, 
+            "isActive": true, 
+            "isPublic": false, 
+            "location": "123/GSI-3ee65927-f80d-43df-92df-6c7e352f009c.img", 
+            "name": "GSI-3ee65927-f80d-43df-92df-6c7e352f009c", 
+            "object": "serverimage", 
+            "os": {
+                "description": "CentOS 5.3 (32-bit)", 
+                "id": 16, 
+                "name": "CentOS 5.3 (32-bit)", 
+                "object": "option"
+            }, 
+            "owner": {
+                "id": 123, 
+                "name": "name", 
+                "object": "customer"
+            }, 
+            "price": 0, 
+            "state": {
+                "description": "Image is being saved", 
+                "id": 1, 
+                "name": "Saving", 
+                "object": "option"
+            }, 
+            "type": {
+                "description": "Web or Application Server", 
+                "id": 1, 
+                "name": "Web Server", 
+                "object": "option"
+            }, 
+            "updatedTime": 1289119839685
+        }
+    ], 
+    "method": "/grid/image/save", 
+    "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=1032303&r1=1032302&r2=1032303&view=diff
==============================================================================
--- incubator/libcloud/trunk/test/test_gogrid.py (original)
+++ incubator/libcloud/trunk/test/test_gogrid.py Sun Nov  7 15:47:32 2010
@@ -50,6 +50,7 @@ class GoGridTests(unittest.TestCase, Tes
 
         self.assertEqual(node.id, '90967')
         self.assertEqual(node.extra['password'], 'bebebe')
+        self.assertEqual(node.extra['isSandbox'], False)
 
     def test_reboot_node(self):
         node = Node(90967, None, None, None, None, self.driver)
@@ -101,6 +102,11 @@ class GoGridTests(unittest.TestCase, Tes
         else:
             self.fail("test should have thrown")
 
+    def test_ex_save_image(self):
+        node = self.driver.list_nodes()[0]
+        image = self.driver.ex_save_image(node, "testimage")
+        self.assertEqual(image.name, "testimage")
+
 class GoGridMockHttp(MockHttp):
 
     fixtures = FileFixtures('gogrid')
@@ -111,7 +117,8 @@ class GoGridMockHttp(MockHttp):
 
     def _api_grid_image_list_FAIL(self, method, url, body, headers):
         body = "<h3>some non valid json here</h3>"
-        return (httplib.SERVICE_UNAVAILABLE, body, {}, httplib.responses[httplib.SERVICE_UNAVAILABLE])
+        return (httplib.SERVICE_UNAVAILABLE, body, {},
+                httplib.responses[httplib.SERVICE_UNAVAILABLE])
 
     def _api_grid_server_list(self, method, url, body, headers):
         body = self.fixtures.load('server_list.json')
@@ -150,5 +157,9 @@ class GoGridMockHttp(MockHttp):
 
     _api_support_password_list_NOPUBIPS = _api_support_password_list
 
+    def _api_grid_image_save(self, method, url, body, headers):
+        body = self.fixtures.load('image_save.json')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
 if __name__ == '__main__':
     sys.exit(unittest.main())



Mime
View raw message