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:05 UTC

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

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))