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/04/26 08:58:18 UTC
svn commit: r1476076 - in /libcloud/branches/0.12.x: ./
libcloud/compute/drivers/ libcloud/test/compute/
libcloud/test/compute/fixtures/vcloud_1_5/
Author: tomaz
Date: Fri Apr 26 06:58:17 2013
New Revision: 1476076
URL: http://svn.apache.org/r1476076
Log:
Backport commit from trunk.
Added:
libcloud/branches/0.12.x/libcloud/test/compute/fixtures/vcloud_1_5/api_vapp_get_metadata.xml
- copied unchanged from r1476072, libcloud/trunk/libcloud/test/compute/fixtures/vcloud_1_5/api_vapp_get_metadata.xml
libcloud/branches/0.12.x/libcloud/test/compute/fixtures/vcloud_1_5/api_vapp_post_metadata.xml
- copied unchanged from r1476072, libcloud/trunk/libcloud/test/compute/fixtures/vcloud_1_5/api_vapp_post_metadata.xml
Modified:
libcloud/branches/0.12.x/ (props changed)
libcloud/branches/0.12.x/CHANGES
libcloud/branches/0.12.x/libcloud/compute/drivers/vcloud.py
libcloud/branches/0.12.x/libcloud/test/compute/test_vcloud.py
Propchange: libcloud/branches/0.12.x/
------------------------------------------------------------------------------
Merged /libcloud/trunk:r1476056,1476072
Modified: libcloud/branches/0.12.x/CHANGES
URL: http://svn.apache.org/viewvc/libcloud/branches/0.12.x/CHANGES?rev=1476076&r1=1476075&r2=1476076&view=diff
==============================================================================
--- libcloud/branches/0.12.x/CHANGES (original)
+++ libcloud/branches/0.12.x/CHANGES Fri Apr 26 06:58:17 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/branches/0.12.x/libcloud/compute/drivers/vcloud.py
URL: http://svn.apache.org/viewvc/libcloud/branches/0.12.x/libcloud/compute/drivers/vcloud.py?rev=1476076&r1=1476075&r2=1476076&view=diff
==============================================================================
--- libcloud/branches/0.12.x/libcloud/compute/drivers/vcloud.py (original)
+++ libcloud/branches/0.12.x/libcloud/compute/drivers/vcloud.py Fri Apr 26 06:58:17 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/branches/0.12.x/libcloud/test/compute/test_vcloud.py
URL: http://svn.apache.org/viewvc/libcloud/branches/0.12.x/libcloud/test/compute/test_vcloud.py?rev=1476076&r1=1476075&r2=1476076&view=diff
==============================================================================
--- libcloud/branches/0.12.x/libcloud/test/compute/test_vcloud.py (original)
+++ libcloud/branches/0.12.x/libcloud/test/compute/test_vcloud.py Fri Apr 26 06:58:17 2013
@@ -270,6 +270,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):
@@ -558,6 +567,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]