From f6ab19e25f048a80df0652d012a9da8a0d044f67 Mon Sep 17 00:00:00 2001 From: jo Date: Wed, 3 Dec 2025 15:03:18 +0100 Subject: [PATCH] refactor: add actions helpers to global module class --- plugins/module_utils/hcloud.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/plugins/module_utils/hcloud.py b/plugins/module_utils/hcloud.py index dc9d652..1d09e54 100644 --- a/plugins/module_utils/hcloud.py +++ b/plugins/module_utils/hcloud.py @@ -23,7 +23,7 @@ from .vendor.hcloud import ( HCloudException, exponential_backoff_function, ) -from .vendor.hcloud.actions import ActionException +from .vendor.hcloud.actions import ActionException, BoundAction from .version import version @@ -54,6 +54,7 @@ class AnsibleHCloud: module: AnsibleModule client: Client + actions: list[BoundAction] def __init__(self, module: AnsibleModule): if not self.represent: @@ -69,6 +70,9 @@ class AnsibleHCloud: self._build_client() + # Save actions and wait for them using self._wait_actions() + self.actions = [] + def fail_json_hcloud( self, exception: HCloudException, @@ -123,6 +127,14 @@ 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