|
124 | 124 | from ansible.module_utils.common.text.converters import to_native
|
125 | 125 | from ansible.module_utils.six.moves.urllib.parse import urlencode
|
126 | 126 |
|
127 |
| -from ansible_collections.community.hrobot.plugins.module_utils.common import ( |
128 |
| - CheckDoneTimeoutException, |
129 |
| -) |
130 | 127 | from ansible_collections.community.hrobot.plugins.module_utils.robot import (
|
131 | 128 | BASE_URL,
|
132 | 129 | ROBOT_DEFAULT_ARGUMENT_SPEC,
|
|
138 | 135 | API_BASE_URL,
|
139 | 136 | API_DEFAULT_ARGUMENT_SPEC,
|
140 | 137 | _API_DEFAULT_ARGUMENT_SPEC_COMPAT,
|
141 |
| - api_fetch_url_json_with_retries, |
| 138 | + ApplyActionError, |
| 139 | + api_apply_action, |
142 | 140 | api_fetch_url_json,
|
143 | 141 | )
|
144 | 142 |
|
@@ -297,34 +295,17 @@ def main():
|
297 | 295 | if action and not module.check_mode:
|
298 | 296 | after.update(update_after_update)
|
299 | 297 | action_url = "{0}/actions/update_access_settings".format(url)
|
300 |
| - headers = {"Content-type": "application/json"} |
301 |
| - result, dummy, dummy2 = api_fetch_url_json( |
302 |
| - module, |
303 |
| - action_url, |
304 |
| - data=module.jsonify(action), |
305 |
| - headers=headers, |
306 |
| - method='POST', |
307 |
| - ) |
308 |
| - action_id = result["action"]["id"] |
309 |
| - if result["action"]["status"] == "running": |
310 |
| - this_action_url = "{0}/v1/storage_boxes/actions/{1}".format(API_BASE_URL, action_id) |
311 |
| - |
312 |
| - def action_done_callback(result_, info_, error_): |
313 |
| - if error_ is not None: # pragma: no cover |
314 |
| - return True # pragma: no cover |
315 |
| - return result_["action"]["status"] != "running" |
316 |
| - |
317 |
| - try: |
318 |
| - result, dummy, dummy2 = api_fetch_url_json_with_retries( |
319 |
| - module, this_action_url, action_done_callback, check_done_delay=1, check_done_timeout=60, skip_first=True, |
320 |
| - ) |
321 |
| - except CheckDoneTimeoutException as dummy: |
322 |
| - module.fail_json(msg='Timeout while waiting for access settings to be configured.') |
323 |
| - error = result["action"].get("error") |
324 |
| - if isinstance(error, dict): |
325 |
| - module.fail_json(msg='Error while updating access settings: [{0}] {1}'.format(error.get("code"), error.get("message"))) |
326 |
| - elif result["action"]["status"] == "error": |
327 |
| - module.fail_json(msg='Error while updating access settings (unknown error)') |
| 298 | + try: |
| 299 | + api_apply_action( |
| 300 | + module, |
| 301 | + action_url, |
| 302 | + action, |
| 303 | + lambda action_id: "{0}/v1/storage_boxes/actions/{1}".format(API_BASE_URL, action_id), |
| 304 | + check_done_delay=1, |
| 305 | + check_done_timeout=60, |
| 306 | + ) |
| 307 | + except ApplyActionError as exc: |
| 308 | + module.fail_json(msg='Error while updating access settings: {0}'.format(exc)) |
328 | 309 |
|
329 | 310 | result = dict(after)
|
330 | 311 | result['changed'] = bool(changes)
|
|
0 commit comments