You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by se...@apache.org on 2015/06/02 06:36:04 UTC

[1/2] libcloud git commit: Added CloudStackNodeDriver.ex_get_node with test

Repository: libcloud
Updated Branches:
  refs/heads/trunk 601526bee -> 13fe5a557


Added CloudStackNodeDriver.ex_get_node with test

Shortcut function for get only one node (like in GCE or Joyent)

Signed-off-by: Sebastien Goasguen <ru...@gmail.com>


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

Branch: refs/heads/trunk
Commit: e6fa98b7d70a43be2ee1dfed55021903b1e3b43a
Parents: 601526b
Author: ZuluPro <mo...@hotmail.com>
Authored: Wed May 27 12:50:16 2015 -0400
Committer: Sebastien Goasguen <ru...@gmail.com>
Committed: Tue Jun 2 06:32:22 2015 +0200

----------------------------------------------------------------------
 libcloud/compute/drivers/cloudstack.py   | 74 +++++++++++++++++++++++++++
 libcloud/test/compute/test_cloudstack.py | 10 ++++
 2 files changed, 84 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/e6fa98b7/libcloud/compute/drivers/cloudstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/cloudstack.py b/libcloud/compute/drivers/cloudstack.py
index 9228760..f768783 100644
--- a/libcloud/compute/drivers/cloudstack.py
+++ b/libcloud/compute/drivers/cloudstack.py
@@ -1409,6 +1409,80 @@ class CloudStackNodeDriver(CloudStackDriverMixIn, NodeDriver):
 
         return nodes
 
+    def ex_get_node(self, node_id, project=None):
+        """
+        Return a Node object based on its ID.
+
+        :param  node_id: The id of the node
+        :type   node_id: ``str``
+
+        :keyword    project: Limit node returned to those configured under
+                             the defined project.
+        :type       project: :class:`.CloudStackProject`
+
+        :rtype: :class:`CloudStackNode`
+        """
+        list_nodes_args = {'id': node_id}
+        list_ips_args = {}
+        if project:
+            list_nodes_args['projectid'] = project.id
+            list_ips_args['projectid'] = project.id
+        vms = self._sync_request('listVirtualMachines', params=list_nodes_args)
+        if not vms:
+            raise Exception("Node '%s' not found" % node_id)
+        vm = vms['virtualmachine'][0]
+        addrs = self._sync_request('listPublicIpAddresses',
+                                   params=list_ips_args)
+
+        public_ips = {}
+        for addr in addrs.get('publicipaddress', []):
+            if 'virtualmachineid' not in addr:
+                continue
+            public_ips[addr['ipaddress']] = addr['id']
+
+        node = self._to_node(data=vm, public_ips=public_ips.keys())
+
+        addresses = public_ips.items()
+        addresses = [CloudStackAddress(node, v, k) for k, v in addresses]
+        node.extra['ip_addresses'] = addresses
+
+        rules = []
+        list_fw_rules = {'virtualmachineid': node_id}
+        for addr in addresses:
+            result = self._sync_request('listIpForwardingRules',
+                                        params=list_fw_rules)
+            for r in result.get('ipforwardingrule', []):
+                if str(r['virtualmachineid']) == node.id:
+                    rule = CloudStackIPForwardingRule(node, r['id'],
+                                                      addr,
+                                                      r['protocol']
+                                                      .upper(),
+                                                      r['startport'],
+                                                      r['endport'])
+                    rules.append(rule)
+        node.extra['ip_forwarding_rules'] = rules
+
+        rules = []
+        public_ips = self.ex_list_public_ips()
+        result = self._sync_request('listPortForwardingRules',
+                                    params=list_fw_rules)
+        for r in result.get('portforwardingrule', []):
+            if str(r['virtualmachineid']) == node.id:
+                addr = [a for a in public_ips if
+                        a.address == r['ipaddress']]
+                rule = CloudStackPortForwardingRule(node, r['id'],
+                                                    addr[0],
+                                                    r['protocol'].upper(),
+                                                    r['publicport'],
+                                                    r['privateport'],
+                                                    r['publicendport'],
+                                                    r['privateendport'])
+                if not addr[0].address in node.public_ips:
+                    node.public_ips.append(addr[0].address)
+                rules.append(rule)
+        node.extra['port_forwarding_rules'] = rules
+        return node
+
     def list_sizes(self, location=None):
         """
         :rtype ``list`` of :class:`NodeSize`

http://git-wip-us.apache.org/repos/asf/libcloud/blob/e6fa98b7/libcloud/test/compute/test_cloudstack.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_cloudstack.py b/libcloud/test/compute/test_cloudstack.py
index 384f706..a9d0b55 100644
--- a/libcloud/test/compute/test_cloudstack.py
+++ b/libcloud/test/compute/test_cloudstack.py
@@ -580,6 +580,16 @@ class CloudStackCommonTestCase(TestCaseMixin):
         self.assertEqual([], nodes[0].extra['security_group'])
         self.assertEqual(None, nodes[0].extra['key_name'])
 
+    def test_ex_get_node(self):
+        node = self.driver.ex_get_node(2600)
+        self.assertEqual('test', node.name)
+        self.assertEqual('2600', node.id)
+        self.assertEqual([], node.extra['security_group'])
+        self.assertEqual(None, node.extra['key_name'])
+
+    def test_ex_get_node_doesnt_exist(self):
+        self.assertRaises(Exception, self.driver.ex_get_node(26), node_id=26)
+
     def test_list_locations(self):
         location = self.driver.list_locations()[0]
         self.assertEqual('1', location.id)


[2/2] libcloud git commit: Added CloudStackNodeDriver.ex_get_volume and test

Posted by se...@apache.org.
Added CloudStackNodeDriver.ex_get_volume and test

Shortcut for get only one volume
(Little py3 fix for CloudStackNodeDriver.ex_get_node)

Signed-off-by: Sebastien Goasguen <ru...@gmail.com>

This closes #532


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

Branch: refs/heads/trunk
Commit: 13fe5a5574dcdeb8bfe39f0ac9f2b0e9a2c71fdb
Parents: e6fa98b
Author: ZuluPro <mo...@hotmail.com>
Authored: Wed May 27 13:15:02 2015 -0400
Committer: Sebastien Goasguen <ru...@gmail.com>
Committed: Tue Jun 2 06:35:04 2015 +0200

----------------------------------------------------------------------
 CHANGES.rst                              |  4 ++++
 libcloud/compute/drivers/cloudstack.py   | 33 ++++++++++++++++++++++++++-
 libcloud/test/compute/test_cloudstack.py |  4 ++++
 3 files changed, 40 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/13fe5a55/CHANGES.rst
----------------------------------------------------------------------
diff --git a/CHANGES.rst b/CHANGES.rst
index c66d27b..b8bd91f 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -199,6 +199,10 @@ Compute
   (GITHUB-528)
   [Michael Bennett]
 
+- Add ``ex_get_node`` and ``ex_get_volume`` methods to CloudStack driver
+  (GITHUB-532)
+  [ZuluPro]
+
 Storage
 ~~~~~~~
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/13fe5a55/libcloud/compute/drivers/cloudstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/cloudstack.py b/libcloud/compute/drivers/cloudstack.py
index f768783..b226c55 100644
--- a/libcloud/compute/drivers/cloudstack.py
+++ b/libcloud/compute/drivers/cloudstack.py
@@ -1440,7 +1440,7 @@ class CloudStackNodeDriver(CloudStackDriverMixIn, NodeDriver):
                 continue
             public_ips[addr['ipaddress']] = addr['id']
 
-        node = self._to_node(data=vm, public_ips=public_ips.keys())
+        node = self._to_node(data=vm, public_ips=list(public_ips.keys()))
 
         addresses = public_ips.items()
         addresses = [CloudStackAddress(node, v, k) for k, v in addresses]
@@ -2173,6 +2173,37 @@ class CloudStackNodeDriver(CloudStackDriverMixIn, NodeDriver):
                                               extra=extra))
         return list_volumes
 
+    def ex_get_volume(self, volume_id, project=None):
+        """
+        Return a StorageVolume object based on its ID.
+
+        :param  volume_id: The id of the volume
+        :type   volume_id: ``str``
+
+        :keyword    project: Limit volume returned to those configured under
+                             the defined project.
+        :type       project: :class:`.CloudStackProject`
+
+        :rtype: :class:`CloudStackNode`
+        """
+        args = {'id': volume_id}
+        if project:
+            args['projectid'] = project.id
+        volumes = self._sync_request(command='listVolumes', params=args)
+        if not volumes:
+            raise Exception("Volume '%s' not found" % volume_id)
+        vol = volumes['volume'][0]
+
+        extra_map = RESOURCE_EXTRA_ATTRIBUTES_MAP['volume']
+        extra = self._get_extra_dict(vol, extra_map)
+
+        if 'tags' in vol:
+            extra['tags'] = self._get_resource_tags(vol['tags'])
+
+        volume = StorageVolume(id=vol['id'], name=vol['name'],
+                               size=vol['size'], driver=self, extra=extra)
+        return volume
+
     def list_key_pairs(self, **kwargs):
         """
         List registered key pairs.

http://git-wip-us.apache.org/repos/asf/libcloud/blob/13fe5a55/libcloud/test/compute/test_cloudstack.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_cloudstack.py b/libcloud/test/compute/test_cloudstack.py
index a9d0b55..ed83d70 100644
--- a/libcloud/test/compute/test_cloudstack.py
+++ b/libcloud/test/compute/test_cloudstack.py
@@ -572,6 +572,10 @@ class CloudStackCommonTestCase(TestCaseMixin):
         self.assertEqual(1, len(volumes))
         self.assertEqual('ROOT-69942', volumes[0].name)
 
+    def test_ex_get_volume(self):
+        volume = self.driver.ex_get_volume(2600)
+        self.assertEqual('ROOT-69942', volume.name)
+
     def test_list_nodes(self):
         nodes = self.driver.list_nodes()
         self.assertEqual(2, len(nodes))