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/11/20 07:06:32 UTC
svn commit: r1037117 - in /incubator/libcloud/trunk:
libcloud/drivers/rackspace.py
test/fixtures/rackspace/v1_slug_images_post.xml test/test_rackspace.py
Author: rbogorodskiy
Date: Sat Nov 20 06:06:32 2010
New Revision: 1037117
URL: http://svn.apache.org/viewvc?rev=1037117&view=rev
Log:
Add extra call ex_save_image() to Rackspace driver to save images from nodes.
Added:
incubator/libcloud/trunk/test/fixtures/rackspace/v1_slug_images_post.xml
Modified:
incubator/libcloud/trunk/libcloud/drivers/rackspace.py
incubator/libcloud/trunk/test/test_rackspace.py
Modified: incubator/libcloud/trunk/libcloud/drivers/rackspace.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/drivers/rackspace.py?rev=1037117&r1=1037116&r2=1037117&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/drivers/rackspace.py (original)
+++ incubator/libcloud/trunk/libcloud/drivers/rackspace.py Sat Nov 20 06:06:32 2010
@@ -357,6 +357,7 @@ class RackspaceNodeDriver(NodeDriver):
@return: C{dict} with keys 'rate' and 'absolute'
"""
+
def _to_rate(el):
rate = {}
for item in el.items():
@@ -374,3 +375,23 @@ class RackspaceNodeDriver(NodeDriver):
absolute.update(_to_absolute(item))
return {"rate": rate, "absolute": absolute}
+
+ def ex_save_image(self, node, name):
+ """Create an image for node.
+
+ @keyword node: node to use as a base for image
+ @param node: L{Node}
+ @keyword name: name for new image
+ @param name: C{string}
+ """
+
+ image_elm = ET.Element(
+ 'image',
+ {'xmlns': NAMESPACE,
+ 'name': name,
+ 'serverId': node.id}
+ )
+
+ return self._to_image(self.connection.request("/images",
+ method="POST",
+ data=ET.tostring(image_elm)).object)
Added: incubator/libcloud/trunk/test/fixtures/rackspace/v1_slug_images_post.xml
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/test/fixtures/rackspace/v1_slug_images_post.xml?rev=1037117&view=auto
==============================================================================
--- incubator/libcloud/trunk/test/fixtures/rackspace/v1_slug_images_post.xml (added)
+++ incubator/libcloud/trunk/test/fixtures/rackspace/v1_slug_images_post.xml Sat Nov 20 06:06:32 2010
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<image xmlns="http://docs.rackspacecloud.com/servers/api/v1.0" status="QUEUED" updated="2010-11-19T23:36:58-06:00" serverId="444222" name="imgtest" id="12345"/>
+
Modified: incubator/libcloud/trunk/test/test_rackspace.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/test/test_rackspace.py?rev=1037117&r1=1037116&r2=1037117&view=diff
==============================================================================
--- incubator/libcloud/trunk/test/test_rackspace.py (original)
+++ incubator/libcloud/trunk/test/test_rackspace.py Sat Nov 20 06:06:32 2010
@@ -108,6 +108,13 @@ class RackspaceTests(unittest.TestCase,
self.assertTrue("rate" in limits)
self.assertTrue("absolute" in limits)
+ def test_ex_save_image(self):
+ node = Node(id=444222, name=None, state=None, public_ip=None, private_ip=None,
+ driver=self.driver)
+ image = self.driver.ex_save_image(node, "imgtest")
+ self.assertEqual(image.name, "imgtest")
+ self.assertEqual(image.id, "12345")
+
class RackspaceMockHttp(MockHttp):
fixtures = FileFixtures('rackspace')
@@ -140,6 +147,14 @@ class RackspaceMockHttp(MockHttp):
body = self.fixtures.load('v1_slug_flavors_detail.xml')
return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+ def _v1_0_slug_images(self, method, url, body, headers):
+ if method != "POST":
+ raise NotImplemented
+ # this is currently used for creation of new image with
+ # POST request, don't handle GET to avoid possible confusion
+ body = self.fixtures.load('v1_slug_images_post.xml')
+ return (httplib.ACCEPTED, body, {}, httplib.responses[httplib.ACCEPTED])
+
def _v1_0_slug_images_detail(self, method, url, body, headers):
body = self.fixtures.load('v1_slug_images_detail.xml')
return (httplib.OK, body, {}, httplib.responses[httplib.OK])