Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cloudscale_server: refactor to implement update #52683

merged 17 commits into from Mar 5, 2019
@@ -6,6 +6,7 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type

from copy import deepcopy
from ansible.module_utils.basic import env_fallback
from ansible.module_utils.urls import fetch_url
from ansible.module_utils._text import to_text
@@ -27,6 +28,10 @@ class AnsibleCloudscaleBase(object):
def __init__(self, module):
self._module = module
self._auth_header = {'Authorization': 'Bearer %s' % module.params['api_token']}
self._result = {
'changed': False,
'diff': dict(before=dict(), after=dict()),

def _get(self, api_call):
resp, info = fetch_url(self._module, API_URL + api_call,
@@ -44,6 +49,13 @@ def _get(self, api_call):
def _post_or_patch(self, api_call, method, data):
headers = self._auth_header.copy()
if data is not None:
# Sanitize data dictionary
# Deepcopy: Duplicate the data object for iteration, because
# iterating an object and changing it at the same time is insecure
for k, v in deepcopy(data).items():
if v is None:
del data[k]

data = self._module.jsonify(data)
headers['Content-type'] = 'application/json'

@@ -80,3 +92,9 @@ def _delete(self, api_call):
self._module.fail_json(msg='Failure while calling the API with DELETE for '
'"%s".' % api_call, fetch_url_info=info)

def get_result(self, resource):
if resource:
for k, v in resource.items():
self._result[k] = v
return self._result
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.