mirror of
https://github.com/ansible-collections/hetzner.hcloud.git
synced 2026-02-04 08:01:49 +00:00
* chore: ignore venv directories * chore: ignore integration test generated inventory * feat: vendor hcloud package * import https://github.com/hetznercloud/hcloud-python * use vendored hcloud in modules * update integration test requirements * make vendor script self contained * chore: add check-hcloud-vendor pre-commit hook * pin hcloud version to v.1.24.0 * move vendored __version__.py file to _version.py * update comment about galaxy-importer filename lint
68 lines
2 KiB
Python
68 lines
2 KiB
Python
# Copyright: (c) 2019, Hetzner Cloud GmbH <info@hetzner-cloud.de>
|
|
|
|
# Simplified BSD License (see licenses/simplified_bsd.txt or https://opensource.org/licenses/BSD-2-Clause)
|
|
|
|
|
|
from ansible.module_utils.ansible_release import __version__
|
|
from ansible.module_utils.basic import env_fallback, missing_required_lib
|
|
from ansible_collections.hetzner.hcloud.plugins.module_utils.vendor import hcloud
|
|
|
|
HAS_REQUESTS = True
|
|
HAS_DATEUTIL = True
|
|
|
|
try:
|
|
import requests # pylint: disable=unused-import
|
|
except ImportError:
|
|
HAS_REQUESTS = False
|
|
|
|
try:
|
|
import dateutil # pylint: disable=unused-import
|
|
except ImportError:
|
|
HAS_DATEUTIL = False
|
|
|
|
|
|
class Hcloud:
|
|
def __init__(self, module, represent):
|
|
self.module = module
|
|
self.represent = represent
|
|
self.result = {"changed": False, self.represent: None}
|
|
if not HAS_REQUESTS:
|
|
module.fail_json(msg=missing_required_lib("requests"))
|
|
if not HAS_DATEUTIL:
|
|
module.fail_json(msg=missing_required_lib("python-dateutil"))
|
|
self._build_client()
|
|
|
|
def _build_client(self):
|
|
self.client = hcloud.Client(
|
|
token=self.module.params["api_token"],
|
|
api_endpoint=self.module.params["endpoint"],
|
|
application_name="ansible-module",
|
|
application_version=__version__,
|
|
)
|
|
|
|
def _mark_as_changed(self):
|
|
self.result["changed"] = True
|
|
|
|
@staticmethod
|
|
def base_module_arguments():
|
|
return {
|
|
"api_token": {
|
|
"type": "str",
|
|
"required": True,
|
|
"fallback": (env_fallback, ["HCLOUD_TOKEN"]),
|
|
"no_log": True,
|
|
},
|
|
"endpoint": {"type": "str", "default": "https://api.hetzner.cloud/v1"},
|
|
}
|
|
|
|
def _prepare_result(self):
|
|
"""Prepare the result for every module
|
|
|
|
:return: dict
|
|
"""
|
|
return {}
|
|
|
|
def get_result(self):
|
|
if getattr(self, self.represent) is not None:
|
|
self.result[self.represent] = self._prepare_result()
|
|
return self.result
|