libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [4/7] git commit: Add ex_metadata parameter to create_node
Date Tue, 05 Nov 2013 19:05:22 GMT
Add ex_metadata parameter to create_node

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/9bfb08af
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/9bfb08af
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/9bfb08af

Branch: refs/heads/trunk
Commit: 9bfb08af7519d016e79a9fd75320eb1f8f6870ad
Parents: e1124b0
Author: Ivan Kusalic <ivan@ikusalic.com>
Authored: Tue Sep 10 13:02:55 2013 +0200
Committer: Tomaz Muraus <tomaz@apache.org>
Committed: Tue Nov 5 18:56:17 2013 +0000

----------------------------------------------------------------------
 libcloud/compute/drivers/ec2.py   |  5 +++++
 libcloud/test/compute/test_ec2.py | 16 ++++++++++++++++
 2 files changed, 21 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/9bfb08af/libcloud/compute/drivers/ec2.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/ec2.py b/libcloud/compute/drivers/ec2.py
index 003d7ef..4d2a724 100644
--- a/libcloud/compute/drivers/ec2.py
+++ b/libcloud/compute/drivers/ec2.py
@@ -1566,6 +1566,9 @@ class BaseEC2NodeDriver(NodeDriver):
                                         assign to the node.
         :type       ex_security_groups:   ``list``
 
+        :keyword    ex_metadata: Key/Value metadata to associate with a node
+        :type       ex_metadata: ``dict``
+
         :keyword    ex_mincount: Minimum number of instances to launch
         :type       ex_mincount: ``int``
 
@@ -1666,6 +1669,8 @@ class BaseEC2NodeDriver(NodeDriver):
 
         for node in nodes:
             tags = {'Name': kwargs['name']}
+            if 'ex_metadata' in kwargs:
+                tags.update(kwargs['ex_metadata'])
 
             try:
                 self.ex_create_tags(resource=node, tags=tags)

http://git-wip-us.apache.org/repos/asf/libcloud/blob/9bfb08af/libcloud/test/compute/test_ec2.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_ec2.py b/libcloud/test/compute/test_ec2.py
index 0840446..303d335 100644
--- a/libcloud/test/compute/test_ec2.py
+++ b/libcloud/test/compute/test_ec2.py
@@ -105,6 +105,22 @@ class EC2Tests(LibcloudTestCase, TestCaseMixin):
         self.assertEqual(node.extra['tags']['Name'], 'foo')
         self.assertEqual(len(node.extra['tags']), 1)
 
+    def test_create_node_with_metadata(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'})
+        self.assertEqual(node.name, 'foo')
+        self.assertEqual(node.extra['tags']['Name'], 'foo')
+        self.assertEqual(node.extra['tags']['Bar'], 'baz')
+        self.assertEqual(node.extra['tags']['Num'], '42')
+        self.assertEqual(len(node.extra['tags']), 3)
+
     def test_create_node_idempotent(self):
         EC2MockHttp.type = 'idempotent'
         image = NodeImage(id='ami-be3adfd7',


Mime
View raw message