1
0
Fork 0
mirror of https://github.com/ansible-collections/hetzner.hcloud.git synced 2026-02-04 08:01:49 +00:00

refactor: add actions helpers to global module class

This commit is contained in:
jo 2025-12-03 15:03:18 +01:00
parent 4c242d193c
commit f6ab19e25f
No known key found for this signature in database
GPG key ID: B2FEC9B22722B984

View file

@ -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