mirror of
https://github.com/ansible-collections/hetzner.hcloud
synced 2024-11-10 06:34:13 +00:00
Fix error handling and add test cases (#58)
* Fix error handling and add test cases Signed-off-by: Lukas Kämmerling <lukas.kaemmerling@hetzner-cloud.de>
This commit is contained in:
parent
0a27de6fc6
commit
eb45ae014c
47 changed files with 260 additions and 187 deletions
|
@ -165,7 +165,7 @@ class AnsibleHcloudCertificate(Hcloud):
|
|||
self.module.params.get("name")
|
||||
)
|
||||
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
def _create_certificate(self):
|
||||
|
@ -182,12 +182,13 @@ class AnsibleHcloudCertificate(Hcloud):
|
|||
if not self.module.check_mode:
|
||||
try:
|
||||
self.client.certificates.create(**params)
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
self._mark_as_changed()
|
||||
self._get_certificate()
|
||||
|
||||
def _update_certificate(self):
|
||||
try:
|
||||
name = self.module.params.get("name")
|
||||
if name is not None and self.hcloud_certificate.name != name:
|
||||
self.module.fail_on_missing_params(
|
||||
|
@ -202,7 +203,8 @@ class AnsibleHcloudCertificate(Hcloud):
|
|||
if not self.module.check_mode:
|
||||
self.hcloud_certificate.update(labels=labels)
|
||||
self._mark_as_changed()
|
||||
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
self._get_certificate()
|
||||
|
||||
def present_certificate(self):
|
||||
|
@ -216,7 +218,10 @@ class AnsibleHcloudCertificate(Hcloud):
|
|||
self._get_certificate()
|
||||
if self.hcloud_certificate is not None:
|
||||
if not self.module.check_mode:
|
||||
try:
|
||||
self.client.certificates.delete(self.hcloud_certificate)
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
self._mark_as_changed()
|
||||
self.hcloud_certificate = None
|
||||
|
||||
|
|
|
@ -134,7 +134,7 @@ class AnsibleHcloudCertificateInfo(Hcloud):
|
|||
else:
|
||||
self.hcloud_certificate_info = self.client.certificates.get_all()
|
||||
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -123,7 +123,7 @@ class AnsibleHcloudDatacenterInfo(Hcloud):
|
|||
else:
|
||||
self.hcloud_datacenter_info = self.client.datacenters.get_all()
|
||||
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -207,14 +207,14 @@ class AnsibleHcloudFloatingIP(Hcloud):
|
|||
self.hcloud_floating_ip = self.client.floating_ips.get_by_name(
|
||||
self.module.params.get("name")
|
||||
)
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
def _create_floating_ip(self):
|
||||
self.module.fail_on_missing_params(
|
||||
required_params=["type"]
|
||||
)
|
||||
|
||||
try:
|
||||
params = {
|
||||
"description": self.module.params.get("description"),
|
||||
"type": self.module.params.get("type"),
|
||||
|
@ -240,7 +240,8 @@ class AnsibleHcloudFloatingIP(Hcloud):
|
|||
delete_protection = self.module.params.get("delete_protection")
|
||||
if delete_protection is not None:
|
||||
self.hcloud_floating_ip.change_protection(delete=delete_protection).wait_until_finished()
|
||||
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
self._mark_as_changed()
|
||||
self._get_floating_ip()
|
||||
|
||||
|
@ -290,7 +291,7 @@ class AnsibleHcloudFloatingIP(Hcloud):
|
|||
self._mark_as_changed()
|
||||
|
||||
self._get_floating_ip()
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
def present_floating_ip(self):
|
||||
|
@ -314,7 +315,7 @@ class AnsibleHcloudFloatingIP(Hcloud):
|
|||
)
|
||||
self._mark_as_changed()
|
||||
self.hcloud_floating_ip = None
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -147,7 +147,7 @@ class AnsibleHcloudFloatingIPInfo(Hcloud):
|
|||
else:
|
||||
self.hcloud_floating_ip_info = self.client.floating_ips.get_all()
|
||||
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -158,7 +158,7 @@ class AnsibleHcloudImageInfo(Hcloud):
|
|||
|
||||
self.hcloud_image_info = self.client.images.get_all(**params)
|
||||
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -187,7 +187,7 @@ class AnsibleHcloudLoadBalancer(Hcloud):
|
|||
self.hcloud_load_balancer = self.client.load_balancers.get_by_name(
|
||||
self.module.params.get("name")
|
||||
)
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
def _create_load_balancer(self):
|
||||
|
@ -195,7 +195,7 @@ class AnsibleHcloudLoadBalancer(Hcloud):
|
|||
self.module.fail_on_missing_params(
|
||||
required_params=["name", "load_balancer_type"]
|
||||
)
|
||||
|
||||
try:
|
||||
params = {
|
||||
"name": self.module.params.get("name"),
|
||||
"load_balancer_type": self.client.load_balancer_types.get_by_name(
|
||||
|
@ -221,7 +221,8 @@ class AnsibleHcloudLoadBalancer(Hcloud):
|
|||
if delete_protection is not None:
|
||||
self._get_load_balancer()
|
||||
self.hcloud_load_balancer.change_protection(delete=delete_protection).wait_until_finished()
|
||||
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
self._mark_as_changed()
|
||||
self._get_load_balancer()
|
||||
|
||||
|
@ -261,7 +262,7 @@ class AnsibleHcloudLoadBalancer(Hcloud):
|
|||
|
||||
self._mark_as_changed()
|
||||
self._get_load_balancer()
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
def present_load_balancer(self):
|
||||
|
@ -279,7 +280,7 @@ class AnsibleHcloudLoadBalancer(Hcloud):
|
|||
self.client.load_balancers.delete(self.hcloud_load_balancer)
|
||||
self._mark_as_changed()
|
||||
self.hcloud_load_balancer = None
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -370,7 +370,7 @@ class AnsibleHcloudLoadBalancerInfo(Hcloud):
|
|||
|
||||
self.hcloud_load_balancer_info = self.client.load_balancers.get_all(**params)
|
||||
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -125,7 +125,7 @@ class AnsibleHcloudLoadBalancerNetwork(Hcloud):
|
|||
self.hcloud_network = self.client.networks.get_by_name(self.module.params.get("network"))
|
||||
self.hcloud_load_balancer = self.client.load_balancers.get_by_name(self.module.params.get("load_balancer"))
|
||||
self.hcloud_load_balancer_network = None
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
def _get_load_balancer_network(self):
|
||||
|
@ -144,7 +144,7 @@ class AnsibleHcloudLoadBalancerNetwork(Hcloud):
|
|||
if not self.module.check_mode:
|
||||
try:
|
||||
self.hcloud_load_balancer.attach_to_network(**params).wait_until_finished()
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
self._mark_as_changed()
|
||||
|
@ -162,9 +162,13 @@ class AnsibleHcloudLoadBalancerNetwork(Hcloud):
|
|||
self._get_load_balancer_network()
|
||||
if self.hcloud_load_balancer_network is not None and self.hcloud_load_balancer is not None:
|
||||
if not self.module.check_mode:
|
||||
try:
|
||||
self.hcloud_load_balancer.detach_from_network(
|
||||
self.hcloud_load_balancer_network.network).wait_until_finished()
|
||||
self._mark_as_changed()
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
self.hcloud_load_balancer_network = None
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -344,7 +344,7 @@ class AnsibleHcloudLoadBalancerService(Hcloud):
|
|||
self.module.params.get("load_balancer")
|
||||
)
|
||||
self._get_load_balancer_service()
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
def _create_load_balancer_service(self):
|
||||
|
@ -377,7 +377,7 @@ class AnsibleHcloudLoadBalancerService(Hcloud):
|
|||
try:
|
||||
self.hcloud_load_balancer.add_service(LoadBalancerService(**params)).wait_until_finished(
|
||||
max_retries=1000)
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
self._mark_as_changed()
|
||||
self._get_load_balancer()
|
||||
|
@ -403,11 +403,11 @@ class AnsibleHcloudLoadBalancerService(Hcloud):
|
|||
hcloud_cert = self.client.certificates.get_by_name(
|
||||
certificate
|
||||
)
|
||||
except APIException:
|
||||
except Exception:
|
||||
hcloud_cert = self.client.certificates.get_by_id(
|
||||
certificate
|
||||
)
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
service_http.certificates.append(hcloud_cert)
|
||||
|
||||
|
@ -475,7 +475,7 @@ class AnsibleHcloudLoadBalancerService(Hcloud):
|
|||
if not self.module.check_mode:
|
||||
self.hcloud_load_balancer.update_service(LoadBalancerService(**params)).wait_until_finished(
|
||||
max_retries=1000)
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
self._get_load_balancer()
|
||||
|
||||
|
@ -499,8 +499,11 @@ class AnsibleHcloudLoadBalancerService(Hcloud):
|
|||
self._get_load_balancer()
|
||||
if self.hcloud_load_balancer_service is not None:
|
||||
if not self.module.check_mode:
|
||||
try:
|
||||
self.hcloud_load_balancer.delete_service(self.hcloud_load_balancer_service).wait_until_finished(
|
||||
max_retries=1000)
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
self._mark_as_changed()
|
||||
self.hcloud_load_balancer_service = None
|
||||
except APIException as e:
|
||||
|
|
|
@ -181,7 +181,7 @@ class AnsibleHcloudLoadBalancerTarget(Hcloud):
|
|||
if self.module.params.get("type") == "server":
|
||||
self.hcloud_server = self.client.servers.get_by_name(self.module.params.get("server"))
|
||||
self.hcloud_load_balancer_target = None
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
def _get_load_balancer_target(self):
|
||||
|
@ -226,7 +226,7 @@ class AnsibleHcloudLoadBalancerTarget(Hcloud):
|
|||
if not self.module.check_mode:
|
||||
try:
|
||||
self.hcloud_load_balancer.add_target(**params).wait_until_finished()
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
if e.code == "locked" or e.code == "conflict":
|
||||
self._create_load_balancer_target()
|
||||
else:
|
||||
|
@ -269,7 +269,10 @@ class AnsibleHcloudLoadBalancerTarget(Hcloud):
|
|||
target = LoadBalancerTarget(type=self.module.params.get("type"),
|
||||
ip=LoadBalancerTargetIP(ip=self.module.params.get("ip")),
|
||||
use_private_ip=False)
|
||||
try:
|
||||
self.hcloud_load_balancer.remove_target(target).wait_until_finished()
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
self._mark_as_changed()
|
||||
self.hcloud_load_balancer_target = None
|
||||
|
||||
|
|
|
@ -132,7 +132,7 @@ class AnsibleHcloudLoadBalancerTypeInfo(Hcloud):
|
|||
else:
|
||||
self.hcloud_load_balancer_type_info = self.client.load_balancer_types.get_all()
|
||||
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -122,7 +122,7 @@ class AnsibleHcloudLocationInfo(Hcloud):
|
|||
else:
|
||||
self.hcloud_location_info = self.client.locations.get_all()
|
||||
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -144,7 +144,7 @@ class AnsibleHcloudNetwork(Hcloud):
|
|||
self.hcloud_network = self.client.networks.get_by_name(
|
||||
self.module.params.get("name")
|
||||
)
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
def _create_network(self):
|
||||
|
@ -157,7 +157,7 @@ class AnsibleHcloudNetwork(Hcloud):
|
|||
"ip_range": self.module.params.get("ip_range"),
|
||||
"labels": self.module.params.get("labels"),
|
||||
}
|
||||
|
||||
try:
|
||||
if not self.module.check_mode:
|
||||
self.client.networks.create(**params)
|
||||
|
||||
|
@ -165,7 +165,8 @@ class AnsibleHcloudNetwork(Hcloud):
|
|||
if delete_protection is not None:
|
||||
self._get_network()
|
||||
self.hcloud_network.change_protection(delete=delete_protection).wait_until_finished()
|
||||
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
self._mark_as_changed()
|
||||
self._get_network()
|
||||
|
||||
|
@ -188,7 +189,7 @@ class AnsibleHcloudNetwork(Hcloud):
|
|||
if not self.module.check_mode:
|
||||
self.hcloud_network.change_protection(delete=delete_protection).wait_until_finished()
|
||||
self._mark_as_changed()
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
self._get_network()
|
||||
|
||||
|
@ -206,7 +207,7 @@ class AnsibleHcloudNetwork(Hcloud):
|
|||
if not self.module.check_mode:
|
||||
self.client.networks.delete(self.hcloud_network)
|
||||
self._mark_as_changed()
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
self.hcloud_network = None
|
||||
|
||||
|
|
|
@ -264,7 +264,7 @@ class AnsibleHcloudNetworkInfo(Hcloud):
|
|||
else:
|
||||
self.hcloud_network_info = self.client.networks.get_all()
|
||||
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -147,7 +147,7 @@ class AnsibleHcloudReverseDNS(Hcloud):
|
|||
self.hcloud_resource = self.client.floating_ips.get_by_name(
|
||||
self.module.params.get("floating_ip")
|
||||
)
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
def _get_rdns(self):
|
||||
|
@ -198,8 +198,10 @@ class AnsibleHcloudReverseDNS(Hcloud):
|
|||
}
|
||||
|
||||
if not self.module.check_mode:
|
||||
try:
|
||||
self.hcloud_resource.change_dns_ptr(**params).wait_until_finished()
|
||||
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
self._mark_as_changed()
|
||||
self._get_resource()
|
||||
self._get_rdns()
|
||||
|
@ -213,8 +215,10 @@ class AnsibleHcloudReverseDNS(Hcloud):
|
|||
}
|
||||
|
||||
if not self.module.check_mode:
|
||||
try:
|
||||
self.hcloud_resource.change_dns_ptr(**params).wait_until_finished()
|
||||
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
self._mark_as_changed()
|
||||
self._get_resource()
|
||||
self._get_rdns()
|
||||
|
@ -232,7 +236,10 @@ class AnsibleHcloudReverseDNS(Hcloud):
|
|||
self._get_rdns()
|
||||
if self.hcloud_rdns is not None:
|
||||
if not self.module.check_mode:
|
||||
try:
|
||||
self.hcloud_resource.change_dns_ptr(ip=self.hcloud_rdns['ip_address'], dns_ptr=None)
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
self._mark_as_changed()
|
||||
self.hcloud_rdns = None
|
||||
|
||||
|
|
|
@ -120,7 +120,7 @@ class AnsibleHcloudRoute(Hcloud):
|
|||
try:
|
||||
self.hcloud_network = self.client.networks.get_by_name(self.module.params.get("network"))
|
||||
self.hcloud_route = None
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
def _get_route(self):
|
||||
|
@ -139,7 +139,7 @@ class AnsibleHcloudRoute(Hcloud):
|
|||
if not self.module.check_mode:
|
||||
try:
|
||||
self.hcloud_network.add_route(route=route).wait_until_finished()
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
self._mark_as_changed()
|
||||
|
@ -157,7 +157,10 @@ class AnsibleHcloudRoute(Hcloud):
|
|||
self._get_route()
|
||||
if self.hcloud_route is not None and self.hcloud_network is not None:
|
||||
if not self.module.check_mode:
|
||||
try:
|
||||
self.hcloud_network.delete_route(self.hcloud_route).wait_until_finished()
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
self._mark_as_changed()
|
||||
self.hcloud_route = None
|
||||
|
||||
|
|
|
@ -297,7 +297,7 @@ class AnsibleHcloudServer(Hcloud):
|
|||
self.hcloud_server = self.client.servers.get_by_name(
|
||||
self.module.params.get("name")
|
||||
)
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
def _create_server(self):
|
||||
|
@ -345,6 +345,7 @@ class AnsibleHcloudServer(Hcloud):
|
|||
)
|
||||
|
||||
if not self.module.check_mode:
|
||||
try:
|
||||
resp = self.client.servers.create(**params)
|
||||
self.result["root_password"] = resp.root_password
|
||||
resp.action.wait_until_finished(max_retries=1000)
|
||||
|
@ -366,6 +367,8 @@ class AnsibleHcloudServer(Hcloud):
|
|||
self._get_server()
|
||||
self.hcloud_server.change_protection(delete=delete_protection,
|
||||
rebuild=rebuild_protection).wait_until_finished()
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
self._mark_as_changed()
|
||||
self._get_server()
|
||||
|
||||
|
@ -434,7 +437,7 @@ class AnsibleHcloudServer(Hcloud):
|
|||
rebuild=rebuild_protection).wait_until_finished()
|
||||
self._mark_as_changed()
|
||||
self._get_server()
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
def _set_rescue_mode(self, rescue_mode):
|
||||
|
@ -456,7 +459,7 @@ class AnsibleHcloudServer(Hcloud):
|
|||
self.client.servers.power_on(self.hcloud_server).wait_until_finished()
|
||||
self._mark_as_changed()
|
||||
self._get_server()
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
def stop_server(self):
|
||||
|
@ -466,7 +469,7 @@ class AnsibleHcloudServer(Hcloud):
|
|||
self.client.servers.power_off(self.hcloud_server).wait_until_finished()
|
||||
self._mark_as_changed()
|
||||
self._get_server()
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
def rebuild_server(self):
|
||||
|
@ -480,7 +483,7 @@ class AnsibleHcloudServer(Hcloud):
|
|||
self._mark_as_changed()
|
||||
|
||||
self._get_server()
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
def present_server(self):
|
||||
|
@ -498,7 +501,7 @@ class AnsibleHcloudServer(Hcloud):
|
|||
self.client.servers.delete(self.hcloud_server).wait_until_finished()
|
||||
self._mark_as_changed()
|
||||
self.hcloud_server = None
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -180,7 +180,7 @@ class AnsibleHcloudServerInfo(Hcloud):
|
|||
else:
|
||||
self.hcloud_server_info = self.client.servers.get_all()
|
||||
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -145,7 +145,7 @@ class AnsibleHcloudServerNetwork(Hcloud):
|
|||
self.hcloud_network = self.client.networks.get_by_name(self.module.params.get("network"))
|
||||
self.hcloud_server = self.client.servers.get_by_name(self.module.params.get("server"))
|
||||
self.hcloud_server_network = None
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
def _get_server_network(self):
|
||||
|
@ -166,7 +166,7 @@ class AnsibleHcloudServerNetwork(Hcloud):
|
|||
if not self.module.check_mode:
|
||||
try:
|
||||
self.hcloud_server.attach_to_network(**params).wait_until_finished()
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
self._mark_as_changed()
|
||||
|
@ -204,7 +204,10 @@ class AnsibleHcloudServerNetwork(Hcloud):
|
|||
self._get_server_network()
|
||||
if self.hcloud_server_network is not None and self.hcloud_server is not None:
|
||||
if not self.module.check_mode:
|
||||
try:
|
||||
self.hcloud_server.detach_from_network(self.hcloud_server_network.network).wait_until_finished()
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
self._mark_as_changed()
|
||||
self.hcloud_server_network = None
|
||||
|
||||
|
|
|
@ -140,7 +140,7 @@ class AnsibleHcloudServerTypeInfo(Hcloud):
|
|||
else:
|
||||
self.hcloud_server_type_info = self.client.server_types.get_all()
|
||||
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -206,7 +206,10 @@ class AnsibleHcloudSSHKey(Hcloud):
|
|||
self._get_ssh_key()
|
||||
if self.hcloud_ssh_key is not None:
|
||||
if not self.module.check_mode:
|
||||
try:
|
||||
self.client.ssh_keys.delete(self.hcloud_ssh_key)
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
self._mark_as_changed()
|
||||
self.hcloud_ssh_key = None
|
||||
|
||||
|
|
|
@ -129,7 +129,7 @@ class AnsibleHcloudSSHKeyInfo(Hcloud):
|
|||
else:
|
||||
self.hcloud_ssh_key_info = self.client.ssh_keys.get_all()
|
||||
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -160,7 +160,7 @@ class AnsibleHcloudSubnetwork(Hcloud):
|
|||
try:
|
||||
self.hcloud_network = self.client.networks.get_by_name(self.module.params.get("network"))
|
||||
self.hcloud_subnetwork = None
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
def _get_subnetwork(self):
|
||||
|
@ -184,7 +184,7 @@ class AnsibleHcloudSubnetwork(Hcloud):
|
|||
if not self.module.check_mode:
|
||||
try:
|
||||
self.hcloud_network.add_subnet(subnet=NetworkSubnet(**params)).wait_until_finished()
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
self._mark_as_changed()
|
||||
|
@ -202,7 +202,10 @@ class AnsibleHcloudSubnetwork(Hcloud):
|
|||
self._get_subnetwork()
|
||||
if self.hcloud_subnetwork is not None and self.hcloud_network is not None:
|
||||
if not self.module.check_mode:
|
||||
try:
|
||||
self.hcloud_network.delete_subnet(self.hcloud_subnetwork).wait_until_finished()
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
self._mark_as_changed()
|
||||
self.hcloud_subnetwork = None
|
||||
|
||||
|
|
|
@ -206,7 +206,7 @@ class AnsibleHcloudVolume(Hcloud):
|
|||
self.hcloud_volume = self.client.volumes.get_by_name(
|
||||
self.module.params.get("name")
|
||||
)
|
||||
except hcloud.APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
def _create_volume(self):
|
||||
|
@ -228,6 +228,7 @@ class AnsibleHcloudVolume(Hcloud):
|
|||
self.module.fail_json(msg="server or location is required")
|
||||
|
||||
if not self.module.check_mode:
|
||||
try:
|
||||
resp = self.client.volumes.create(**params)
|
||||
resp.action.wait_until_finished()
|
||||
[action.wait_until_finished() for action in resp.next_actions]
|
||||
|
@ -235,7 +236,8 @@ class AnsibleHcloudVolume(Hcloud):
|
|||
if delete_protection is not None:
|
||||
self._get_volume()
|
||||
self.hcloud_volume.change_protection(delete=delete_protection).wait_until_finished()
|
||||
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
self._mark_as_changed()
|
||||
self._get_volume()
|
||||
|
||||
|
@ -277,7 +279,7 @@ class AnsibleHcloudVolume(Hcloud):
|
|||
self._mark_as_changed()
|
||||
|
||||
self._get_volume()
|
||||
except hcloud.APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
def present_volume(self):
|
||||
|
@ -295,7 +297,7 @@ class AnsibleHcloudVolume(Hcloud):
|
|||
self.client.volumes.delete(self.hcloud_volume)
|
||||
self._mark_as_changed()
|
||||
self.hcloud_volume = None
|
||||
except hcloud.APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -147,7 +147,7 @@ class AnsibleHcloudVolumeInfo(Hcloud):
|
|||
else:
|
||||
self.hcloud_volume_info = self.client.volumes.get_all()
|
||||
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
@staticmethod
|
||||
|
|
1
tests/integration/constraints.txt
Normal file
1
tests/integration/constraints.txt
Normal file
|
@ -0,0 +1 @@
|
|||
hcloud >= 1.10.0 # minimum version
|
|
@ -2,5 +2,5 @@
|
|||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
---
|
||||
hcloud_prefix: "tests"
|
||||
hcloud_floating_ip_name: "{{hcloud_prefix}}-integration"
|
||||
hcloud_server_name: "{{hcloud_prefix}}-fip-tests"
|
||||
hcloud_floating_ip_name: "{{hcloud_prefix}}-i"
|
||||
hcloud_server_name: "{{hcloud_prefix}}-fip-t"
|
||||
|
|
|
@ -62,6 +62,33 @@
|
|||
- result is failed
|
||||
- 'result.msg == "one of the following is required: id, name"'
|
||||
|
||||
|
||||
- name: test invalid type
|
||||
hcloud_floating_ip:
|
||||
name: "{{ hcloud_floating_ip_name }}"
|
||||
type: ipv5
|
||||
home_location: "fsn1"
|
||||
register: result
|
||||
ignore_errors: yes
|
||||
- name: verify invalid type
|
||||
assert:
|
||||
that:
|
||||
- result is failed
|
||||
- 'result.msg == "value of type must be one of: ipv4, ipv6, got: ipv5"'
|
||||
|
||||
- name: test invalid location
|
||||
hcloud_floating_ip:
|
||||
name: "{{ hcloud_floating_ip_name }}"
|
||||
type: ipv4
|
||||
home_location: "abc"
|
||||
register: result
|
||||
ignore_errors: yes
|
||||
- name: verify invalid location
|
||||
assert:
|
||||
that:
|
||||
- result is failed
|
||||
- result.msg == "invalid input in fields 'server', 'home_location'"
|
||||
|
||||
- name: test create Floating IP with check mode
|
||||
hcloud_floating_ip:
|
||||
name: "{{ hcloud_floating_ip_name }}"
|
||||
|
|
|
@ -2,4 +2,4 @@
|
|||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
---
|
||||
hcloud_prefix: "tests"
|
||||
hcloud_floating_ip_name: "{{hcloud_prefix}}-integration"
|
||||
hcloud_floating_ip_name: "{{hcloud_prefix}}-i"
|
||||
|
|
|
@ -2,4 +2,4 @@
|
|||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
---
|
||||
hcloud_prefix: "tests"
|
||||
hcloud_load_balancer_name: "{{hcloud_prefix}}-integration"
|
||||
hcloud_load_balancer_name: "{{hcloud_prefix}}-i"
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
---
|
||||
hcloud_prefix: "tests"
|
||||
hcloud_load_balancer_name: "{{hcloud_prefix}}-integration"
|
||||
hcloud_server_name: "{{hcloud_prefix}}-lb-info"
|
||||
hcloud_load_balancer_name: "{{hcloud_prefix}}-i"
|
||||
hcloud_server_name: "{{hcloud_prefix}}-lb-i"
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
---
|
||||
hcloud_prefix: "tests"
|
||||
hcloud_network_name: "{{hcloud_prefix}}-load_balancer-network"
|
||||
hcloud_load_balancer_name: "{{hcloud_prefix}}-load_balancer-network"
|
||||
hcloud_network_name: "{{hcloud_prefix}}-lb-n"
|
||||
hcloud_load_balancer_name: "{{hcloud_prefix}}-lb-n"
|
||||
|
|
|
@ -2,4 +2,4 @@
|
|||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
---
|
||||
hcloud_prefix: "tests"
|
||||
hcloud_load_balancer_name: "{{hcloud_prefix}}-load_balancer-target"
|
||||
hcloud_load_balancer_name: "{{hcloud_prefix}}-lb-target"
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
---
|
||||
hcloud_prefix: "tests"
|
||||
hcloud_server_name: "{{hcloud_prefix}}-lb-target"
|
||||
hcloud_load_balancer_name: "{{hcloud_prefix}}-load_balancer-target"
|
||||
hcloud_server_name: "{{hcloud_prefix}}-lb-t"
|
||||
hcloud_load_balancer_name: "{{hcloud_prefix}}-lb-target"
|
||||
hcloud_testing_ip: "176.9.59.39"
|
||||
|
|
|
@ -2,4 +2,4 @@
|
|||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
---
|
||||
hcloud_prefix: "tests"
|
||||
hcloud_network_name: "{{hcloud_prefix}}-integ"
|
||||
hcloud_network_name: "{{hcloud_prefix}}-i"
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
---
|
||||
hcloud_prefix: "tests"
|
||||
hcloud_server_name: "{{hcloud_prefix}}-rdns"
|
||||
hcloud_floating_ip_name: "{{hcloud_prefix}}-rdns"
|
||||
hcloud_server_name: "{{hcloud_prefix}}"
|
||||
hcloud_floating_ip_name: "{{hcloud_prefix}}"
|
||||
|
|
|
@ -2,4 +2,4 @@
|
|||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
---
|
||||
hcloud_prefix: "tests"
|
||||
hcloud_network_name: "{{hcloud_prefix}}-routes"
|
||||
hcloud_network_name: "{{hcloud_prefix}}-ro"
|
||||
|
|
|
@ -2,4 +2,4 @@
|
|||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
---
|
||||
hcloud_prefix: "tests"
|
||||
hcloud_server_name: "{{hcloud_prefix}}-integration"
|
||||
hcloud_server_name: "{{hcloud_prefix}}-i"
|
||||
|
|
|
@ -2,4 +2,4 @@
|
|||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
---
|
||||
hcloud_prefix: "tests"
|
||||
hcloud_server_name: "{{hcloud_prefix}}-integration"
|
||||
hcloud_server_name: "{{hcloud_prefix}}-ii"
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
---
|
||||
hcloud_prefix: "tests"
|
||||
hcloud_network_name: "{{hcloud_prefix}}-server-network"
|
||||
hcloud_server_name: "{{hcloud_prefix}}-server-network"
|
||||
hcloud_network_name: "{{hcloud_prefix}}-sn"
|
||||
hcloud_server_name: "{{hcloud_prefix}}-sn"
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
---
|
||||
hcloud_prefix: "tests"
|
||||
hcloud_server_name: "{{hcloud_prefix}}"
|
||||
hcloud_ssh_key_name: "{{hcloud_prefix}}-integration"
|
||||
hcloud_ssh_key_name: "{{hcloud_prefix}}"
|
||||
hcloud_ssh_key_public_key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDnaTPfKaX1QKcRLOfr34buVLh5FhJAThI9NYB0xNdXsMd4Y0zLyyCQzHbx4eWCVZxym/s6csWSeLaAhO1GOHeAw3hQFMqf1oTBx6Y8g0pKpeotKPa/PDSUzdZF9Lc+DadtpQd8kFVHAu1Kd3zoEUnk1u6kP7I4qu4Z/6F9qBDF+M3aobiPVxdS7GwaVRW3nZu+FcQDLiBiNOjuRDyjHcDfEUkoh2SOu25RrFtGPzFu5mGmBJwotKpWAocLGfHzyn/fAHxgw3jKZVH/t+XWQFnl82Ie8yE3Z1EZ7oDkNRqFQT9AdXEQOLycTTYTQMJZpgeFTv3sAo6lPRCusiFmmLcf ci@ansible.hetzner.cloud"
|
||||
hcloud_ssh_key_fingerprint: "56:89:c4:d6:a7:4a:79:82:f4:c2:58:9c:e1:d2:2d:4e"
|
||||
|
||||
hcloud_doubled_ssh_key_public_key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC1AiuN3UMQKzOs4tNudmlDSkSebC+savc6CivoHGflUKeli7nKb5pKgGiqH+zeWZc+8+flUa2BxsJWmi7d1nGJ++W4BnzmqW78ApelpJnGtuX8IKNcq/trhVTQyaShPiLluoBs7bXyyZpAKNGkk3jHrgwwYD/QQDN0CJnQUM18fjH5CUes2vmaG/kkhn7ctuVHDOvDcEy8KdBX3fYyrtXw5GgWDC5borG6yT1f3E9AXfRPL9OQjMTeC+G4FHscJAZjNnYav+jLrQLdV1xJ0JgbjRyBgTAfBszx9oKIjzCUPvpj4npju0WFGu10pIh0w7bluMoVn1tS6Y3gxE/Cepwt ci@ansible.hetzner.cloud"
|
||||
hcloud_doubled_ssh_key_fingerprint: "f9:33:40:ff:77:f3:3e:85:f2:9e:8f:98:71:fd:a0:58"
|
||||
|
|
|
@ -136,7 +136,7 @@
|
|||
- name: test fail cleanly on double created ssh key
|
||||
hcloud_ssh_key:
|
||||
name: "{{ hcloud_ssh_key_name }}othername"
|
||||
public_key: "{{ hcloud_ssh_key_public_key }}"
|
||||
public_key: "{{ hcloud_doubled_ssh_key_public_key }}"
|
||||
register: result
|
||||
ignore_errors: yes
|
||||
- name: verify failed correctly
|
||||
|
|
|
@ -2,4 +2,4 @@
|
|||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
---
|
||||
hcloud_prefix: "tests"
|
||||
hcloud_ssh_key_name: "{{hcloud_prefix}}-ssh_key_facts"
|
||||
hcloud_ssh_key_name: "{{hcloud_prefix}}-f"
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
---
|
||||
hcloud_prefix: "tests"
|
||||
hcloud_network_name: "{{hcloud_prefix}}-subnet"
|
||||
hcloud_network_name: "{{hcloud_prefix}}-s"
|
||||
hetzner_vswitch_id: 15311
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
---
|
||||
hcloud_prefix: "tests"
|
||||
hcloud_volume_name: "{{hcloud_prefix}}-integ"
|
||||
hcloud_server_name: "{{hcloud_prefix}}-volume-server"
|
||||
hcloud_volume_name: "{{hcloud_prefix}}-i"
|
||||
hcloud_server_name: "{{hcloud_prefix}}-vs"
|
||||
|
|
|
@ -2,4 +2,4 @@
|
|||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
---
|
||||
hcloud_prefix: "tests"
|
||||
hcloud_volume_name: "{{hcloud_prefix}}-facts"
|
||||
hcloud_volume_name: "{{hcloud_prefix}}-i"
|
||||
|
|
Loading…
Reference in a new issue