Send API parameters as JSON in cloudscale_server module

Use JSON to send the POST data to the API instead of an urlencoded
string. Urlencoding is not really a good match for some Python
datatypes.

This fixes an issue when submitting a list of SSH keys which did not get
translated properly.

Partial cherry-pick of the important parts of 4c94c6f9ba.
pull/34028/merge
Gaudenz Steinlin 8 years ago committed by Toshio Kuratomi
parent b375d5f3ea
commit 03eccdea19

@ -217,7 +217,6 @@ from datetime import datetime, timedelta
from time import sleep
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six.moves.urllib.parse import urlencode
from ansible.module_utils.urls import fetch_url
@ -273,12 +272,14 @@ class AnsibleCloudscaleServer(object):
def _post(self, api_call, data=None):
headers = self._auth_header.copy()
if data is not None:
data = urlencode(data)
data = self._module.jsonify(data)
headers['Content-type'] = 'application/json'
resp, info = fetch_url(self._module,
API_URL+api_call,
headers = self._auth_header,
headers = headers,
method='POST',
data=data)

Loading…
Cancel
Save