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 2014/02/09 21:35:32 UTC

[1/2] git commit: LIBCLOUD-514: Add create/delete tag support into the CloudStack driver. New tests and fixtures are also included.

Updated Branches:
  refs/heads/trunk 981611409 -> 91c6281db


LIBCLOUD-514: Add create/delete tag support into the CloudStack driver. New tests and fixtures are also included.

Closes #248.

Signed-off-by: Tomaz Muraus <to...@apache.org>


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

Branch: refs/heads/trunk
Commit: 7d1d1cf63122ddf503d3c8a5dd018488790060fc
Parents: 9816114
Author: Chris DeRamus <ch...@divvycloud.com>
Authored: Sat Feb 8 07:56:36 2014 -0500
Committer: Tomaz Muraus <to...@apache.org>
Committed: Sun Feb 9 21:29:29 2014 +0100

----------------------------------------------------------------------
 libcloud/compute/drivers/cloudstack.py          | 63 ++++++++++++++++++++
 .../fixtures/cloudstack/createTags_default.json |  1 +
 .../fixtures/cloudstack/deleteTags_default.json |  1 +
 .../queryAsyncJobResult_createtagsjob.json      |  1 +
 .../queryAsyncJobResult_deletetagsjob.json      |  1 +
 libcloud/test/compute/test_cloudstack.py        | 12 ++++
 6 files changed, 79 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/7d1d1cf6/libcloud/compute/drivers/cloudstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/cloudstack.py b/libcloud/compute/drivers/cloudstack.py
index 7bc2516..5d66e8d 100644
--- a/libcloud/compute/drivers/cloudstack.py
+++ b/libcloud/compute/drivers/cloudstack.py
@@ -1692,6 +1692,69 @@ class CloudStackNodeDriver(CloudStackDriverMixIn, NodeDriver):
 
         return limits
 
+    def ex_create_tags(self, resource_ids, resource_type, tags):
+        """
+        Create tags for a resource (Node/StorageVolume/etc).
+        A list of resource types can be found at http://goo.gl/6OKphH
+
+        :param resource_ids: Resource IDs to be tagged. The resource IDs must
+                             all be associated with the resource_type.
+                             For example, for virtual machines (UserVm) you
+                             can only specify a list of virtual machine IDs.
+        :type  resource_ids: ``list`` of resource IDs
+
+        :param resource_type: Resource type (eg: UserVm)
+        :type  resource_type: ``str``
+
+        :param tags: A dictionary or other mapping of strings to strings,
+                     associating tag names with tag values.
+        :type  tags: ``dict``
+
+        :rtype: ``bool``
+        """
+        params = {'resourcetype': resource_type,
+                  'resourceids': ','.join(resource_ids)}
+
+        for i, key in enumerate(tags):
+            params['tags[%d].key' % i] = key
+            params['tags[%d].value' % i] = tags[key]
+
+        self._async_request(command='createTags',
+                            params=params,
+                            method='GET')
+        return True
+
+    def ex_delete_tags(self, resource_ids, resource_type, tag_keys):
+        """
+        Delete tags from a resource.
+
+        :param resource_ids: Resource IDs to be tagged. The resource IDs must
+                             all be associated with the resource_type.
+                             For example, for virtual machines (UserVm) you
+                             can only specify a list of virtual machine IDs.
+        :type  resource_ids: ``list`` of resource IDs
+
+        :param resource_type: Resource type (eg: UserVm)
+        :type  resource_type: ``str``
+
+        :param tag_keys: A list of keys to delete. CloudStack only requires
+                         the keys from the key/value pair.
+        :type  tag_keys: ``list``
+
+        :rtype: ``bool``
+        """
+        params = {'resourcetype': resource_type,
+                  'resourceids': ','.join(resource_ids)}
+
+        for i, key in enumerate(tag_keys):
+            params['tags[%s].key' % i] = key
+
+        self._async_request(command='deleteTags',
+                            params=params,
+                            method='GET')
+
+        return True
+
     def _to_node(self, data, public_ips=None):
         """
         :param data: Node data object.

http://git-wip-us.apache.org/repos/asf/libcloud/blob/7d1d1cf6/libcloud/test/compute/fixtures/cloudstack/createTags_default.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/cloudstack/createTags_default.json b/libcloud/test/compute/fixtures/cloudstack/createTags_default.json
new file mode 100644
index 0000000..aeeb1e0
--- /dev/null
+++ b/libcloud/test/compute/fixtures/cloudstack/createTags_default.json
@@ -0,0 +1 @@
+{ "createtagsresponse" : {"id":"60338035-92fb-4d27-98d4-b60ad4b38b87","jobid":"createtagsjob"} }

http://git-wip-us.apache.org/repos/asf/libcloud/blob/7d1d1cf6/libcloud/test/compute/fixtures/cloudstack/deleteTags_default.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/cloudstack/deleteTags_default.json b/libcloud/test/compute/fixtures/cloudstack/deleteTags_default.json
new file mode 100644
index 0000000..e136a00
--- /dev/null
+++ b/libcloud/test/compute/fixtures/cloudstack/deleteTags_default.json
@@ -0,0 +1 @@
+{ "deletetagsresponse" : {"id":"60338035-92fb-4d27-98d4-b60ad4b38b87","jobid":"deletetagsjob"} }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/7d1d1cf6/libcloud/test/compute/fixtures/cloudstack/queryAsyncJobResult_createtagsjob.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/cloudstack/queryAsyncJobResult_createtagsjob.json b/libcloud/test/compute/fixtures/cloudstack/queryAsyncJobResult_createtagsjob.json
new file mode 100644
index 0000000..ab6a845
--- /dev/null
+++ b/libcloud/test/compute/fixtures/cloudstack/queryAsyncJobResult_createtagsjob.json
@@ -0,0 +1 @@
+{ "queryasyncjobresultresponse" : {"accountid":"dcfd4b83-2ae6-43d1-a2eb-af87066ecbc9","userid":"c3d3cb3c-0f13-429a-b900-5bacc346df32","cmd":"com.cloud.api.commands.CreateTagsCmd","jobstatus":1,"jobprocstatus":0,"jobresultcode":0,"jobresulttype":"object","jobresult":{"success":true},"created":"2014-02-07T20:10:40+0100","jobid":"2a7426a5-e25e-4400-900d-09bca3c0a039"} }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/7d1d1cf6/libcloud/test/compute/fixtures/cloudstack/queryAsyncJobResult_deletetagsjob.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/cloudstack/queryAsyncJobResult_deletetagsjob.json b/libcloud/test/compute/fixtures/cloudstack/queryAsyncJobResult_deletetagsjob.json
new file mode 100644
index 0000000..b16cb4d
--- /dev/null
+++ b/libcloud/test/compute/fixtures/cloudstack/queryAsyncJobResult_deletetagsjob.json
@@ -0,0 +1 @@
+{ "queryasyncjobresultresponse" : {"accountid":"dcfd4b83-2ae6-43d1-a2eb-af87066ecbc9","userid":"c3d3cb3c-0f13-429a-b900-5bacc346df32","cmd":"com.cloud.api.commands.DeleteTagsCmd","jobstatus":1,"jobprocstatus":0,"jobresultcode":0,"jobresulttype":"object","jobresult":{"success":true},"created":"2014-02-08T13:43:24+0100","jobid":"02425faf-4cf4-44c2-9241-cb8b1eabc957"} }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/7d1d1cf6/libcloud/test/compute/test_cloudstack.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_cloudstack.py b/libcloud/test/compute/test_cloudstack.py
index c54d423..fc73116 100644
--- a/libcloud/test/compute/test_cloudstack.py
+++ b/libcloud/test/compute/test_cloudstack.py
@@ -496,6 +496,18 @@ class CloudStackCommonTestCase(TestCaseMixin):
         self.assertEqual(limits['max_volumes'], 20)
         self.assertEqual(limits['max_snapshots'], 20)
 
+    def test_ex_create_tags(self):
+        node = self.driver.list_nodes()[0]
+        tags = {'Region': 'Canada'}
+        resp = self.driver.ex_create_tags([node.id], 'UserVm', tags)
+        self.assertTrue(resp)
+
+    def test_ex_delete_tags(self):
+        node = self.driver.list_nodes()[0]
+        tag_keys = ['Region']
+        resp = self.driver.ex_delete_tags([node.id], 'UserVm', tag_keys)
+        self.assertTrue(resp)
+
 
 class CloudStackTestCase(CloudStackCommonTestCase, unittest.TestCase):
     def test_driver_instantiation(self):


[2/2] git commit: Update CHANGES.

Posted by to...@apache.org.
Update CHANGES.


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

Branch: refs/heads/trunk
Commit: 91c6281dbf19d2e0ac5d44662b00cac227753e18
Parents: 7d1d1cf
Author: Tomaz Muraus <to...@apache.org>
Authored: Sun Feb 9 21:34:20 2014 +0100
Committer: Tomaz Muraus <to...@apache.org>
Committed: Sun Feb 9 21:34:20 2014 +0100

----------------------------------------------------------------------
 CHANGES.rst | 7 +++++++
 1 file changed, 7 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/91c6281d/CHANGES.rst
----------------------------------------------------------------------
diff --git a/CHANGES.rst b/CHANGES.rst
index c906f54..8430287 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -4,6 +4,9 @@ Changelog
 Changes with Apache Libcloud in development
 -------------------------------------------
 
+Compute
+~~~~~~~
+
 - Map "Stopped" node state in the CloudStack driver to NodeState.STOPPED
   instead of NodeState.TERMINATED, "Stopping" to NodeState.PENDING instead of
   NodeState.TERMINATED and "Expunging" to NodeState.PENDING instead of
@@ -11,6 +14,10 @@ Changes with Apache Libcloud in development
   (GITHUB-246)
   [Chris DeRamus, Tomaz Muraus]
 
+- Add ex_create_tags and ex_delete_tags method to the CloudStack driver.
+  (LIBCLOUD-514, GITHUB-248)
+  [Chris DeRamus]
+
 Changes with Apache Libcloud 0.14.1
 -----------------------------------