libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [5/7] git commit: Add ex_get_metadata_for_node to AWS and OpenStack
Date Tue, 05 Nov 2013 19:05:23 GMT
Add ex_get_metadata_for_node to AWS and OpenStack

Signed-off-by: Tomaz Muraus <tomaz@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/5cd9322d
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/5cd9322d
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/5cd9322d

Branch: refs/heads/trunk
Commit: 5cd9322d133c3d3f9d113df8de86a7ccb900cb9e
Parents: 9bfb08a
Author: Ivan Kusalic <ivan@ikusalic.com>
Authored: Tue Nov 5 11:21:30 2013 +0100
Committer: Tomaz Muraus <tomaz@apache.org>
Committed: Tue Nov 5 18:56:45 2013 +0000

----------------------------------------------------------------------
 libcloud/compute/drivers/ec2.py         | 13 +++++++++++++
 libcloud/compute/drivers/openstack.py   | 13 +++++++++++++
 libcloud/test/compute/test_ec2.py       | 17 +++++++++++++++++
 libcloud/test/compute/test_openstack.py | 11 +++++++++++
 4 files changed, 54 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/5cd9322d/libcloud/compute/drivers/ec2.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/ec2.py b/libcloud/compute/drivers/ec2.py
index 4d2a724..50528b9 100644
--- a/libcloud/compute/drivers/ec2.py
+++ b/libcloud/compute/drivers/ec2.py
@@ -1302,6 +1302,19 @@ class BaseEC2NodeDriver(NodeDriver):
                            namespace=NAMESPACE)
         return element == 'true'
 
+    def ex_get_metadata_for_node(self, node):
+        """
+        Return the metadata associated with the node.
+
+        :param      node: Node instance
+        :type       node: :class:`Node`
+
+        :return: A dictionary or other mapping of strings to strings,
+                 associating tag names with tag values.
+        :type tags: ``dict``
+        """
+        return node.extra['tags']
+
     def _add_instance_filter(self, params, node):
         """
         Add instance filter to the provided params dictionary.

http://git-wip-us.apache.org/repos/asf/libcloud/blob/5cd9322d/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index bb96828..eb6a982 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -2023,6 +2023,19 @@ class OpenStack_1_1_NodeDriver(OpenStackNodeDriver):
                                        method='POST', data=data)
         return resp.status == httplib.ACCEPTED
 
+    def ex_get_metadata_for_node(self, node):
+        """
+        Return the metadata associated with the node.
+
+        :param      node: Node instance
+        :type       node: :class:`Node`
+
+        :return: A dictionary or other mapping of strings to strings,
+                 associating tag names with tag values.
+        :type tags: ``dict``
+        """
+        return node.extra['metadata']
+
 
 class OpenStack_1_1_FloatingIpPool(object):
     """

http://git-wip-us.apache.org/repos/asf/libcloud/blob/5cd9322d/libcloud/test/compute/test_ec2.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_ec2.py b/libcloud/test/compute/test_ec2.py
index 303d335..45e59e6 100644
--- a/libcloud/test/compute/test_ec2.py
+++ b/libcloud/test/compute/test_ec2.py
@@ -630,6 +630,23 @@ class EC2Tests(LibcloudTestCase, TestCaseMixin):
                           ex_securitygroup=security_groups,
                           ex_security_groups=security_groups)
 
+    def test_ex_get_metadata_for_node(self):
+        image = NodeImage(id='ami-be3adfd7',
+                          name=self.image_name,
+                          driver=self.driver)
+        size = NodeSize('m1.small', 'Small Instance', None, None, None, None,
+                        driver=self.driver)
+        node = self.driver.create_node(name='foo',
+                                       image=image,
+                                       size=size,
+                                       ex_metadata={'Bar': 'baz', 'Num': '42'})
+
+        metadata = self.driver.ex_get_metadata_for_node(node)
+        self.assertEqual(metadata['Name'], 'foo')
+        self.assertEqual(metadata['Bar'], 'baz')
+        self.assertEqual(metadata['Num'], '42')
+        self.assertEqual(len(metadata), 3)
+
 
 class EC2USWest1Tests(EC2Tests):
     region = 'us-west-1'

http://git-wip-us.apache.org/repos/asf/libcloud/blob/5cd9322d/libcloud/test/compute/test_openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_openstack.py b/libcloud/test/compute/test_openstack.py
index a68510b..d8c7840 100644
--- a/libcloud/test/compute/test_openstack.py
+++ b/libcloud/test/compute/test_openstack.py
@@ -1412,6 +1412,17 @@ class OpenStack_1_1_Tests(unittest.TestCase, TestCaseMixin):
         network = self.driver.ex_list_networks()[0]
         self.assertTrue(self.driver.ex_delete_network(network=network))
 
+    def test_ex_get_metadata_for_node(self):
+        image = NodeImage(id=11, name='Ubuntu 8.10 (intrepid)', driver=self.driver)
+        size = NodeSize(1, '256 slice', None, None, None, None, driver=self.driver)
+        node = self.driver.create_node(name='foo',
+                                       image=image,
+                                       size=size)
+
+        metadata = self.driver.ex_get_metadata_for_node(node)
+        self.assertEqual(metadata['My Server Name'], 'Apache1')
+        self.assertEqual(len(metadata), 1)
+
 
 class OpenStack_1_1_FactoryMethodTests(OpenStack_1_1_Tests):
     should_list_locations = False


Mime
View raw message