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/09 10:09:32 UTC

svn commit: r1056894 - in /incubator/libcloud/trunk: CHANGES libcloud/drivers/gogrid.py test/test_gogrid.py

Author: rbogorodskiy
Date: Sun Jan  9 09:09:32 2011
New Revision: 1056894

URL: http://svn.apache.org/viewvc?rev=1056894&view=rev
Log:
Add an extra method to GoGrid drivers to edit image attributes.

The name of the method is ex_edit_image() and it uses grid.image.edit
API cal introducent in a version 1.7 of the GoGrid API.

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=1056894&r1=1056893&r2=1056894&view=diff
==============================================================================
--- incubator/libcloud/trunk/CHANGES (original)
+++ incubator/libcloud/trunk/CHANGES Sun Jan  9 09:09:32 2011
@@ -1,5 +1,12 @@
                                                         -*- coding: utf-8 -*-
 
+Changes with Apache Libcloud 0.4.3
+
+    *) Implement ex_edit_image method for GoGrid driver
+       which allows changing image attributes like name,
+       description and make image public or private.
+       [Roman Bogorodskiy]
+
 Changes with Apache Libcloud 0.4.2
 
     *) Fix EC2 create_node to become backward compatible for

Modified: incubator/libcloud/trunk/libcloud/drivers/gogrid.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/drivers/gogrid.py?rev=1056894&r1=1056893&r2=1056894&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/drivers/gogrid.py (original)
+++ incubator/libcloud/trunk/libcloud/drivers/gogrid.py Sun Jan  9 09:09:32 2011
@@ -363,3 +363,34 @@ class GoGridNodeDriver(NodeDriver):
                 params=params).object
 
         return self._to_node(object['list'][0])
+
+    def ex_edit_image(self, **kwargs):
+        """Edit metadata of a server image.
+
+        @keyword    image: image to be edited
+        @type       image: L{NodeImage}
+        @keyword    public: should be the image public?
+        @type       public: C{bool}
+        @keyword    ex_description: description of the image (optional)
+        @type       ex_description: C{string}
+        @keyword    name: name of the image
+        @type       name C{string}
+
+        """
+
+        image = kwargs['image']
+        public = kwargs['public']
+
+        params = {'id': image.id,
+                'isPublic': str(public).lower()}
+
+        if 'ex_description' in kwargs:
+            params['description'] = kwargs['ex_description']
+
+        if 'name' in kwargs:
+            params['friendlyName'] = kwargs['name']
+
+        object = self.connection.request('/api/grid/image/edit',
+                params=params).object
+
+        return self._to_image(object['list'][0])

Modified: incubator/libcloud/trunk/test/test_gogrid.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/test/test_gogrid.py?rev=1056894&r1=1056893&r2=1056894&view=diff
==============================================================================
--- incubator/libcloud/trunk/test/test_gogrid.py (original)
+++ incubator/libcloud/trunk/test/test_gogrid.py Sun Jan  9 09:09:32 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_image(self):
+        image = self.driver.list_images()[0]
+        ret = self.driver.ex_edit_image(image=image, public=False,
+                ex_description="test", name="testname")
+
+        self.assertTrue(isinstance(ret, NodeImage))
+
     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)
@@ -183,6 +190,12 @@ class GoGridMockHttp(MockHttp):
         body = self.fixtures.load('image_save.json')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
+    def _api_grid_image_edit(self, method, url, body, headers):
+        # edit method is quite similar to save method from the response
+        # perspective
+        body = self.fixtures.load('image_save.json')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
     def _api_common_lookup_list(self, method, url, body, headers):
         _valid_lookups = ("ip.datacenter",)