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:
parent
cf2c811a84
commit
d34d6516f4
1 changed files with 15 additions and 1 deletions
|
|
@ -22,7 +22,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
|
||||
|
||||
|
||||
|
|
@ -36,6 +36,9 @@ class AnsibleHCloud:
|
|||
|
||||
module: AnsibleModule
|
||||
|
||||
client: Client
|
||||
actions: list[BoundAction]
|
||||
|
||||
def __init__(self, module: AnsibleModule):
|
||||
if not self.represent:
|
||||
raise NotImplementedError(f"represent property is not defined for {self.__class__.__name__}")
|
||||
|
|
@ -50,6 +53,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,
|
||||
|
|
@ -104,6 +110,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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue