mirror of
https://github.com/ansible-collections/hetzner.hcloud.git
synced 2026-02-04 08:01:49 +00:00
fix: do not run actions concurrently
This commit is contained in:
parent
b2e3ce16e4
commit
3435d0a87c
4 changed files with 24 additions and 43 deletions
|
|
@ -23,7 +23,7 @@ from .vendor.hcloud import (
|
|||
HCloudException,
|
||||
exponential_backoff_function,
|
||||
)
|
||||
from .vendor.hcloud.actions import ActionException, BoundAction
|
||||
from .vendor.hcloud.actions import ActionException
|
||||
from .version import version
|
||||
|
||||
|
||||
|
|
@ -54,7 +54,6 @@ class AnsibleHCloud:
|
|||
module: AnsibleModule
|
||||
|
||||
client: Client
|
||||
actions: list[BoundAction]
|
||||
|
||||
def __init__(self, module: AnsibleModule):
|
||||
if not self.represent:
|
||||
|
|
@ -70,9 +69,6 @@ class AnsibleHCloud:
|
|||
|
||||
self._build_client()
|
||||
|
||||
# Save actions and wait for them using self._wait_actions()
|
||||
self.actions = []
|
||||
|
||||
def fail_json_hcloud(
|
||||
self,
|
||||
exception: HCloudException,
|
||||
|
|
@ -127,14 +123,6 @@ class AnsibleHCloud:
|
|||
except ClientException as exception:
|
||||
self.module.fail_json(msg=to_native(exception))
|
||||
|
||||
def _wait_actions(self):
|
||||
"""
|
||||
Wait for all pending actions and flush the list once completed.
|
||||
"""
|
||||
for a in self.actions:
|
||||
a.wait_until_finished()
|
||||
self.actions = []
|
||||
|
||||
def _mark_as_changed(self) -> None:
|
||||
self.result["changed"] = True
|
||||
|
||||
|
|
|
|||
|
|
@ -400,35 +400,34 @@ class AnsibleStorageBox(AnsibleHCloud):
|
|||
|
||||
if not self.module.check_mode:
|
||||
resp = self.client.storage_boxes.create(**params)
|
||||
self.actions.append(resp.action)
|
||||
|
||||
self.storage_box = resp.storage_box
|
||||
|
||||
self._wait_actions()
|
||||
resp.action.wait_until_finished()
|
||||
|
||||
if (value := self.module.params.get("delete_protection")) is not None:
|
||||
if not self.module.check_mode:
|
||||
action = self.storage_box.change_protection(delete=value)
|
||||
self.actions.append(action)
|
||||
action.wait_until_finished()
|
||||
|
||||
if self.module.param_is_defined("snapshot_plan"):
|
||||
if (value := self.module.params.get("snapshot_plan")) is not None:
|
||||
if not self.module.check_mode:
|
||||
action = self.storage_box.enable_snapshot_plan(StorageBoxSnapshotPlan.from_dict(value))
|
||||
self.actions.append(action)
|
||||
action.wait_until_finished()
|
||||
|
||||
if not self.module.check_mode:
|
||||
self._wait_actions()
|
||||
self.storage_box.reload()
|
||||
|
||||
self._mark_as_changed()
|
||||
|
||||
def _update(self):
|
||||
need_reload = False
|
||||
|
||||
if (value := self.module.params.get("storage_box_type")) is not None:
|
||||
if not self.storage_box.storage_box_type.has_id_or_name(value):
|
||||
if not self.module.check_mode:
|
||||
action = self.storage_box.change_type(StorageBoxType(value))
|
||||
self.actions.append(action)
|
||||
action.wait_until_finished()
|
||||
need_reload = True
|
||||
self._mark_as_changed()
|
||||
|
||||
if (value := self.module.params.get("access_settings")) is not None:
|
||||
|
|
@ -436,14 +435,16 @@ class AnsibleStorageBox(AnsibleHCloud):
|
|||
if self.storage_box.access_settings.to_payload() != access_settings.to_payload():
|
||||
if not self.module.check_mode:
|
||||
action = self.storage_box.update_access_settings(access_settings)
|
||||
self.actions.append(action)
|
||||
action.wait_until_finished()
|
||||
need_reload = True
|
||||
self._mark_as_changed()
|
||||
|
||||
if (value := self.module.params.get("delete_protection")) is not None:
|
||||
if self.storage_box.protection["delete"] != value:
|
||||
if not self.module.check_mode:
|
||||
action = self.storage_box.change_protection(delete=value)
|
||||
self.actions.append(action)
|
||||
action.wait_until_finished()
|
||||
need_reload = True
|
||||
self._mark_as_changed()
|
||||
|
||||
if self.module.param_is_defined("snapshot_plan"):
|
||||
|
|
@ -455,13 +456,15 @@ class AnsibleStorageBox(AnsibleHCloud):
|
|||
):
|
||||
if not self.module.check_mode:
|
||||
action = self.storage_box.enable_snapshot_plan(snapshot_plan)
|
||||
self.actions.append(action)
|
||||
action.wait_until_finished()
|
||||
need_reload = True
|
||||
self._mark_as_changed()
|
||||
else:
|
||||
if self.storage_box.snapshot_plan is not None:
|
||||
if not self.module.check_mode:
|
||||
action = self.storage_box.disable_snapshot_plan()
|
||||
self.actions.append(action)
|
||||
action.wait_until_finished()
|
||||
need_reload = True
|
||||
self._mark_as_changed()
|
||||
|
||||
params = {}
|
||||
|
|
@ -476,10 +479,8 @@ class AnsibleStorageBox(AnsibleHCloud):
|
|||
|
||||
# Update only if params holds changes or the data must be refreshed (actions
|
||||
# were triggered)
|
||||
if params or self.actions:
|
||||
if params or need_reload:
|
||||
if not self.module.check_mode:
|
||||
self._wait_actions()
|
||||
|
||||
self.storage_box = self.storage_box.update(**params)
|
||||
|
||||
def _delete(self):
|
||||
|
|
@ -524,8 +525,7 @@ class AnsibleStorageBox(AnsibleHCloud):
|
|||
)
|
||||
if not self.module.check_mode:
|
||||
action = self.storage_box.reset_password(self.module.params.get("password"))
|
||||
self.actions.append(action)
|
||||
self._wait_actions()
|
||||
action.wait_until_finished()
|
||||
|
||||
self._mark_as_changed()
|
||||
|
||||
|
|
@ -546,8 +546,7 @@ class AnsibleStorageBox(AnsibleHCloud):
|
|||
|
||||
if not self.module.check_mode:
|
||||
action = self.storage_box.rollback_snapshot(StorageBoxSnapshot(self.module.params.get("snapshot")))
|
||||
self.actions.append(action)
|
||||
self._wait_actions()
|
||||
action.wait_until_finished()
|
||||
|
||||
self._mark_as_changed()
|
||||
|
||||
|
|
|
|||
|
|
@ -185,9 +185,8 @@ class AnsibleStorageBoxSnapshot(AnsibleHCloud):
|
|||
if not self.module.check_mode:
|
||||
resp = self.storage_box.create_snapshot(**params)
|
||||
self.storage_box_snapshot = resp.snapshot
|
||||
self.actions.append(resp.action)
|
||||
resp.action.wait_until_finished()
|
||||
|
||||
self._wait_actions()
|
||||
self.storage_box_snapshot.reload()
|
||||
|
||||
self._mark_as_changed()
|
||||
|
|
|
|||
|
|
@ -296,9 +296,8 @@ class AnsibleStorageBoxSubaccount(AnsibleHCloud):
|
|||
if not self.module.check_mode:
|
||||
resp = self.storage_box.create_subaccount(**params)
|
||||
self.storage_box_subaccount = resp.subaccount
|
||||
self.actions.append(resp.action)
|
||||
resp.action.wait_until_finished()
|
||||
|
||||
self._wait_actions()
|
||||
self.storage_box_subaccount.reload()
|
||||
self.storage_box_subaccount_name = self.storage_box_subaccount.labels.pop(NAME_LABEL_KEY)
|
||||
|
||||
|
|
@ -311,7 +310,7 @@ class AnsibleStorageBoxSubaccount(AnsibleHCloud):
|
|||
if self.storage_box_subaccount.home_directory != value:
|
||||
if not self.module.check_mode:
|
||||
action = self.storage_box_subaccount.change_home_directory(value)
|
||||
self.actions.append(action)
|
||||
action.wait_until_finished()
|
||||
need_reload = True
|
||||
self._mark_as_changed()
|
||||
|
||||
|
|
@ -320,13 +319,10 @@ class AnsibleStorageBoxSubaccount(AnsibleHCloud):
|
|||
if self.storage_box_subaccount.access_settings.to_payload() != access_settings.to_payload():
|
||||
if not self.module.check_mode:
|
||||
action = self.storage_box_subaccount.update_access_settings(access_settings)
|
||||
self.actions.append(action)
|
||||
action.wait_until_finished()
|
||||
need_reload = True
|
||||
self._mark_as_changed()
|
||||
|
||||
if not self.module.check_mode:
|
||||
self._wait_actions()
|
||||
|
||||
params = {}
|
||||
if (value := self.module.params.get("description")) is not None:
|
||||
if value != self.storage_box_subaccount.description:
|
||||
|
|
@ -400,8 +396,7 @@ class AnsibleStorageBoxSubaccount(AnsibleHCloud):
|
|||
)
|
||||
if not self.module.check_mode:
|
||||
action = self.storage_box_subaccount.reset_password(self.module.params.get("password"))
|
||||
self.actions.append(action)
|
||||
self._wait_actions()
|
||||
action.wait_until_finished()
|
||||
|
||||
self._mark_as_changed()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue