libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r1196577 - in /libcloud/trunk: libcloud/compute/drivers/openstack.py test/compute/fixtures/openstack_v1.1/_servers_12063_metadata_two_keys.json test/compute/test_openstack.py
Date Wed, 02 Nov 2011 13:43:24 GMT
Author: tomaz
Date: Wed Nov  2 13:43:24 2011
New Revision: 1196577

URL: http://svn.apache.org/viewvc?rev=1196577&view=rev
Log:
Add ex_get_metadata and ex_set_metadata methods to the OpenStack 1.1 compute
driver. Contributed by Mark Everett <mark dot everett at rackspace dot com> and
part of GITHUB-33.

Added:
    libcloud/trunk/test/compute/fixtures/openstack_v1.1/_servers_12063_metadata_two_keys.json
Modified:
    libcloud/trunk/libcloud/compute/drivers/openstack.py
    libcloud/trunk/test/compute/test_openstack.py

Modified: libcloud/trunk/libcloud/compute/drivers/openstack.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/compute/drivers/openstack.py?rev=1196577&r1=1196576&r2=1196577&view=diff
==============================================================================
--- libcloud/trunk/libcloud/compute/drivers/openstack.py (original)
+++ libcloud/trunk/libcloud/compute/drivers/openstack.py Wed Nov  2 13:43:24 2011
@@ -910,18 +910,44 @@ class OpenStack_1_1_NodeDriver(OpenStack
         """
         Sets the Node's name.
         """
-        return self.ex_update_node(node, name=name)
+        return self._update_node(node, name=name)
+
+    def ex_get_metadata(self, node):
+        """
+        Get a Node's metadata.
+
+        @return     Key/Value metadata associated with node.
+        @type       C{dict}
+        """
+        return self.connection.request(
+                '/servers/%s/metadata' % (node.id,), method='GET',
+            ).object['metadata']
+
+    def ex_set_metadata(self, node, metadata):
+        """
+        Sets the Node's metadata.
+
+        @keyword    metadata: Key/Value metadata to associate with a node
+        @type       metadata: C{dict}
+        """
+        return self.connection.request(
+                '/servers/%s/metadata' % (node.id,), method='PUT',
+                data={'metadata': metadata}
+            ).object['metadata']
 
     def ex_update_node(self, node, **node_updates):
-        # Currently only setting the name is supported in OpenStack, but we
-        # leave the function signature prepared to support metadata or other
-        # fields in the future.
+        """
+        Update the Node's editable attributes.  The OpenStack API currently
+        supports editing name and IPv4/IPv6 access addresses.
+
+        The driver currently only supports updating the node name.
+
+        @keyword    name:   New name for the server
+        @type       name:   C{str}
+        """
         potential_data = self._create_args_to_params(node, node_updates)
-        return self._to_node(
-            self.connection.request(
-                '/servers/%s' % (node.id,), method='PUT',
-                data={'server': {'name': potential_data['name']}})
-                   .object['server'])
+        updates = {'name': potential_data['name']}
+        return self._update_node(node, **updates)
 
     def ex_get_size(self, size_id):
         return self._to_size(self.connection.request('/flavors/%s' %
@@ -946,6 +972,18 @@ class OpenStack_1_1_NodeDriver(OpenStack
         return self.connection.request('/servers/%s/action' % (node.id,),
                                        method='POST', data={action: params})
 
+    def _update_node(self, node, **node_updates):
+        """
+        Updates the editable attributes of a server, which currently include
+        its name and IPv4/IPv6 access addresses.
+        """
+        return self._to_node(
+            self.connection.request(
+                '/servers/%s' % (node.id,), method='PUT',
+                data={'server': node_updates}
+            ).object['server']
+        )
+
     def _to_node_from_obj(self, obj):
         return self._to_node(obj['server'])
 

Added: libcloud/trunk/test/compute/fixtures/openstack_v1.1/_servers_12063_metadata_two_keys.json
URL: http://svn.apache.org/viewvc/libcloud/trunk/test/compute/fixtures/openstack_v1.1/_servers_12063_metadata_two_keys.json?rev=1196577&view=auto
==============================================================================
--- libcloud/trunk/test/compute/fixtures/openstack_v1.1/_servers_12063_metadata_two_keys.json
(added)
+++ libcloud/trunk/test/compute/fixtures/openstack_v1.1/_servers_12063_metadata_two_keys.json
Wed Nov  2 13:43:24 2011
@@ -0,0 +1,6 @@
+{
+    "metadata" :  {
+            "Server Label" : "Web Head 1",
+            "Image Version" : "2.1"
+        }
+}

Modified: libcloud/trunk/test/compute/test_openstack.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/test/compute/test_openstack.py?rev=1196577&r1=1196576&r2=1196577&view=diff
==============================================================================
--- libcloud/trunk/test/compute/test_openstack.py (original)
+++ libcloud/trunk/test/compute/test_openstack.py Wed Nov  2 13:43:24 2011
@@ -597,6 +597,33 @@ class OpenStack_1_1_Tests(unittest.TestC
         else:
             self.fail('An expected error was not raised')
 
+    def test_ex_set_server_name(self):
+        old_node = Node(
+            id='12064', name=None, state=None,
+            public_ip=None, private_ip=None, driver=self.driver,
+        )
+        new_node = self.driver.ex_set_server_name(old_node, 'Bob')
+        self.assertEqual('Bob', new_node.name)
+
+    def test_ex_set_metadata(self):
+        old_node = Node(
+            id='12063', name=None, state=None,
+            public_ip=None, private_ip=None, driver=self.driver,
+        )
+        metadata = {'Image Version': '2.1', 'Server Label': 'Web Head 1'}
+        returned_metadata = self.driver.ex_set_metadata(old_node, metadata)
+        self.assertEqual(metadata, returned_metadata)
+
+    def test_ex_get_metadata(self):
+        node = Node(
+            id='12063', name=None, state=None,
+            public_ip=None, private_ip=None, driver=self.driver,
+        )
+
+        metadata = {'Image Version': '2.1', 'Server Label': 'Web Head 1'}
+        returned_metadata = self.driver.ex_get_metadata(node)
+        self.assertEqual(metadata, returned_metadata)
+
     def test_ex_update_node(self):
         old_node = Node(
             id='12064',
@@ -702,6 +729,19 @@ class OpenStack_1_1_MockHttp(MockHttpTes
         else:
             raise NotImplementedError()
 
+    def _servers_12062(self, method, url, body, headers):
+        if method == "GET":
+            body = self.fixtures.load('_servers_12064.json')
+            return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
+
+    def _servers_12063_metadata(self, method, url, body, headers):
+        if method == "GET":
+            body = self.fixtures.load('_servers_12063_metadata_two_keys.json')
+            return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
+        elif method == "PUT":
+            body = self.fixtures.load('_servers_12063_metadata_two_keys.json')
+            return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
+
     def _flavors_7(self, method, url, body, headers):
         if method == "GET":
             body = self.fixtures.load('_flavors_7.json')



Mime
View raw message