libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r1476056 - in /libcloud/trunk: CHANGES libcloud/compute/drivers/vcloud.py libcloud/test/compute/test_vcloud.py
Date Fri, 26 Apr 2013 06:09:44 GMT
Author: tomaz
Date: Fri Apr 26 06:09:43 2013
New Revision: 1476056

URL: http://svn.apache.org/r1476056
Log:
Add ex_set_metadata_entry and ex_get_metadata method to the VCloud driver.

Contributed by Michel Samia, part of LIBCLOUD-318.

Modified:
    libcloud/trunk/CHANGES
    libcloud/trunk/libcloud/compute/drivers/vcloud.py
    libcloud/trunk/libcloud/test/compute/test_vcloud.py

Modified: libcloud/trunk/CHANGES
URL: http://svn.apache.org/viewvc/libcloud/trunk/CHANGES?rev=1476056&r1=1476055&r2=1476056&view=diff
==============================================================================
--- libcloud/trunk/CHANGES (original)
+++ libcloud/trunk/CHANGES Fri Apr 26 06:09:43 2013
@@ -14,6 +14,10 @@ Changes with Apache Libcloud in deveplom
       (LIBCLOUD-321)
       [Arfrever Frehtes Taifersar Arahesis]
 
+    - Add ex_set_metadata_entry and ex_get_metadata method to the VCloud driver.
+      (LIBCLOUD-318)
+      [Michel Samia]
+
  *) Load Balancer
 
     - Add ex_list_current_usage method to the Rackspace driver.

Modified: libcloud/trunk/libcloud/compute/drivers/vcloud.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/compute/drivers/vcloud.py?rev=1476056&r1=1476055&r2=1476056&view=diff
==============================================================================
--- libcloud/trunk/libcloud/compute/drivers/vcloud.py (original)
+++ libcloud/trunk/libcloud/compute/drivers/vcloud.py Fri Apr 26 06:09:43 2013
@@ -1191,6 +1191,59 @@ class VCloud_1_5_NodeDriver(VCloudNodeDr
             },
             method='POST')
 
+    def ex_get_metadata(self, node):
+        """
+        @param  node: node
+        @type   node: L{Node}
+
+        @return: dictionary mapping metadata keys to metadata values
+        @rtype: dictionary mapping C{str} to C{str}
+        """
+        res = self.connection.request('%s/metadata' % (get_url_path(node.id)))
+        metadata_entries = res.object.findall(fixxpath(res.object, 'MetadataEntry'))
+        res_dict = {}
+
+        for entry in metadata_entries:
+            key = entry.findtext(fixxpath(res.object, 'Key'))
+            value = entry.findtext(fixxpath(res.object, 'Value'))
+            res_dict[key] = value
+
+        return res_dict
+
+    def ex_set_metadata_entry(self, node, key, value):
+        """
+        @param  node: node
+        @type   node: L{Node}
+
+        @param key: metadata key to be set
+        @type key: C{str}
+
+        @param value: metadata value to be set
+        @type value: C{str}
+
+        @rtype: C{None}
+        """
+        metadata_elem = ET.Element(
+            'Metadata',
+            {'xmlns': "http://www.vmware.com/vcloud/v1.5",
+             'xmlns:xsi': "http://www.w3.org/2001/XMLSchema-instance"}
+        )
+        entry = ET.SubElement(metadata_elem, 'MetadataEntry')
+        key_elem = ET.SubElement(entry, 'Key')
+        key_elem.text = key
+        value_elem = ET.SubElement(entry, 'Value')
+        value_elem.text = value
+
+        # send it back to the server
+        res = self.connection.request(
+            '%s/metadata' % get_url_path(node.id),
+            data=ET.tostring(metadata_elem),
+            headers={
+                'Content-Type': 'application/vnd.vmware.vcloud.metadata+xml'
+            },
+            method='POST')
+        self._wait_for_task_completion(res.object.get('href'))
+
     def ex_query(self, type, filter=None, page=1, page_size=100, sort_asc=None,
                  sort_desc=None):
         """

Modified: libcloud/trunk/libcloud/test/compute/test_vcloud.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/test/compute/test_vcloud.py?rev=1476056&r1=1476055&r2=1476056&view=diff
==============================================================================
--- libcloud/trunk/libcloud/test/compute/test_vcloud.py (original)
+++ libcloud/trunk/libcloud/test/compute/test_vcloud.py Fri Apr 26 06:09:43 2013
@@ -271,6 +271,15 @@ class VCloud_1_5_Tests(unittest.TestCase
             access_level = ControlAccess.AccessLevel.FULL_CONTROL)])
         self.driver.ex_set_control_access(node, control_access)
 
+    def test_ex_get_metadata(self):
+        node = Node('https://vm-vcloud/api/vApp/vapp-8c57a5b6-e61b-48ca-8a78-3b70ee65ef6b',
'testNode', NodeState.RUNNING, [], [], self.driver)
+        metadata = self.driver.ex_get_metadata(node)
+        self.assertEqual(metadata, {'owners':'msamia@netsuite.com'})
+
+    def test_ex_set_metadata_entry(self):
+        node = Node('https://vm-vcloud/api/vApp/vapp-8c57a5b6-e61b-48ca-8a78-3b70ee65ef6b',
'testNode', NodeState.RUNNING, [], [], self.driver)
+        self.driver.ex_set_metadata_entry(node, 'foo', 'bar')
+
 
 class VCloud_5_1_Tests(unittest.TestCase, TestCaseMixin):
 
@@ -561,6 +570,14 @@ class VCloud_1_5_MockHttp(MockHttp, unit
             raise AssertionError('Unexpected query type')
         return httplib.OK, body, headers, httplib.responses[httplib.OK]
 
+    def _api_vApp_vapp_8c57a5b6_e61b_48ca_8a78_3b70ee65ef6b_metadata(self, method, url, body,
headers):
+        if method == 'POST':
+            body = self.fixtures.load('api_vapp_post_metadata.xml')
+            return httplib.ACCEPTED, body, headers, httplib.responses[httplib.ACCEPTED]
+        else:
+            body = self.fixtures.load('api_vapp_get_metadata.xml')
+            return httplib.OK, body, headers, httplib.responses[httplib.OK]
+
     def _api_vApp_vapp_8c57a5b6_e61b_48ca_8a78_3b70ee65ef6b_controlAccess(self, method, url,
body, headers):
         body = self.fixtures.load('api_vApp_vapp_8c57a5b6_e61b_48ca_8a78_3b70ee65ef6a_controlAccess.xml')
         return httplib.OK, body, headers, httplib.responses[httplib.OK]



Mime
View raw message