You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@libcloud.apache.org by Soren Hansen <so...@ubuntu.com> on 2009/12/01 10:05:37 UTC

[PATCH 0/2] Extra dict for NodeImage objects

Add an "extra" dict to NodeImage objects and make use of it in the
Rackspace driver.

Soren Hansen (2):
  Make NodeImage accept an extra dict
  Return serverId for backups in Rackspace driver

 libcloud/base.py              |    6 +++++-
 libcloud/drivers/rackspace.py |    3 ++-
 libcloud/interface.py         |    1 +
 test/test_rackspace.py        |    4 +++-
 4 files changed, 11 insertions(+), 3 deletions(-)


[PATCH 1/2] Make NodeImage accept an extra dict

Posted by Soren Hansen <so...@ubuntu.com>.
Just like a Node, there are cases where it's useful to be able to tack
on extra information to a NodeImage.

This patch adds this capability with semantics identical to those of the
extra dict for Node.
---
 libcloud/base.py      |    6 +++++-
 libcloud/interface.py |    1 +
 2 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/libcloud/base.py b/libcloud/base.py
index c99e1ca..764fd93 100644
--- a/libcloud/base.py
+++ b/libcloud/base.py
@@ -73,10 +73,14 @@ class NodeImage(object):
     interface.implements(INodeImage)
     interface.classProvides(INodeImageFactory)
 
-    def __init__(self, id, name, driver):
+    def __init__(self, id, name, driver, extra=None):
         self.id = id
         self.name = name
         self.driver = driver
+        if not extra:
+            self.extra = {}
+        else:
+            self.extra = extra
     def __repr__(self):
         return (('<NodeImage: id=%s, name=%s, driver=%s  ...>')
                 % (self.id, self.name, self.driver.name))
diff --git a/libcloud/interface.py b/libcloud/interface.py
index 22d4853..77cd18b 100644
--- a/libcloud/interface.py
+++ b/libcloud/interface.py
@@ -83,6 +83,7 @@ class INodeImage(Interface):
     id = Attribute("""Unique ID provided by the provider (ami-abcd1234, etc)""")
     name = Attribute("""Name provided by the provider (Ubuntu 8.1)""")
     driver = Attribute("""The NodeDriver that belongs to this Image""")
+    extra = Attribute("""Dict containing provider specific data""")
 
 
 class INodeImageFactory(Interface):
-- 
1.6.5


Re: [PATCH 0/2] Extra dict for NodeImage objects

Posted by Soren Hansen <so...@ubuntu.com>.
On Tue, Dec 01, 2009 at 11:07:48AM -0800, Jeremy Orem wrote:
> Have you pushed this to github? I'm not able to apply your patches.

git://github.com/sorenh/libcloud.git 

> error: patch failed: test/test_rackspace.py:118
> error: test/test_rackspace.py: patch does not apply
> Did you hand edit your patch?

Um.. No. It appears that something along the way decided to insert line
breaks into my patch. That's.. Uh.. Rather unfortunate. I sent it from
the command line, so it's not in my Sent folder, so I can't really check
if it's anything on my end.

Just for kicks, I'll try again here and see if it does it again:


-        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>"""


-- 
Soren Hansen                 | 
Lead virtualisation engineer | Ubuntu Server Team
Canonical Ltd.               | http://www.ubuntu.com/

Re: [PATCH 0/2] Extra dict for NodeImage objects

Posted by Jeremy Orem <or...@oremj.com>.
Have you pushed this to github? I'm not able to apply your patches.

error: patch failed: test/test_rackspace.py:118
error: test/test_rackspace.py: patch does not apply
Did you hand edit your patch?

-Jeremy
On 12/1/09 1:05 AM, Soren Hansen wrote:
> Add an "extra" dict to NodeImage objects and make use of it in the
> Rackspace driver.
>
> Soren Hansen (2):
>    Make NodeImage accept an extra dict
>    Return serverId for backups in Rackspace driver
>
>   libcloud/base.py              |    6 +++++-
>   libcloud/drivers/rackspace.py |    3 ++-
>   libcloud/interface.py         |    1 +
>   test/test_rackspace.py        |    4 +++-
>   4 files changed, 11 insertions(+), 3 deletions(-)
>

[PATCH 2/2] Return serverId for backups in Rackspace driver

Posted by Soren Hansen <so...@ubuntu.com>.
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