mirror of
https://github.com/ansible-collections/hetzner.hcloud
synced 2024-11-10 06:34:13 +00:00
Improve imports of APIException (#37)
Signed-off-by: Lukas Kämmerling <lukas.kaemmerling@hetzner-cloud.de>
This commit is contained in:
parent
207d68677a
commit
8bb449d3de
21 changed files with 29 additions and 20 deletions
|
@ -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.")
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ from ansible.module_utils.basic import env_fallback, missing_required_lib
|
|||
|
||||
try:
|
||||
import hcloud
|
||||
from hcloud import APIException
|
||||
|
||||
HAS_HCLOUD = True
|
||||
except ImportError:
|
||||
|
|
|
@ -134,7 +134,7 @@ try:
|
|||
from hcloud.certificates.domain import Server
|
||||
from hcloud import APIException
|
||||
except ImportError:
|
||||
pass
|
||||
APIException = None
|
||||
|
||||
|
||||
class AnsibleHcloudCertificate(Hcloud):
|
||||
|
|
|
@ -93,7 +93,7 @@ from ansible_collections.hetzner.hcloud.plugins.module_utils.hcloud import Hclou
|
|||
try:
|
||||
from hcloud import APIException
|
||||
except ImportError:
|
||||
pass
|
||||
APIException = None
|
||||
|
||||
|
||||
class AnsibleHcloudCertificateInfo(Hcloud):
|
||||
|
|
|
@ -88,7 +88,7 @@ from ansible_collections.hetzner.hcloud.plugins.module_utils.hcloud import Hclou
|
|||
try:
|
||||
from hcloud import APIException
|
||||
except ImportError:
|
||||
pass
|
||||
APIException = None
|
||||
|
||||
|
||||
class AnsibleHcloudDatacenterInfo(Hcloud):
|
||||
|
|
|
@ -105,7 +105,7 @@ from ansible_collections.hetzner.hcloud.plugins.module_utils.hcloud import Hclou
|
|||
try:
|
||||
from hcloud import APIException
|
||||
except ImportError:
|
||||
pass
|
||||
APIException = None
|
||||
|
||||
|
||||
class AnsibleHcloudFloatingIPInfo(Hcloud):
|
||||
|
|
|
@ -111,7 +111,7 @@ from ansible_collections.hetzner.hcloud.plugins.module_utils.hcloud import Hclou
|
|||
try:
|
||||
from hcloud import APIException
|
||||
except ImportError:
|
||||
pass
|
||||
APIException = None
|
||||
|
||||
|
||||
class AnsibleHcloudImageInfo(Hcloud):
|
||||
|
|
|
@ -153,7 +153,7 @@ try:
|
|||
from hcloud.load_balancers.domain import LoadBalancer
|
||||
from hcloud import APIException
|
||||
except ImportError:
|
||||
pass
|
||||
APIException = None
|
||||
|
||||
|
||||
class AnsibleHcloudLoadBalancer(Hcloud):
|
||||
|
|
|
@ -288,7 +288,7 @@ try:
|
|||
LoadBalancerServiceHealthCheck, LoadBalancerServiceHealthCheckHttp
|
||||
from hcloud import APIException
|
||||
except ImportError:
|
||||
pass
|
||||
APIException = None
|
||||
|
||||
|
||||
class AnsibleHcloudLoadBalancerService(Hcloud):
|
||||
|
|
|
@ -147,6 +147,9 @@ try:
|
|||
from hcloud.load_balancers.domain import LoadBalancerTarget, LoadBalancerTargetLabelSelector, LoadBalancerTargetIP
|
||||
except ImportError:
|
||||
APIException = None
|
||||
LoadBalancerTarget = None
|
||||
LoadBalancerTargetLabelSelector = None
|
||||
LoadBalancerTargetIP = None
|
||||
|
||||
|
||||
class AnsibleHcloudLoadBalancerTarget(Hcloud):
|
||||
|
|
|
@ -87,7 +87,7 @@ from ansible_collections.hetzner.hcloud.plugins.module_utils.hcloud import Hclou
|
|||
try:
|
||||
from hcloud import APIException
|
||||
except ImportError:
|
||||
pass
|
||||
APIException = None
|
||||
|
||||
|
||||
class AnsibleHcloudLocationInfo(Hcloud):
|
||||
|
|
|
@ -187,7 +187,7 @@ from ansible_collections.hetzner.hcloud.plugins.module_utils.hcloud import Hclou
|
|||
try:
|
||||
from hcloud import APIException
|
||||
except ImportError:
|
||||
pass
|
||||
APIException = None
|
||||
|
||||
|
||||
class AnsibleHcloudNetworkInfo(Hcloud):
|
||||
|
|
|
@ -100,7 +100,7 @@ try:
|
|||
from hcloud.networks.domain import NetworkRoute
|
||||
except ImportError:
|
||||
APIException = None
|
||||
NetworkSubnet = None
|
||||
NetworkRoute = None
|
||||
|
||||
|
||||
class AnsibleHcloudRoute(Hcloud):
|
||||
|
|
|
@ -257,7 +257,10 @@ try:
|
|||
from hcloud.servers.domain import Server
|
||||
from hcloud import APIException
|
||||
except ImportError:
|
||||
pass
|
||||
APIException = None
|
||||
Volume = None
|
||||
SSHKey = None
|
||||
Server = None
|
||||
|
||||
|
||||
class AnsibleHcloudServer(Hcloud):
|
||||
|
|
|
@ -132,7 +132,7 @@ from ansible_collections.hetzner.hcloud.plugins.module_utils.hcloud import Hclou
|
|||
try:
|
||||
from hcloud import APIException
|
||||
except ImportError:
|
||||
pass
|
||||
APIException = None
|
||||
|
||||
|
||||
class AnsibleHcloudServerInfo(Hcloud):
|
||||
|
|
|
@ -123,7 +123,6 @@ try:
|
|||
from hcloud import APIException
|
||||
except ImportError:
|
||||
APIException = None
|
||||
NetworkSubnet = None
|
||||
|
||||
|
||||
class AnsibleHcloudServerNetwork(Hcloud):
|
||||
|
|
|
@ -102,7 +102,7 @@ from ansible_collections.hetzner.hcloud.plugins.module_utils.hcloud import Hclou
|
|||
try:
|
||||
from hcloud import APIException
|
||||
except ImportError:
|
||||
pass
|
||||
APIException = None
|
||||
|
||||
|
||||
class AnsibleHcloudServerTypeInfo(Hcloud):
|
||||
|
|
|
@ -124,7 +124,7 @@ try:
|
|||
from hcloud.ssh_keys.domain import Server
|
||||
from hcloud import APIException
|
||||
except ImportError:
|
||||
pass
|
||||
APIException = None
|
||||
|
||||
|
||||
class AnsibleHcloudSSHKey(Hcloud):
|
||||
|
|
|
@ -87,7 +87,7 @@ from ansible_collections.hetzner.hcloud.plugins.module_utils.hcloud import Hclou
|
|||
try:
|
||||
from hcloud import APIException
|
||||
except ImportError:
|
||||
pass
|
||||
APIException = None
|
||||
|
||||
|
||||
class AnsibleHcloudSSHKeyInfo(Hcloud):
|
||||
|
|
|
@ -169,7 +169,9 @@ try:
|
|||
from hcloud.servers.domain import Server
|
||||
import hcloud
|
||||
except ImportError:
|
||||
pass
|
||||
APIException = None
|
||||
Volume = None
|
||||
Server = None
|
||||
|
||||
|
||||
class AnsibleHcloudVolume(Hcloud):
|
||||
|
|
|
@ -102,7 +102,7 @@ from ansible_collections.hetzner.hcloud.plugins.module_utils.hcloud import Hclou
|
|||
try:
|
||||
from hcloud import APIException
|
||||
except ImportError:
|
||||
pass
|
||||
APIException = None
|
||||
|
||||
|
||||
class AnsibleHcloudVolumeInfo(Hcloud):
|
||||
|
|
Loading…
Reference in a new issue