mirror of
https://github.com/ansible-collections/hetzner.hcloud.git
synced 2026-02-04 08:01:49 +00:00
chore: setup pre-commit (#234)
* chore: add pre-commit config * chore: fix pre-commit errors * chore: add black pre-commit hook * style: format python files with black * chore: add isort pre-commit hook * style: format python files using isort * chore: add pyupgrade pre-commit hook * refactor: upgrade code to python3.7 * Allow stacking PRs Co-authored-by: Julian Tölle <julian.toelle97@gmail.com> --------- Co-authored-by: Julian Tölle <julian.toelle97@gmail.com>
This commit is contained in:
parent
e83997517d
commit
dfff49e31f
42 changed files with 904 additions and 1091 deletions
|
|
@ -1,14 +1,10 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright: (c) 2020, Hetzner Cloud GmbH <info@hetzner-cloud.de>
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
|
||||
__metaclass__ = type
|
||||
|
||||
DOCUMENTATION = '''
|
||||
DOCUMENTATION = """
|
||||
---
|
||||
module: hcloud_load_balancer
|
||||
|
||||
|
|
@ -71,7 +67,7 @@ extends_documentation_fragment:
|
|||
|
||||
requirements:
|
||||
- hcloud-python >= 1.8.0
|
||||
'''
|
||||
"""
|
||||
|
||||
EXAMPLES = """
|
||||
- name: Create a basic Load Balancer
|
||||
|
|
@ -145,8 +141,8 @@ hcloud_load_balancer:
|
|||
sample: false
|
||||
"""
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils._text import to_native
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible_collections.hetzner.hcloud.plugins.module_utils.hcloud import Hcloud
|
||||
|
||||
|
||||
|
|
@ -156,8 +152,11 @@ class AnsibleHcloudLoadBalancer(Hcloud):
|
|||
self.hcloud_load_balancer = None
|
||||
|
||||
def _prepare_result(self):
|
||||
private_ipv4_address = None if len(self.hcloud_load_balancer.private_net) == 0 else to_native(
|
||||
self.hcloud_load_balancer.private_net[0].ip)
|
||||
private_ipv4_address = (
|
||||
None
|
||||
if len(self.hcloud_load_balancer.private_net) == 0
|
||||
else to_native(self.hcloud_load_balancer.private_net[0].ip)
|
||||
)
|
||||
return {
|
||||
"id": to_native(self.hcloud_load_balancer.id),
|
||||
"name": to_native(self.hcloud_load_balancer.name),
|
||||
|
|
@ -174,21 +173,14 @@ class AnsibleHcloudLoadBalancer(Hcloud):
|
|||
def _get_load_balancer(self):
|
||||
try:
|
||||
if self.module.params.get("id") is not None:
|
||||
self.hcloud_load_balancer = self.client.load_balancers.get_by_id(
|
||||
self.module.params.get("id")
|
||||
)
|
||||
self.hcloud_load_balancer = self.client.load_balancers.get_by_id(self.module.params.get("id"))
|
||||
else:
|
||||
self.hcloud_load_balancer = self.client.load_balancers.get_by_name(
|
||||
self.module.params.get("name")
|
||||
)
|
||||
self.hcloud_load_balancer = self.client.load_balancers.get_by_name(self.module.params.get("name"))
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
||||
def _create_load_balancer(self):
|
||||
|
||||
self.module.fail_on_missing_params(
|
||||
required_params=["name", "load_balancer_type"]
|
||||
)
|
||||
self.module.fail_on_missing_params(required_params=["name", "load_balancer_type"])
|
||||
try:
|
||||
params = {
|
||||
"name": self.module.params.get("name"),
|
||||
|
|
@ -201,9 +193,7 @@ class AnsibleHcloudLoadBalancer(Hcloud):
|
|||
if self.module.params.get("location") is None and self.module.params.get("network_zone") is None:
|
||||
self.module.fail_json(msg="one of the following is required: location, network_zone")
|
||||
elif self.module.params.get("location") is not None and self.module.params.get("network_zone") is None:
|
||||
params["location"] = self.client.locations.get_by_name(
|
||||
self.module.params.get("location")
|
||||
)
|
||||
params["location"] = self.client.locations.get_by_name(self.module.params.get("location"))
|
||||
elif self.module.params.get("location") is None and self.module.params.get("network_zone") is not None:
|
||||
params["network_zone"] = self.module.params.get("network_zone")
|
||||
|
||||
|
|
@ -236,7 +226,9 @@ class AnsibleHcloudLoadBalancer(Hcloud):
|
|||
self._get_load_balancer()
|
||||
|
||||
disable_public_interface = self.module.params.get("disable_public_interface")
|
||||
if disable_public_interface is not None and disable_public_interface != (not self.hcloud_load_balancer.public_net.enabled):
|
||||
if disable_public_interface is not None and disable_public_interface != (
|
||||
not self.hcloud_load_balancer.public_net.enabled
|
||||
):
|
||||
if not self.module.check_mode:
|
||||
if disable_public_interface is True:
|
||||
self.hcloud_load_balancer.disable_public_interface().wait_until_finished()
|
||||
|
|
@ -245,7 +237,10 @@ class AnsibleHcloudLoadBalancer(Hcloud):
|
|||
self._mark_as_changed()
|
||||
|
||||
load_balancer_type = self.module.params.get("load_balancer_type")
|
||||
if load_balancer_type is not None and self.hcloud_load_balancer.load_balancer_type.name != load_balancer_type:
|
||||
if (
|
||||
load_balancer_type is not None
|
||||
and self.hcloud_load_balancer.load_balancer_type.name != load_balancer_type
|
||||
):
|
||||
new_load_balancer_type = self.client.load_balancer_types.get_by_name(load_balancer_type)
|
||||
if not new_load_balancer_type:
|
||||
self.module.fail_json(msg="unknown load balancer type")
|
||||
|
|
@ -295,7 +290,7 @@ class AnsibleHcloudLoadBalancer(Hcloud):
|
|||
},
|
||||
**Hcloud.base_module_arguments()
|
||||
),
|
||||
required_one_of=[['id', 'name']],
|
||||
required_one_of=[["id", "name"]],
|
||||
mutually_exclusive=[["location", "network_zone"]],
|
||||
supports_check_mode=True,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue