You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2013/11/27 19:19:48 UTC

[1/3] git commit: Refactor CloudStack driver and consolidate repeated code inside the _to_node method.

Updated Branches:
  refs/heads/trunk 345856f20 -> 5d310f196


Refactor CloudStack driver and consolidate repeated code inside the _to_node
method.

Also fix an issue with public_ips map which was not properly populated because
dictionary key was a string but a code incorrectly passed int to it.


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

Branch: refs/heads/trunk
Commit: af0ef296f4675515ec09372cce5685e7f590e426
Parents: 345856f
Author: Tomaz Muraus <to...@apache.org>
Authored: Wed Nov 27 17:51:46 2013 +0100
Committer: Tomaz Muraus <to...@apache.org>
Committed: Wed Nov 27 17:55:17 2013 +0100

----------------------------------------------------------------------
 libcloud/compute/drivers/cloudstack.py | 130 +++++++++++++---------------
 1 file changed, 59 insertions(+), 71 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/af0ef296/libcloud/compute/drivers/cloudstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/cloudstack.py b/libcloud/compute/drivers/cloudstack.py
index 1b0338c..f35f46d 100644
--- a/libcloud/compute/drivers/cloudstack.py
+++ b/libcloud/compute/drivers/cloudstack.py
@@ -285,9 +285,13 @@ class CloudStackNodeDriver(CloudStackDriverMixIn, NodeDriver):
         :rtype ``list`` of :class:`NodeLocation`
         """
         locs = self._sync_request('listZones')
+
         locations = []
         for loc in locs['zone']:
-            locations.append(NodeLocation(loc['id'], loc['name'], 'AU', self))
+            location = NodeLocation(str(loc['id']), loc['name'], 'Unknown',
+                                    self)
+            locations.append(location)
+
         return locations
 
     def list_nodes(self):
@@ -310,42 +314,9 @@ class CloudStackNodeDriver(CloudStackDriverMixIn, NodeDriver):
         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()
+            public_ips = public_ips_map.get(str(vm['id']), {}).keys()
             public_ips = list(public_ips)
-            public_ips.extend([ip for ip in private_ips
-                              if not is_private_subnet(ip)])
-
-            keypair, password, securitygroup = None, None, None
-            if 'keypair' in vm.keys():
-                keypair = vm['keypair']
-            if 'password' in vm.keys():
-                password = vm['password']
-            if 'securitygroup' in vm.keys():
-                securitygroup = [sg['name'] for sg in vm['securitygroup']]
-
-            node = CloudStackNode(
-                id=vm['id'],
-                name=vm.get('displayname', None),
-                state=state,
-                public_ips=public_ips,
-                private_ips=private_ips,
-                driver=self,
-                extra={'zoneid': vm['zoneid'],
-                       'password': password,
-                       'keyname': keypair,
-                       'securitygroup': securitygroup,
-                       'created': vm['created']
-                       }
-            )
+            node = self._to_node(data=vm, public_ips=public_ips)
 
             addresses = public_ips_map.get(vm['id'], {}).items()
             addresses = [CloudStackAddress(node, v, k) for k, v in addresses]
@@ -424,43 +395,11 @@ class CloudStackNodeDriver(CloudStackDriverMixIn, NodeDriver):
 
         server_params = self._create_args_to_params(None, **kwargs)
 
-        node = self._async_request(command='deployVirtualMachine',
+        data = self._async_request(command='deployVirtualMachine',
                                    params=server_params,
                                    method='GET')['virtualmachine']
-        public_ips = []
-        private_ips = []
-        for nic in node['nic']:
-            if is_private_subnet(nic['ipaddress']):
-                private_ips.append(nic['ipaddress'])
-            else:
-                public_ips.append(nic['ipaddress'])
-
-        keypair, password, securitygroup = None, None, None
-        if 'keypair' in node.keys():
-            keypair = node['keypair']
-        if 'password' in node.keys():
-            password = node['password']
-        if 'securitygroup' in node.keys():
-            securitygroup = [sg['name'] for sg in node['securitygroup']]
-
-        return CloudStackNode(
-            id=node['id'],
-            name=node['displayname'],
-            state=self.NODE_STATE_MAP[node['state']],
-            public_ips=public_ips,
-            private_ips=private_ips,
-            driver=self,
-            extra={'zoneid': server_params['zoneid'],
-                   'ip_addresses': [],
-                   'ip_forwarding_rules': [],
-                   'port_forwarding_rules': [],
-                   'password': password,
-                   'keyname': keypair,
-                   'securitygroup': securitygroup,
-                   'created': node['created']
-                   }
-
-        )
+        node = self._to_node(data=data)
+        return node
 
     def _create_args_to_params(self, node, **kwargs):
         server_params = {
@@ -1317,3 +1256,52 @@ class CloudStackNodeDriver(CloudStackDriverMixIn, NodeDriver):
                                   url=url,
                                   zoneid=location.id,
                                   params=params)
+
+    def _to_node(self, data, public_ips=None):
+        """
+        :param data: Node data object.
+        :type data: ``dict``
+
+        :param public_ips: A list of additional IP addresses belonging to
+                           this node. (optional)
+        :type public_ips: ``list`` or ``None``
+        """
+        id = data['id']
+        name = data['displayname']
+        state = self.NODE_STATE_MAP[data['state']]
+
+        public_ips = public_ips if public_ips else []
+        private_ips = []
+
+        for nic in data['nic']:
+            if is_private_subnet(nic['ipaddress']):
+                private_ips.append(nic['ipaddress'])
+            else:
+                public_ips.append(nic['ipaddress'])
+
+        zone_id = str(data['zoneid'])
+        password = data.get('password', None)
+        keypair = data.get('keypair', None)
+
+        security_groups = data.get('securitygroup', [])
+
+        if security_groups:
+            security_groups = [sg['name'] for sg in security_groups]
+
+        created = data.get('created', False)
+
+        extra = {
+            'zoneid': zone_id,
+            'ip_addresses': [],
+            'ip_forwarding_rules': [],
+            'port_forwarding_rules': [],
+            'password': password,
+            'keyname': keypair,
+            'securitygroup': security_groups,
+            'created': created
+        }
+
+        node = CloudStackNode(id=id, name=name, state=state,
+                              public_ips=public_ips, private_ips=private_ips,
+                              driver=self, extra=extra)
+        return node


[3/3] git commit: Update invalid docstring.

Posted by to...@apache.org.
Update invalid docstring.


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

Branch: refs/heads/trunk
Commit: 5d310f196b6c2548dafe8d799597900763600d79
Parents: b86e6a7
Author: Tomaz Muraus <to...@apache.org>
Authored: Wed Nov 27 18:10:27 2013 +0100
Committer: Tomaz Muraus <to...@apache.org>
Committed: Wed Nov 27 18:10:27 2013 +0100

----------------------------------------------------------------------
 libcloud/compute/drivers/cloudstack.py | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/5d310f19/libcloud/compute/drivers/cloudstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/cloudstack.py b/libcloud/compute/drivers/cloudstack.py
index ea7c0e1..27498fd 100644
--- a/libcloud/compute/drivers/cloudstack.py
+++ b/libcloud/compute/drivers/cloudstack.py
@@ -377,20 +377,21 @@ class CloudStackNodeDriver(CloudStackDriverMixIn, NodeDriver):
 
         @inherits: :class:`NodeDriver.create_node`
 
+        :keyword    networks: Optional list of networks to launch the server
+                              into.
+        :type       networks: ``list`` of :class:`.CloudStackNetwork`
+
         :keyword    ex_keyname:  Name of existing keypair
         :type       ex_keyname:  ``str``
 
         :keyword    ex_userdata: String containing user data
         :type       ex_userdata: ``str``
 
-        :keyword    networks: The server is launched into a set of Networks.
-        :type       networks: :class:`CloudStackNetwork`
-
         :keyword    ex_security_groups: List of security groups to assign to
                                         the node
         :type       ex_security_groups: ``list`` of ``str``
 
-        :rtype:     :class:`CloudStackNode`
+        :rtype:     :class:`.CloudStackNode`
         """
 
         server_params = self._create_args_to_params(None, **kwargs)


[2/3] git commit: Make the node name detection in CloudStack driver more robust. Some newer versions use 'name' instead of 'displayname' attribute.

Posted by to...@apache.org.
Make the node name detection in CloudStack driver more robust. Some newer
versions use 'name' instead of 'displayname' attribute.


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

Branch: refs/heads/trunk
Commit: b86e6a7ccf6fb5c3a08314434c3992db6c736468
Parents: af0ef29
Author: Tomaz Muraus <to...@apache.org>
Authored: Wed Nov 27 17:58:58 2013 +0100
Committer: Tomaz Muraus <to...@apache.org>
Committed: Wed Nov 27 17:58:58 2013 +0100

----------------------------------------------------------------------
 libcloud/compute/drivers/cloudstack.py | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/b86e6a7c/libcloud/compute/drivers/cloudstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/cloudstack.py b/libcloud/compute/drivers/cloudstack.py
index f35f46d..ea7c0e1 100644
--- a/libcloud/compute/drivers/cloudstack.py
+++ b/libcloud/compute/drivers/cloudstack.py
@@ -1267,7 +1267,14 @@ class CloudStackNodeDriver(CloudStackDriverMixIn, NodeDriver):
         :type public_ips: ``list`` or ``None``
         """
         id = data['id']
-        name = data['displayname']
+
+        if 'name' in data:
+            name = data['name']
+        elif 'displayname' in data:
+            name = data['displayname']
+        else:
+            name = None
+
         state = self.NODE_STATE_MAP[data['state']]
 
         public_ips = public_ips if public_ips else []