libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From je...@apache.org
Subject svn commit: r1056498 - in /incubator/libcloud/trunk: CHANGES libcloud/drivers/ec2.py test/test_ec2.py
Date Fri, 07 Jan 2011 20:42:29 GMT
Author: jerry
Date: Fri Jan  7 20:42:28 2011
New Revision: 1056498

URL: http://svn.apache.org/viewvc?rev=1056498&view=rev
Log:
Make create_node backward compatible and don't throw an exception if a
NodeLocation object passed to the create_node method doesn't have
availability_zone attribute.

Submitted By: Tomaž Muraus <tomaz@cloudkick.com>

Modified:
    incubator/libcloud/trunk/CHANGES
    incubator/libcloud/trunk/libcloud/drivers/ec2.py
    incubator/libcloud/trunk/test/test_ec2.py

Modified: incubator/libcloud/trunk/CHANGES
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/CHANGES?rev=1056498&r1=1056497&r2=1056498&view=diff
==============================================================================
--- incubator/libcloud/trunk/CHANGES (original)
+++ incubator/libcloud/trunk/CHANGES Fri Jan  7 20:42:28 2011
@@ -1,6 +1,10 @@
                                                         -*- coding: utf-8 -*-
 
-Changes with Apache Libcloud 0.4.1 [In Development]
+Changes with Apache Libcloud 0.4.2 [In Development]
+
+    *) Fix EC2 create_node to become backward compatible for
+       NodeLocation.
+       [Tomaž Muraus]
 
     *) Update code for compatibility with CPython 2.5
        [Jerry Chen]

Modified: incubator/libcloud/trunk/libcloud/drivers/ec2.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/drivers/ec2.py?rev=1056498&r1=1056497&r2=1056498&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/drivers/ec2.py (original)
+++ incubator/libcloud/trunk/libcloud/drivers/ec2.py Fri Jan  7 20:42:28 2011
@@ -615,11 +615,13 @@ class EC2NodeDriver(NodeDriver):
                 params['SecurityGroup.%d' % (sig+1,)]  = kwargs['ex_securitygroup'][sig]
 
         if 'location' in kwargs:
-            availability_zone = kwargs['location'].availability_zone
-            if availability_zone.region_name != self.region_name:
-                raise AttributeError('Invalid availability zone: %s'
-                                     % (availability_zone.name))
-            params['Placement.AvailabilityZone'] = availability_zone.name
+            availability_zone = getattr(kwargs['location'], 'availability_zone',
+                                        None)
+            if availability_zone:
+                if availability_zone.region_name != self.region_name:
+                    raise AttributeError('Invalid availability zone: %s'
+                                         % (availability_zone.name))
+                params['Placement.AvailabilityZone'] = availability_zone.name
 
         if 'ex_keyname' in kwargs:
             params['KeyName'] = kwargs['ex_keyname']

Modified: incubator/libcloud/trunk/test/test_ec2.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/test/test_ec2.py?rev=1056498&r1=1056497&r2=1056498&view=diff
==============================================================================
--- incubator/libcloud/trunk/test/test_ec2.py (original)
+++ incubator/libcloud/trunk/test/test_ec2.py Fri Jan  7 20:42:28 2011
@@ -16,7 +16,7 @@ import sys
 import unittest
 
 from libcloud.drivers.ec2 import EC2NodeDriver, EC2APSENodeDriver, IdempotentParamError
-from libcloud.base import Node, NodeImage, NodeSize
+from libcloud.base import Node, NodeImage, NodeSize, NodeLocation
 
 from test import MockHttp, TestCaseMixin
 from test.file_fixtures import FileFixtures
@@ -72,6 +72,19 @@ class EC2Tests(unittest.TestCase, TestCa
             idem_error = e
         self.assertTrue(idem_error is not None)
 
+    def test_create_node_no_availability_zone(self):
+        image = NodeImage(id='ami-be3adfd7',
+                          name='ec2-public-images/fedora-8-i386-base-v1.04.manifest.xml',
+                          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)
+        location = NodeLocation(0, 'Amazon US N. Virginia', 'US', self.driver)
+        self.assertEqual(node.id, 'i-2ba64342')
+        node = self.driver.create_node(name='foo', image=image, size=size,
+                                       location=location)
+        self.assertEqual(node.id, 'i-2ba64342')
+
     def test_list_nodes(self):
         node = self.driver.list_nodes()[0]
         self.assertEqual(node.id, 'i-4382922a')



Mime
View raw message