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
4c242d193c
commit
f6ab19e25f
1 changed files with 13 additions and 1 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue