You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by an...@apache.org on 2017/09/01 12:07:30 UTC

[3/4] libcloud git commit: Use TagSpecification parameter on EC2 create_node

Use TagSpecification parameter on EC2 create_node


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

Branch: refs/heads/trunk
Commit: 0d1be1d7a28699d726c1256682a4e63889f2a1ba
Parents: 84735c8
Author: Lucas Di Pentima <ld...@veritasgenetics.com>
Authored: Tue Aug 29 19:06:18 2017 -0300
Committer: Anthony Shaw <an...@apache.org>
Committed: Fri Sep 1 22:07:04 2017 +1000

----------------------------------------------------------------------
 libcloud/__init__.py            |  2 +-
 libcloud/compute/drivers/ec2.py | 22 +++++++++++++---------
 2 files changed, 14 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/0d1be1d7/libcloud/__init__.py
----------------------------------------------------------------------
diff --git a/libcloud/__init__.py b/libcloud/__init__.py
index 24d4a68..773c03f 100644
--- a/libcloud/__init__.py
+++ b/libcloud/__init__.py
@@ -36,7 +36,7 @@ __all__ = [
     '__version__',
     'enable_debug'
 ]
-__version__ = '2.2.0'
+__version__ = '2.2.0.dev1'
 
 
 def enable_debug(fo):

http://git-wip-us.apache.org/repos/asf/libcloud/blob/0d1be1d7/libcloud/compute/drivers/ec2.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/ec2.py b/libcloud/compute/drivers/ec2.py
index efb6275..fd807aa 100644
--- a/libcloud/compute/drivers/ec2.py
+++ b/libcloud/compute/drivers/ec2.py
@@ -3765,19 +3765,23 @@ class BaseEC2NodeDriver(NodeDriver):
             if subnet_id:
                 params['SubnetId'] = subnet_id
 
+        # Specify tags at instance creation time
+        tags = {'Name': kwargs['name']}
+        if 'ex_metadata' in kwargs:
+            tags.update(kwargs['ex_metadata'])
+        tagspec_root = 'TagSpecification.1.'
+        params[tagspec_root + 'ResourceType'] = 'instance'
+        tag_nr = 1
+        for k, v in tags.iteritems():
+            tag_root = tagspec_root + "Tag.{}.".format(tag_nr)
+            params[tag_root + "Key"] = k
+            params[tag_root + "Value"] = v
+            tag_nr += 1
+
         object = self.connection.request(self.path, params=params).object
         nodes = self._to_nodes(object, 'instancesSet/item')
 
         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)
-            except Exception:
-                continue
-
             node.name = kwargs['name']
             node.extra.update({'tags': tags})