libcloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Soren Hansen <so...@ubuntu.com>
Subject [PATCH 2/2] Return serverId for backups in Rackspace driver
Date Mon, 30 Nov 2009 22:02:29 GMT
Backups on the Rackspace Cloud are stored as images, so they can be seen
in response to list_images. However, as they are generically named, it's
currently impossible to tell of which Node they're a backup.

The Rackspace Cloud API returns the serverId of the origin Node. Add
this to the extra dict of the image.
---
 libcloud/drivers/rackspace.py |    3 ++-
 test/test_rackspace.py        |    4 +++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/libcloud/drivers/rackspace.py b/libcloud/drivers/rackspace.py
index 061c648..d5cbb81 100644
--- a/libcloud/drivers/rackspace.py
+++ b/libcloud/drivers/rackspace.py
@@ -266,5 +266,6 @@ class RackspaceNodeDriver(NodeDriver):
     def _to_image(self, el):
         i = NodeImage(id=el.get('id'),
                      name=el.get('name'),
-                     driver=self.connection.driver)
+                     driver=self.connection.driver,
+                     extra = { 'serverId' : el.get('serverId') })
         return i
diff --git a/test/test_rackspace.py b/test/test_rackspace.py
index 9426011..551edc1 100644
--- a/test/test_rackspace.py
+++ b/test/test_rackspace.py
@@ -60,6 +60,8 @@ class RackspaceTests(unittest.TestCase, TestCaseMixin):
 
     def test_list_images(self):
         ret = self.driver.list_images()
+        self.assertEqual(ret[10].extra['serverId'], None)
+        self.assertEqual(ret[11].extra['serverId'], '91221')
 
     def test_create_node(self):
         image = NodeImage(id=11, name='Ubuntu 8.10 (intrepid)', driver=self.driver)
@@ -118,7 +120,7 @@ class RackspaceMockHttp(MockHttp):
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
     def _v1_0_slug_images_detail(self, method, url, body, headers):
-        body = """<?xml version="1.0" encoding="UTF-8" standalone="yes"?><images
xmlns="http://docs.rackspacecloud.com/servers/api/v1.0"><image status="ACTIVE" created="2009-07-20T09:14:37-05:00"
updated="2009-07-20T09:14:37-05:00" name="CentOS 5.2" id="2"/><image status="ACTIVE"
created="2009-07-20T09:14:37-05:00" updated="2009-07-20T09:14:37-05:00" name="Gentoo 2008.0"
id="3"/><image status="ACTIVE" created="2009-07-20T09:14:37-05:00" updated="2009-07-20T09:14:37-05:00"
name="Debian 5.0 (lenny)" id="4"/><image status="ACTIVE" created="2009-07-20T09:14:37-05:00"
updated="2009-07-20T09:14:37-05:00" name="Fedora 10 (Cambridge)" id="5"/><image status="ACTIVE"
created="2009-07-20T09:14:37-05:00" updated="2009-07-20T09:14:37-05:00" name="CentOS 5.3"
id="7"/><image status="ACTIVE" created="2009-07-20T09:14:37-05:00" updated="2009-07-20T09:14:37-05:00"
name="Ubuntu 9.04 (jaunty)" id="8"/><image status="ACTIVE" created="2009-07-20T09:14:37-05:00"
updated="2009-07-20T09:14:37-05:00"
  name="Arch 2009.02" id="9"/><image status="ACTIVE" created="2009-07-20T09:14:37-05:00"
updated="2009-07-20T09:14:37-05:00" name="Ubuntu 8.04.2 LTS (hardy)" id="10"/><image
status="ACTIVE" created="2009-07-20T09:14:37-05:00" updated="2009-07-20T09:14:37-05:00" name="Ubuntu
8.10 (intrepid)" id="11"/><image status="ACTIVE" created="2009-07-20T09:14:37-05:00"
updated="2009-07-20T09:14:37-05:00" name="Red Hat EL 5.3" id="12"/><image status="ACTIVE"
created="2009-07-20T09:14:37-05:00" updated="2009-07-20T09:14:37-05:00" name="Fedora 11 (Leonidas)"
id="13"/></images>"""
+        body = """<?xml version="1.0" encoding="UTF-8" standalone="yes"?><images
xmlns="http://docs.rackspacecloud.com/servers/api/v1.0"><image status="ACTIVE" created="2009-07-20T09:14:37-05:00"
updated="2009-07-20T09:14:37-05:00" name="CentOS 5.2" id="2"/><image status="ACTIVE"
created="2009-07-20T09:14:37-05:00" updated="2009-07-20T09:14:37-05:00" name="Gentoo 2008.0"
id="3"/><image status="ACTIVE" created="2009-07-20T09:14:37-05:00" updated="2009-07-20T09:14:37-05:00"
name="Debian 5.0 (lenny)" id="4"/><image status="ACTIVE" created="2009-07-20T09:14:37-05:00"
updated="2009-07-20T09:14:37-05:00" name="Fedora 10 (Cambridge)" id="5"/><image status="ACTIVE"
created="2009-07-20T09:14:37-05:00" updated="2009-07-20T09:14:37-05:00" name="CentOS 5.3"
id="7"/><image status="ACTIVE" created="2009-07-20T09:14:37-05:00" updated="2009-07-20T09:14:37-05:00"
name="Ubuntu 9.04 (jaunty)" id="8"/><image status="ACTIVE" created="2009-07-20T09:14:37-05:00"
updated="2009-07-20T09:14:37-05:00"
  name="Arch 2009.02" id="9"/><image status="ACTIVE" created="2009-07-20T09:14:37-05:00"
updated="2009-07-20T09:14:37-05:00" name="Ubuntu 8.04.2 LTS (hardy)" id="10"/><image
status="ACTIVE" created="2009-07-20T09:14:37-05:00" updated="2009-07-20T09:14:37-05:00" name="Ubuntu
8.10 (intrepid)" id="11"/><image status="ACTIVE" created="2009-07-20T09:14:37-05:00"
updated="2009-07-20T09:14:37-05:00" name="Red Hat EL 5.3" id="12"/><image status="ACTIVE"
created="2009-07-20T09:14:37-05:00" updated="2009-07-20T09:14:37-05:00" name="Fedora 11 (Leonidas)"
id="13"/><image status="ACTIVE" progress="100" created="2009-11-29T20:22:09-06:00" updated="2009-11-29T20:24:08-06:00"
serverId="91221" name="daily" id="191234"/></images>"""
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
         
     def _v1_0_slug_servers(self, method, url, body, headers):
-- 
1.6.5


Mime
View raw message