You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by an...@apache.org on 2016/04/23 05:13:37 UTC
[3/3] libcloud git commit: profitbricks.py: Figure out a pattern that
works with xml + lxml Closes #772
profitbricks.py: Figure out a pattern that works with xml + lxml Closes #772
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/0789cb58
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/0789cb58
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/0789cb58
Branch: refs/heads/trunk
Commit: 0789cb58d2d293b984696da0c1f674311248485b
Parents: 1588cc7
Author: Peter Schmidt <pe...@peterjs.com>
Authored: Fri Apr 22 23:11:53 2016 +1000
Committer: anthony-shaw <an...@apache.org>
Committed: Sat Apr 23 13:13:18 2016 +1000
----------------------------------------------------------------------
libcloud/compute/drivers/profitbricks.py | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/0789cb58/libcloud/compute/drivers/profitbricks.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/profitbricks.py b/libcloud/compute/drivers/profitbricks.py
index 697b082..ab217f0 100644
--- a/libcloud/compute/drivers/profitbricks.py
+++ b/libcloud/compute/drivers/profitbricks.py
@@ -85,6 +85,16 @@ class ProfitBricksConnection(ConnectionUserAndKey):
api_prefix = API_VERSION
responseCls = ProfitBricksResponse
+ # Supporting xml + lxml is funky :S
+ SOAPENV_NAMESPACE = 'http://schemas.xmlsoap.org/soap/envelope/'
+ SOAPENV = '{%s}' % SOAPENV_NAMESPACE
+ WS_NAMESPACE = 'http://ws.api.profitbricks.com/'
+ WS = '{%s}' % WS_NAMESPACE
+ NSMAP = {
+ 'soapenv': SOAPENV_NAMESPACE,
+ 'ws': WS_NAMESPACE,
+ }
+
def add_default_headers(self, headers):
headers['Content-Type'] = 'text/xml'
headers['Authorization'] = 'Basic %s' % (base64.b64encode(
@@ -93,13 +103,11 @@ class ProfitBricksConnection(ConnectionUserAndKey):
return headers
def encode_data(self, data):
- soap_env = ET.Element('soapenv:Envelope', {
- 'xmlns:soapenv': 'http://schemas.xmlsoap.org/soap/envelope/',
- 'xmlns:ws': 'http://ws.api.profitbricks.com/'
- })
- ET.SubElement(soap_env, 'soapenv:Header')
- soap_body = ET.SubElement(soap_env, 'soapenv:Body')
- soap_req_body = ET.SubElement(soap_body, 'ws:%s' % (data['action']))
+ soap_env = ET.Element(self.SOAPENV + 'Envelope',
+ self.NSMAP, **self.NSMAP)
+ ET.SubElement(soap_env, self.SOAPENV + 'Header')
+ soap_body = ET.SubElement(soap_env, self.SOAPENV + 'Body')
+ soap_req_body = ET.SubElement(soap_body, self.WS + data['action'])
if 'request' in data.keys():
soap_req_body = ET.SubElement(soap_req_body, 'request')