libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [1/2] git commit: Fix setting Name tags and name attributes when creating some objects in the EC2 driver.
Date Tue, 24 Jun 2014 18:10:57 GMT
Repository: libcloud
Updated Branches:
  refs/heads/trunk ee39aad51 -> 8f704e86f


Fix setting Name tags and name attributes when creating some objects
in the EC2 driver.

Closes #322

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

Branch: refs/heads/trunk
Commit: 158380bb8e84bb584f9314cbc5579a80c219f75c
Parents: ee39aad
Author: Lior Goikhburg <goikhburg@gmail.com>
Authored: Mon Jun 23 16:51:33 2014 +0400
Committer: Tomaz Muraus <tomaz@apache.org>
Committed: Tue Jun 24 19:59:16 2014 +0200

----------------------------------------------------------------------
 libcloud/compute/drivers/ec2.py | 58 +++++++++++++++++++++---------------
 1 file changed, 34 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/158380bb/libcloud/compute/drivers/ec2.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/ec2.py b/libcloud/compute/drivers/ec2.py
index 657ae36..77e7629 100644
--- a/libcloud/compute/drivers/ec2.py
+++ b/libcloud/compute/drivers/ec2.py
@@ -1746,12 +1746,15 @@ class EC2RouteTable(object):
     Note: This class is VPC specific.
     """
 
-    def __init__(self, id, routes, subnet_associations,
+    def __init__(self, id, name, routes, subnet_associations,
                  propagating_gateway_ids, extra=None):
         """
         :param      id: The ID of the route table.
         :type       id: ``str``
 
+        :param      name: The name of the route table.
+        :type       name: ``str``
+
         :param      routes: A list of routes in the route table.
         :type       routes: ``list`` of :class:`EC2Route`
 
@@ -1767,6 +1770,7 @@ class EC2RouteTable(object):
         """
 
         self.id = id
+        self.name = name
         self.routes = routes
         self.subnet_associations = subnet_associations
         self.propagating_gateway_ids = propagating_gateway_ids
@@ -2193,7 +2197,10 @@ class BaseEC2NodeDriver(NodeDriver):
         volume = self._to_volume(
             self.connection.request(self.path, params=params).object,
             name=name)
-        self.ex_create_tags(volume, {'Name': name})
+
+        if self.ex_create_tags(volume, {'Name': name}):
+            volume.extra['tags']['Name'] = name
+
         return volume
 
     def attach_volume(self, node, volume, device):
@@ -2245,8 +2252,8 @@ class BaseEC2NodeDriver(NodeDriver):
         response = self.connection.request(self.path, params=params).object
         snapshot = self._to_snapshot(response, name)
 
-        if name:
-            self.ex_create_tags(snapshot, {'Name': name})
+        if name and self.ex_create_tags(snapshot, {'Name': name}):
+            snapshot.extra['tags']['Name'] = name
 
         return snapshot
 
@@ -2586,10 +2593,10 @@ class BaseEC2NodeDriver(NodeDriver):
         element = response.findall(fixxpath(xpath='vpc',
                                             namespace=NAMESPACE))[0]
 
-        network = self._to_network(element)
+        network = self._to_network(element, name)
 
-        if name is not None:
-            self.ex_create_tags(network, {'Name': name})
+        if name and self.ex_create_tags(network, {'Name': name}):
+            network.extra['tags']['Name'] = name
 
         return network
 
@@ -2669,10 +2676,10 @@ class BaseEC2NodeDriver(NodeDriver):
         element = response.findall(fixxpath(xpath='subnet',
                                             namespace=NAMESPACE))[0]
 
-        subnet = self._to_subnet(element)
+        subnet = self._to_subnet(element, name)
 
-        if name is not None:
-            self.ex_create_tags(subnet, {'Name': name})
+        if name and self.ex_create_tags(subnet, {'Name': name}):
+            subnet.extra['tags']['Name'] = name
 
         return subnet
 
@@ -3528,9 +3535,8 @@ class BaseEC2NodeDriver(NodeDriver):
 
         interface = self._to_interface(element, name)
 
-        if name is not None:
-            tags = {'Name': name}
-            self.ex_create_tags(resource=interface, tags=tags)
+        if name and self.ex_create_tags(interface, {'Name': name}):
+            interface.extra['tags']['Name'] = name
 
         return interface
 
@@ -4038,8 +4044,8 @@ class BaseEC2NodeDriver(NodeDriver):
 
         gateway = self._to_internet_gateway(element[0], name)
 
-        if name is not None:
-            self.ex_create_tags(gateway, {'Name': name})
+        if name and self.ex_create_tags(gateway, {'Name': name}):
+            gateway.extra['tags']['Name'] = name
 
         return gateway
 
@@ -4153,10 +4159,10 @@ class BaseEC2NodeDriver(NodeDriver):
         element = response.findall(fixxpath(xpath='routeTable',
                                             namespace=NAMESPACE))[0]
 
-        route_table = self._to_route_table(element)
+        route_table = self._to_route_table(element, name=name)
 
-        if name:
-            self.ex_create_tags(route_table, {'Name': name})
+        if name and self.ex_create_tags(route_table, {'Name': name}):
+            route_table.extra['tags']['Name'] = name
 
         return route_table
 
@@ -4505,6 +4511,8 @@ class BaseEC2NodeDriver(NodeDriver):
         extra = self._get_extra_dict(
             element, RESOURCE_EXTRA_ATTRIBUTES_MAP['volume'])
 
+        extra['tags'] = tags
+
         return StorageVolume(id=volId,
                              name=name,
                              size=int(size),
@@ -4667,7 +4675,7 @@ class BaseEC2NodeDriver(NodeDriver):
             fixxpath(xpath='vpcSet/item', namespace=NAMESPACE))
         ]
 
-    def _to_network(self, element):
+    def _to_network(self, element, name=None):
         # Get the network id
         vpc_id = findtext(element=element,
                           xpath='vpcId',
@@ -4678,7 +4686,7 @@ class BaseEC2NodeDriver(NodeDriver):
 
         # Set our name if the Name key/value if available
         # If we don't get anything back then use the vpc_id
-        name = tags.get('Name', vpc_id)
+        name = name if name else tags.get('Name', vpc_id)
 
         cidr_block = findtext(element=element,
                               xpath='cidrBlock',
@@ -4740,7 +4748,7 @@ class BaseEC2NodeDriver(NodeDriver):
             fixxpath(xpath='subnetSet/item', namespace=NAMESPACE))
         ]
 
-    def _to_subnet(self, element):
+    def _to_subnet(self, element, name=None):
         # Get the subnet ID
         subnet_id = findtext(element=element,
                              xpath='subnetId',
@@ -4750,7 +4758,7 @@ class BaseEC2NodeDriver(NodeDriver):
         tags = self._get_resource_tags(element)
 
         # If we don't get anything back then use the subnet_id
-        name = tags.get('Name', subnet_id)
+        name = name if name else tags.get('Name', subnet_id)
 
         state = findtext(element=element,
                          xpath='state',
@@ -4934,7 +4942,7 @@ class BaseEC2NodeDriver(NodeDriver):
             fixxpath(xpath='routeTableSet/item', namespace=NAMESPACE))
         ]
 
-    def _to_route_table(self, element):
+    def _to_route_table(self, element, name=None):
         # route table id
         route_table_id = findtext(element=element,
                                   xpath='routeTableId',
@@ -4965,7 +4973,9 @@ class BaseEC2NodeDriver(NodeDriver):
                                                     xpath='gatewayId',
                                                     namespace=NAMESPACE))
 
-        return EC2RouteTable(route_table_id, routes, subnet_associations,
+        name = name if name else tags.get('Name', id)
+
+        return EC2RouteTable(route_table_id, name, routes, subnet_associations,
                              propagating_gateway_ids, extra=extra)
 
     def _to_routes(self, element, xpath):


Mime
View raw message