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.")

View file

@ -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:

View file

@ -134,7 +134,7 @@ try:
from hcloud.certificates.domain import Server
from hcloud import APIException
except ImportError:
pass
APIException = None
class AnsibleHcloudCertificate(Hcloud):

View file

@ -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):

View file

@ -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):

View file

@ -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):

View file

@ -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):

View file

@ -153,7 +153,7 @@ try:
from hcloud.load_balancers.domain import LoadBalancer
from hcloud import APIException
except ImportError:
pass
APIException = None
class AnsibleHcloudLoadBalancer(Hcloud):

View file

@ -288,7 +288,7 @@ try:
LoadBalancerServiceHealthCheck, LoadBalancerServiceHealthCheckHttp
from hcloud import APIException
except ImportError:
pass
APIException = None
class AnsibleHcloudLoadBalancerService(Hcloud):

View file

@ -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):

View file

@ -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):

View file

@ -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):

View file

@ -100,7 +100,7 @@ try:
from hcloud.networks.domain import NetworkRoute
except ImportError:
APIException = None
NetworkSubnet = None
NetworkRoute = None
class AnsibleHcloudRoute(Hcloud):

View file

@ -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):

View file

@ -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):

View file

@ -123,7 +123,6 @@ try:
from hcloud import APIException
except ImportError:
APIException = None
NetworkSubnet = None
class AnsibleHcloudServerNetwork(Hcloud):

View file

@ -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):

View file

@ -124,7 +124,7 @@ try:
from hcloud.ssh_keys.domain import Server
from hcloud import APIException
except ImportError:
pass
APIException = None
class AnsibleHcloudSSHKey(Hcloud):

View file

@ -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):

View file

@ -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):

View file

@ -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):