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

Improve imports of APIException (#37)

Signed-off-by: Lukas Kämmerling <lukas.kaemmerling@hetzner-cloud.de>
This commit is contained in:
Lukas Kämmerling 2020-11-24 06:39:21 +01:00 committed by GitHub
parent 207d68677a
commit 8bb449d3de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 29 additions and 20 deletions

View file

@ -98,6 +98,7 @@ from ansible.release import __version__
try:
from hcloud import hcloud
from hcloud import APIException
except ImportError:
raise AnsibleError("The Hetzner Cloud dynamic inventory plugin requires hcloud-python.")
@ -123,7 +124,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 hcloud.APIException:
except APIException:
raise AnsibleError("Invalid Hetzner Cloud API Token.")
def _get_servers(self):
@ -138,7 +139,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable):
self.network = self.client.networks.get_by_name(self.get_option("network"))
if self.network is None:
self.network = self.client.networks.get_by_id(self.get_option("network"))
except hcloud.APIException:
except APIException:
raise AnsibleError(
"The given network is not found.")