mirror of
https://github.com/ansible-collections/hetzner.hcloud.git
synced 2026-02-04 08:01:49 +00:00
feat: vendor hcloud python dependency (#244)
* 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
This commit is contained in:
parent
5190535323
commit
8a6157e8b2
84 changed files with 8433 additions and 79 deletions
|
|
@ -121,13 +121,11 @@ from ansible.errors import AnsibleError
|
|||
from ansible.module_utils.common.text.converters import to_native
|
||||
from ansible.plugins.inventory import BaseInventoryPlugin, Constructable
|
||||
from ansible.release import __version__
|
||||
|
||||
try:
|
||||
from hcloud import APIException, hcloud
|
||||
|
||||
HAS_HCLOUD = True
|
||||
except ImportError:
|
||||
HAS_HCLOUD = False
|
||||
from ansible_collections.hetzner.hcloud.plugins.module_utils.hcloud import (
|
||||
HAS_DATEUTIL,
|
||||
HAS_REQUESTS,
|
||||
)
|
||||
from ansible_collections.hetzner.hcloud.plugins.module_utils.vendor import hcloud
|
||||
|
||||
|
||||
class InventoryModule(BaseInventoryPlugin, Constructable):
|
||||
|
|
@ -159,7 +157,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable):
|
|||
# We test the API Token against the location API, because this is the API with the smallest result
|
||||
# and not controllable from the customer.
|
||||
self.client.locations.get_all()
|
||||
except APIException:
|
||||
except hcloud.APIException:
|
||||
raise AnsibleError("Invalid Hetzner Cloud API Token.")
|
||||
|
||||
def _get_servers(self):
|
||||
|
|
@ -177,7 +175,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable):
|
|||
self.network = self.client.networks.get_by_name(network)
|
||||
if self.network is None:
|
||||
self.network = self.client.networks.get_by_id(network)
|
||||
except APIException:
|
||||
except hcloud.APIException:
|
||||
raise AnsibleError("The given network is not found.")
|
||||
|
||||
tmp = []
|
||||
|
|
@ -322,8 +320,10 @@ class InventoryModule(BaseInventoryPlugin, Constructable):
|
|||
def parse(self, inventory, loader, path, cache=True):
|
||||
super().parse(inventory, loader, path, cache)
|
||||
|
||||
if not HAS_HCLOUD:
|
||||
raise AnsibleError("The Hetzner Cloud dynamic inventory plugin requires hcloud-python.")
|
||||
if not HAS_REQUESTS:
|
||||
raise AnsibleError("The Hetzner Cloud dynamic inventory plugin requires requests.")
|
||||
if not HAS_DATEUTIL:
|
||||
raise AnsibleError("The Hetzner Cloud dynamic inventory plugin requires python-dateutil.")
|
||||
|
||||
self._read_config_data(path)
|
||||
self._configure_hcloud_client()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue