libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r1485883 - in /libcloud/trunk: CHANGES libcloud/compute/drivers/cloudstack.py libcloud/test/compute/test_cloudstack.py
Date Thu, 23 May 2013 22:28:31 GMT
Author: tomaz
Date: Thu May 23 22:28:30 2013
New Revision: 1485883

URL: http://svn.apache.org/r1485883
Log:
Populate private_ips attribute in the CloudStack drive when returning
a Node object from the create_node method.

Also add a basic test case for create_node.

Part of LIBCLOUD-329.

Modified:
    libcloud/trunk/CHANGES
    libcloud/trunk/libcloud/compute/drivers/cloudstack.py
    libcloud/trunk/libcloud/test/compute/test_cloudstack.py

Modified: libcloud/trunk/CHANGES
URL: http://svn.apache.org/viewvc/libcloud/trunk/CHANGES?rev=1485883&r1=1485882&r2=1485883&view=diff
==============================================================================
--- libcloud/trunk/CHANGES (original)
+++ libcloud/trunk/CHANGES Thu May 23 22:28:30 2013
@@ -54,6 +54,10 @@ Changes with Apache Libcloud in deveplom
       return value. (LIBCLOUD-326)
       [Andre Merzky, Tomaz Muraus]
 
+    - Populate private_ips attribute in the CloudStack drive when returning
+      a Node object from the create_node method. (LIBCLOUD-329)
+      [Sebastien Goasguen, Tomaz Muraus]
+
  *) Storage
 
     - Fix an issue with double encoding the container name in the CloudFiles

Modified: libcloud/trunk/libcloud/compute/drivers/cloudstack.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/compute/drivers/cloudstack.py?rev=1485883&r1=1485882&r2=1485883&view=diff
==============================================================================
--- libcloud/trunk/libcloud/compute/drivers/cloudstack.py (original)
+++ libcloud/trunk/libcloud/compute/drivers/cloudstack.py Thu May 23 22:28:30 2013
@@ -170,35 +170,40 @@ class CloudStackNodeDriver(CloudStackDri
         vms = self._sync_request('listVirtualMachines')
         addrs = self._sync_request('listPublicIpAddresses')
 
-        public_ips = {}
+        public_ips_map = {}
         for addr in addrs.get('publicipaddress', []):
             if 'virtualmachineid' not in addr:
                 continue
             vm_id = addr['virtualmachineid']
-            if vm_id not in public_ips:
-                public_ips[vm_id] = {}
-            public_ips[vm_id][addr['ipaddress']] = addr['id']
+            if vm_id not in public_ips_map:
+                public_ips_map[vm_id] = {}
+            public_ips_map[vm_id][addr['ipaddress']] = addr['id']
 
         nodes = []
 
         for vm in vms.get('virtualmachine', []):
+            state = self.NODE_STATE_MAP[vm['state']]
+
+            public_ips = []
             private_ips = []
 
             for nic in vm['nic']:
                 if 'ipaddress' in nic:
                     private_ips.append(nic['ipaddress'])
 
+            public_ips = public_ips_map.get(vm['id'], {}).keys()
+
             node = CloudStackNode(
                 id=vm['id'],
                 name=vm.get('displayname', None),
-                state=self.NODE_STATE_MAP[vm['state']],
-                public_ips=public_ips.get(vm['id'], {}).keys(),
+                state=state,
+                public_ips=public_ips,
                 private_ips=private_ips,
                 driver=self,
                 extra={'zoneid': vm['zoneid'], }
             )
 
-            addrs = public_ips.get(vm['id'], {}).items()
+            addrs = public_ips_map.get(vm['id'], {}).items()
             addrs = [CloudStackAddress(node, v, k) for k, v in addrs]
             node.extra['ip_addresses'] = addrs
 
@@ -244,13 +249,17 @@ class CloudStackNodeDriver(CloudStackDri
         )
 
         node = result['virtualmachine']
+        state = self.NODE_STATE_MAP[node['state']]
+
+        public_ips = []
+        private_ips = [nic['ipaddress'] for nic in node['nic']]
 
         return Node(
             id=node['id'],
             name=node['displayname'],
-            state=self.NODE_STATE_MAP[node['state']],
-            public_ips=[],
-            private_ips=[],
+            state=state,
+            public_ips=public_ips,
+            private_ips=private_ips,
             driver=self,
             extra={
                 'zoneid': location.id,

Modified: libcloud/trunk/libcloud/test/compute/test_cloudstack.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/test/compute/test_cloudstack.py?rev=1485883&r1=1485882&r2=1485883&view=diff
==============================================================================
--- libcloud/trunk/libcloud/test/compute/test_cloudstack.py (original)
+++ libcloud/trunk/libcloud/test/compute/test_cloudstack.py Thu May 23 22:28:30 2013
@@ -58,6 +58,20 @@ class CloudStackNodeDriverTest(unittest.
             return
         self.assertTrue(False)
 
+    def test_create_node_default_location_success(self):
+        size = self.driver.list_sizes()[0]
+        image = self.driver.list_images()[0]
+        default_location = self.driver.list_locations()[0]
+
+        node = self.driver.create_node(name='fred',
+                                       image=image,
+                                       size=size)
+
+        self.assertEqual(node.name, 'fred')
+        self.assertEqual(node.public_ips, [])
+        self.assertEqual(node.private_ips, ['1.1.1.2'])
+        self.assertEqual(node.extra['zoneid'], default_location.id)
+
     def test_list_images_no_images_available(self):
         CloudStackMockHttp.fixture_tag = 'notemplates'
 



Mime
View raw message