I am trying to add a Virtual Guest to a Bandwidth pool using Python. My rest call goes through without issue but for some reason my python script is failing. Here are the 2 scripts I have tried
import SoftLayer
from pprint import pprint as pp
import logging
logger = logging.getLogger()
logger.addHandler(logging.StreamHandler())
logger.setLevel(3)
client = SoftLayer.Client()
parms = { "parameters": [[], [], [{ "id": "17437341" }], []]}
pool_id = '286469'
addtopool = client['SoftLayer_Network_Bandwidth_Version1_Allotment'].requestVdrContentUpdates(parms["parameters"], id=pool_id)
pp(addtopool)
And:
import SoftLayer
from pprint import pprint as pp
import logging
logger = logging.getLogger()
logger.addHandler(logging.StreamHandler())
logger.setLevel(3)
client = SoftLayer.Client()
parms = [[], [], [{'id': '17406051'}], []]
pool_id = '286469'
addtopool = client['SoftLayer_Network_Bandwidth_Version1_Allotment'].requestVdrContentUpdates(parms, id=pool_id)
pp(addtopool)
In both cases the API returns
"POST /xmlrpc/v3.1/SoftLayer_Network_Bandwidth_Version1_Allotment HTTP/1.1" 200 251
=== RESPONSE ===
{'Content-Length': '251', 'Content-Encoding': 'gzip', 'Vary': 'Accept-Encoding', 'Server': 'Apache', 'Connection': 'close', 'ntCoent-Length': '443', 'Cache-Control': 'private', 'Date': 'Wed, 27 Apr 2016 18:10:07 GMT', 'X-Frame-Options': 'SAMEORIGIN', 'Content-Type': 'text/xml'}
<?xml version="1.0" encoding="iso-8859-1"?>
<methodResponse>
<fault>
<value>
<struct>
<member>
<name>faultCode</name>
<value>
<string>SoftLayer_Exception_Public</string>
</value>
</member>
<member>
<name>faultString</name>
<value>
<string>An error has occurred while processing your request. Please try again later.</string>
</value>
</member>
</struct>
</value>
</fault>
</methodResponse>
Traceback (most recent call last):
File "/Users/ryan/Projects/apitesting/python/addtopool.py", line 13, in <module>
addtopool = client['SoftLayer_Network_Bandwidth_Version1_Allotment'].requestVdrContentUpdates(parms,id=pool_id)
File "/usr/local/lib/python2.7/site-packages/SoftLayer/API.py", line 373, in call_handler
return self(name, *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/SoftLayer/API.py", line 341, in call
return self.client.call(self.name, name, *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/SoftLayer/API.py", line 237, in call
return self.transport(request)
File "/usr/local/lib/python2.7/site-packages/SoftLayer/transports.py", line 187, in __call__
raise _ex(ex.faultCode, ex.faultString)
SoftLayer.exceptions.SoftLayerAPIError: SoftLayerAPIError(SoftLayer_Exception_Public): An error has occurred while processing your request. Please try again later.
For reference the curl request that works is
curl --verbose --user "$SOFTLAYER_USERNAME:$SOFTLAYER_API_KEY" -k -X POST -d '{"parameters": [[], [], [{ "id": "17812855" }], []]}' "https://api.softlayer.com/rest/v3/SoftLayer_Network_Bandwidth_Version1_Allotment/286469/requestVdrContentUpdates"
* Trying 66.228.119.120...
* Connected to api.softlayer.com (66.228.119.120) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
* Server certificate: api.softlayer.com
* Server certificate: RapidSSL SHA256 CA - G3
* Server certificate: GeoTrust Global CA
* Server auth using Basic with user 'xxx'
> POST /rest/v3/SoftLayer_Network_Bandwidth_Version1_Allotment/286469/requestVdrContentUpdates HTTP/1.1
> Host: api.softlayer.com
> Authorization: Basic xxxx
> User-Agent: curl/7.43.0
> Accept: */*
> Content-Length: 52
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 52 out of 52 bytes
< HTTP/1.1 200 OK
< Date: Wed, 27 Apr 2016 18:12:40 GMT
< Server: Apache
< X-Frame-Options: SAMEORIGIN
< Content-Length: 4
< Vary: Accept-Encoding
< Connection: close
< Content-Type: application/json
<
* Closing connection 0
true
I am using requestVdrContentUpdates
You do not have to send all the json as parameters for the Softlayer python client that is wrong see this example
import SoftLayer
from pprint import pprint as pp
import logging
client = SoftLayer.Client()
hardwareToAdd = []
hardwareToRemove = []
cloudsToAdd = [{"id": 15535983 }]
pool_id = '234471'
addtopool = client['SoftLayer_Network_Bandwidth_Version1_Allotment'].requestVdrContentUpdates(hardwareToAdd, hardwareToRemove, cloudsToAdd, id=pool_id)
pp(addtopool)
Regards