refactor: add future annotations imports (#398)

##### SUMMARY

This adds future annotations imports to benefit from the modern python
typing system.
This commit is contained in:
Jonas L 2023-11-23 14:53:10 +01:00 committed by GitHub
parent 9905bd0e01
commit df8c3b6a59
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
43 changed files with 275 additions and 126 deletions

View file

@ -24,3 +24,4 @@ exclude_paths:
warn_list:
- internal-error
- sanity[cannot-ignore]

View file

@ -7,6 +7,7 @@ Keep in mind that Azure Pipelines does not enforce unique job display names (onl
It is up to pipeline authors to avoid name collisions when deviating from the recommended format.
"""
from __future__ import annotations
import os
import re

View file

@ -1,6 +1,7 @@
#!/usr/bin/env python
"""Prepends a relative timestamp to each input line from stdin and writes it to stdout."""
from __future__ import annotations
import sys
import time

View file

@ -2,6 +2,9 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations
class ModuleDocFragment:
DOCUMENTATION = """
options:

View file

@ -1,6 +1,8 @@
# Copyright (c) 2019 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 annotations
DOCUMENTATION = r"""
name: hcloud
short_description: Ansible dynamic inventory plugin for the Hetzner Cloud.
@ -135,7 +137,6 @@ keyed_groups:
import os
import sys
from ipaddress import IPv6Network
from typing import List, Optional, Tuple
from ansible.errors import AnsibleError
from ansible.inventory.manager import InventoryData
@ -391,7 +392,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
"""Return the possibly of a file being consumable by this plugin."""
return super().verify_file(path) and path.endswith(("hcloud.yaml", "hcloud.yml"))
def _get_cached_result(self, path, cache) -> Tuple[List[Optional[InventoryServer]], bool]:
def _get_cached_result(self, path, cache) -> tuple[list[InventoryServer | None], bool]:
# false when refresh_cache or --flush-cache is used
if not cache:
return None, False
@ -409,7 +410,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
return cached_result, True
def _update_cached_result(self, path, cache, result: List[InventoryServer]):
def _update_cached_result(self, path, cache, result: list[InventoryServer]):
if not self.get_option("cache"):
return

View file

@ -3,8 +3,10 @@
# Simplified BSD License (see licenses/simplified_bsd.txt or https://opensource.org/licenses/BSD-2-Clause)
from __future__ import annotations
import traceback
from typing import Any, Dict, Optional, Union
from typing import Any
from ansible.module_utils.basic import (
AnsibleModule as AnsibleModuleBase,
@ -56,7 +58,7 @@ class AnsibleHCloud:
def fail_json_hcloud(
self,
exception: HCloudException,
msg: Optional[str] = None,
msg: str | None = None,
params: Any = None,
**kwargs,
) -> None:
@ -91,7 +93,7 @@ class AnsibleHCloud:
application_version=version,
)
def _client_get_by_name_or_id(self, resource: str, param: Union[str, int]):
def _client_get_by_name_or_id(self, resource: str, param: str | int):
"""
Get a resource by name, and if not found by its ID.
@ -132,11 +134,11 @@ class AnsibleHCloud:
},
}
def _prepare_result(self) -> Dict[str, Any]:
def _prepare_result(self) -> dict[str, Any]:
"""Prepare the result for every module"""
return {}
def get_result(self) -> Dict[str, Any]:
def get_result(self) -> dict[str, Any]:
if getattr(self, self.represent) is not None:
self.result[self.represent] = self._prepare_result()
return self.result

View file

@ -1 +1,3 @@
from __future__ import annotations
version = "2.3.0" # x-release-please-version

View file

@ -4,6 +4,8 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations
DOCUMENTATION = """
---
module: certificate
@ -143,8 +145,6 @@ hcloud_certificate:
type: dict
"""
from typing import Optional
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
@ -156,7 +156,7 @@ from ..module_utils.vendor.hcloud.certificates import BoundCertificate
class AnsibleHCloudCertificate(AnsibleHCloud):
represent = "hcloud_certificate"
hcloud_certificate: Optional[BoundCertificate] = None
hcloud_certificate: BoundCertificate | None = None
def _prepare_result(self):
return {
@ -264,7 +264,7 @@ class AnsibleHCloudCertificate(AnsibleHCloud):
"choices": ["absent", "present"],
"default": "present",
},
**super().base_module_arguments()
**super().base_module_arguments(),
),
required_one_of=[["id", "name"]],
required_if=[["state", "present", ["name"]]],

View file

@ -4,6 +4,8 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations
DOCUMENTATION = """
---
module: certificate_info
@ -83,7 +85,6 @@ hcloud_certificate_info:
returned: always
type: dict
"""
from typing import List, Optional
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
@ -96,7 +97,7 @@ from ..module_utils.vendor.hcloud.certificates import BoundCertificate
class AnsibleHCloudCertificateInfo(AnsibleHCloud):
represent = "hcloud_certificate_info"
hcloud_certificate_info: Optional[List[BoundCertificate]] = None
hcloud_certificate_info: list[BoundCertificate] | None = None
def _prepare_result(self):
certificates = []
@ -140,7 +141,7 @@ class AnsibleHCloudCertificateInfo(AnsibleHCloud):
id={"type": "int"},
name={"type": "str"},
label_selector={"type": "str"},
**super().base_module_arguments()
**super().base_module_arguments(),
),
supports_check_mode=True,
)

View file

@ -4,6 +4,8 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations
DOCUMENTATION = """
---
module: datacenter_info
@ -115,8 +117,6 @@ hcloud_datacenter_info:
sample: [1, 2, 3]
"""
from typing import List, Optional
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
@ -128,7 +128,7 @@ from ..module_utils.vendor.hcloud.datacenters import BoundDatacenter
class AnsibleHCloudDatacenterInfo(AnsibleHCloud):
represent = "hcloud_datacenter_info"
hcloud_datacenter_info: Optional[List[BoundDatacenter]] = None
hcloud_datacenter_info: list[BoundDatacenter] | None = None
def _prepare_result(self):
tmp = []

View file

@ -4,6 +4,8 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations
DOCUMENTATION = """
---
module: firewall
@ -167,7 +169,6 @@ hcloud_firewall:
"""
import time
from typing import Optional
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
@ -180,7 +181,7 @@ from ..module_utils.vendor.hcloud.firewalls import BoundFirewall, FirewallRule
class AnsibleHCloudFirewall(AnsibleHCloud):
represent = "hcloud_firewall"
hcloud_firewall: Optional[BoundFirewall] = None
hcloud_firewall: BoundFirewall | None = None
def _prepare_result(self):
return {
@ -324,7 +325,7 @@ class AnsibleHCloudFirewall(AnsibleHCloud):
"choices": ["absent", "present"],
"default": "present",
},
**super().base_module_arguments()
**super().base_module_arguments(),
),
required_one_of=[["id", "name"]],
required_if=[["state", "present", ["name"]]],

View file

@ -4,6 +4,8 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations
DOCUMENTATION = """
---
module: floating_ip
@ -157,8 +159,6 @@ hcloud_floating_ip:
mylabel: 123
"""
from typing import Optional
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
@ -170,7 +170,7 @@ from ..module_utils.vendor.hcloud.floating_ips import BoundFloatingIP
class AnsibleHCloudFloatingIP(AnsibleHCloud):
represent = "hcloud_floating_ip"
hcloud_floating_ip: Optional[BoundFloatingIP] = None
hcloud_floating_ip: BoundFloatingIP | None = None
def _prepare_result(self):
server = None

View file

@ -4,6 +4,8 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations
DOCUMENTATION = """
---
module: floating_ip_info
@ -97,8 +99,6 @@ hcloud_floating_ip_info:
type: dict
"""
from typing import List, Optional
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
@ -110,7 +110,7 @@ from ..module_utils.vendor.hcloud.floating_ips import BoundFloatingIP
class AnsibleHCloudFloatingIPInfo(AnsibleHCloud):
represent = "hcloud_floating_ip_info"
hcloud_floating_ip_info: Optional[List[BoundFloatingIP]] = None
hcloud_floating_ip_info: list[BoundFloatingIP] | None = None
def _prepare_result(self):
tmp = []

View file

@ -4,6 +4,8 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations
DOCUMENTATION = """
---
module: image_info
@ -109,8 +111,6 @@ hcloud_image_info:
type: dict
"""
from typing import List, Optional
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
@ -122,7 +122,7 @@ from ..module_utils.vendor.hcloud.images import BoundImage
class AnsibleHCloudImageInfo(AnsibleHCloud):
represent = "hcloud_image_info"
hcloud_image_info: Optional[List[BoundImage]] = None
hcloud_image_info: list[BoundImage] | None = None
def _prepare_result(self):
tmp = []
@ -188,7 +188,7 @@ class AnsibleHCloudImageInfo(AnsibleHCloud):
label_selector={"type": "str"},
type={"choices": ["system", "snapshot", "backup"], "default": "system", "type": "str"},
architecture={"choices": ["x86", "arm"], "type": "str"},
**super().base_module_arguments()
**super().base_module_arguments(),
),
supports_check_mode=True,
)

View file

@ -5,6 +5,8 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations
DOCUMENTATION = """
---
module: iso_info
@ -119,8 +121,6 @@ hcloud_iso_info:
sample: "2021-12-01T00:00:00+00:00"
"""
from typing import List, Optional
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
@ -132,7 +132,7 @@ from ..module_utils.vendor.hcloud.isos import BoundIso
class AnsibleHCloudIsoInfo(AnsibleHCloud):
represent = "hcloud_iso_info"
hcloud_iso_info: Optional[List[BoundIso]] = None
hcloud_iso_info: list[BoundIso] | None = None
def _prepare_result(self):
tmp = []

View file

@ -4,6 +4,8 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations
DOCUMENTATION = """
---
module: load_balancer
@ -149,8 +151,6 @@ hcloud_load_balancer:
sample: false
"""
from typing import Optional
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
@ -165,7 +165,7 @@ from ..module_utils.vendor.hcloud.load_balancers import (
class AnsibleHCloudLoadBalancer(AnsibleHCloud):
represent = "hcloud_load_balancer"
hcloud_load_balancer: Optional[BoundLoadBalancer] = None
hcloud_load_balancer: BoundLoadBalancer | None = None
def _prepare_result(self):
private_ipv4_address = (
@ -315,7 +315,7 @@ class AnsibleHCloudLoadBalancer(AnsibleHCloud):
"choices": ["absent", "present"],
"default": "present",
},
**super().base_module_arguments()
**super().base_module_arguments(),
),
required_one_of=[["id", "name"]],
mutually_exclusive=[["location", "network_zone"]],

View file

@ -4,6 +4,8 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations
DOCUMENTATION = """
---
module: load_balancer_info
@ -274,8 +276,6 @@ hcloud_load_balancer_info:
sample: false
"""
from typing import List, Optional
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
@ -287,7 +287,7 @@ from ..module_utils.vendor.hcloud.load_balancers import BoundLoadBalancer
class AnsibleHCloudLoadBalancerInfo(AnsibleHCloud):
represent = "hcloud_load_balancer_info"
hcloud_load_balancer_info: Optional[List[BoundLoadBalancer]] = None
hcloud_load_balancer_info: list[BoundLoadBalancer] | None = None
def _prepare_result(self):
tmp = []
@ -403,7 +403,7 @@ class AnsibleHCloudLoadBalancerInfo(AnsibleHCloud):
id={"type": "int"},
name={"type": "str"},
label_selector={"type": "str"},
**super().base_module_arguments()
**super().base_module_arguments(),
),
supports_check_mode=True,
)

View file

@ -4,6 +4,8 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations
DOCUMENTATION = """
---
module: load_balancer_network
@ -87,8 +89,6 @@ hcloud_load_balancer_network:
sample: 10.0.0.8
"""
from typing import Optional
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
@ -101,9 +101,9 @@ from ..module_utils.vendor.hcloud.networks import BoundNetwork
class AnsibleHCloudLoadBalancerNetwork(AnsibleHCloud):
represent = "hcloud_load_balancer_network"
hcloud_network: Optional[BoundNetwork] = None
hcloud_load_balancer: Optional[BoundLoadBalancer] = None
hcloud_load_balancer_network: Optional[PrivateNet] = None
hcloud_network: BoundNetwork | None = None
hcloud_load_balancer: BoundLoadBalancer | None = None
hcloud_load_balancer_network: PrivateNet | None = None
def _prepare_result(self):
return {

View file

@ -4,6 +4,8 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations
DOCUMENTATION = """
---
module: load_balancer_service
@ -276,8 +278,6 @@ hcloud_load_balancer_service:
sample: false
"""
from typing import Optional
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
@ -295,8 +295,8 @@ from ..module_utils.vendor.hcloud.load_balancers import (
class AnsibleHCloudLoadBalancerService(AnsibleHCloud):
represent = "hcloud_load_balancer_service"
hcloud_load_balancer: Optional[BoundLoadBalancer] = None
hcloud_load_balancer_service: Optional[LoadBalancerService] = None
hcloud_load_balancer: BoundLoadBalancer | None = None
hcloud_load_balancer_service: LoadBalancerService | None = None
def _prepare_result(self):
http = None

View file

@ -4,6 +4,8 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations
DOCUMENTATION = """
---
module: load_balancer_target
@ -131,8 +133,6 @@ hcloud_load_balancer_target:
returned: always
"""
from typing import Optional
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
@ -150,9 +150,9 @@ from ..module_utils.vendor.hcloud.servers import BoundServer
class AnsibleHCloudLoadBalancerTarget(AnsibleHCloud):
represent = "hcloud_load_balancer_target"
hcloud_load_balancer: Optional[BoundLoadBalancer] = None
hcloud_load_balancer_target: Optional[LoadBalancerTarget] = None
hcloud_server: Optional[BoundServer] = None
hcloud_load_balancer: BoundLoadBalancer | None = None
hcloud_load_balancer_target: LoadBalancerTarget | None = None
hcloud_server: BoundServer | None = None
def _prepare_result(self):
result = {

View file

@ -4,6 +4,8 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations
DOCUMENTATION = """
---
module: load_balancer_type_info
@ -85,8 +87,6 @@ hcloud_load_balancer_type_info:
sample: 5
"""
from typing import List, Optional
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
@ -98,7 +98,7 @@ from ..module_utils.vendor.hcloud.load_balancer_types import BoundLoadBalancerTy
class AnsibleHCloudLoadBalancerTypeInfo(AnsibleHCloud):
represent = "hcloud_load_balancer_type_info"
hcloud_load_balancer_type_info: Optional[List[BoundLoadBalancerType]] = None
hcloud_load_balancer_type_info: list[BoundLoadBalancerType] | None = None
def _prepare_result(self):
tmp = []

View file

@ -4,6 +4,8 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations
DOCUMENTATION = """
---
module: location_info
@ -75,8 +77,6 @@ hcloud_location_info:
sample: Falkenstein
"""
from typing import List, Optional
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
@ -88,7 +88,7 @@ from ..module_utils.vendor.hcloud.locations import BoundLocation
class AnsibleHCloudLocationInfo(AnsibleHCloud):
represent = "hcloud_location_info"
hcloud_location_info: Optional[List[BoundLocation]] = None
hcloud_location_info: list[BoundLocation] | None = None
def _prepare_result(self):
tmp = []

View file

@ -4,6 +4,8 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations
DOCUMENTATION = """
---
module: network
@ -112,8 +114,6 @@ hcloud_network:
mylabel: 123
"""
from typing import Optional
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
@ -125,7 +125,7 @@ from ..module_utils.vendor.hcloud.networks import BoundNetwork
class AnsibleHCloudNetwork(AnsibleHCloud):
represent = "hcloud_network"
hcloud_network: Optional[BoundNetwork] = None
hcloud_network: BoundNetwork | None = None
def _prepare_result(self):
return {
@ -235,7 +235,7 @@ class AnsibleHCloudNetwork(AnsibleHCloud):
"choices": ["absent", "present"],
"default": "present",
},
**super().base_module_arguments()
**super().base_module_arguments(),
),
required_one_of=[["id", "name"]],
supports_check_mode=True,

View file

@ -4,6 +4,8 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations
DOCUMENTATION = """
---
module: network_info
@ -182,8 +184,6 @@ hcloud_network_info:
type: dict
"""
from typing import List, Optional
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
@ -195,7 +195,7 @@ from ..module_utils.vendor.hcloud.networks import BoundNetwork
class AnsibleHCloudNetworkInfo(AnsibleHCloud):
represent = "hcloud_network_info"
hcloud_network_info: Optional[List[BoundNetwork]] = None
hcloud_network_info: list[BoundNetwork] | None = None
def _prepare_result(self):
tmp = []
@ -275,7 +275,7 @@ class AnsibleHCloudNetworkInfo(AnsibleHCloud):
id={"type": "int"},
name={"type": "str"},
label_selector={"type": "str"},
**super().base_module_arguments()
**super().base_module_arguments(),
),
supports_check_mode=True,
)

View file

@ -4,6 +4,8 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations
DOCUMENTATION = """
---
module: placement_group
@ -104,8 +106,6 @@ hcloud_placement_group:
- 4712
"""
from typing import Optional
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
@ -117,7 +117,7 @@ from ..module_utils.vendor.hcloud.placement_groups import BoundPlacementGroup
class AnsibleHCloudPlacementGroup(AnsibleHCloud):
represent = "hcloud_placement_group"
hcloud_placement_group: Optional[BoundPlacementGroup] = None
hcloud_placement_group: BoundPlacementGroup | None = None
def _prepare_result(self):
return {
@ -195,7 +195,7 @@ class AnsibleHCloudPlacementGroup(AnsibleHCloud):
"choices": ["absent", "present"],
"default": "present",
},
**super().base_module_arguments()
**super().base_module_arguments(),
),
required_one_of=[["id", "name"]],
required_if=[["state", "present", ["name"]]],

View file

@ -4,6 +4,8 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations
DOCUMENTATION = """
---
module: primary_ip
@ -127,8 +129,6 @@ hcloud_primary_ip:
mylabel: 123
"""
from typing import Optional
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
@ -140,7 +140,7 @@ from ..module_utils.vendor.hcloud.primary_ips import BoundPrimaryIP
class AnsibleHCloudPrimaryIP(AnsibleHCloud):
represent = "hcloud_primary_ip"
hcloud_primary_ip: Optional[BoundPrimaryIP] = None
hcloud_primary_ip: BoundPrimaryIP | None = None
def _prepare_result(self):
return {
@ -236,7 +236,7 @@ class AnsibleHCloudPrimaryIP(AnsibleHCloud):
"choices": ["absent", "present"],
"default": "present",
},
**super().base_module_arguments()
**super().base_module_arguments(),
),
required_one_of=[["id", "name"]],
supports_check_mode=True,

View file

@ -4,6 +4,8 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations
DOCUMENTATION = """
---
module: primary_ip_info
@ -117,8 +119,6 @@ hcloud_primary_ip_info:
type: bool
"""
from typing import List, Optional
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
@ -130,7 +130,7 @@ from ..module_utils.vendor.hcloud.primary_ips import BoundPrimaryIP
class AnsibleHCloudPrimaryIPInfo(AnsibleHCloud):
represent = "hcloud_primary_ip_info"
hcloud_primary_ip_info: Optional[List[BoundPrimaryIP]] = None
hcloud_primary_ip_info: list[BoundPrimaryIP] | None = None
def _prepare_result(self):
tmp = []
@ -182,7 +182,7 @@ class AnsibleHCloudPrimaryIPInfo(AnsibleHCloud):
id={"type": "int"},
label_selector={"type": "str"},
name={"type": "str"},
**super().base_module_arguments()
**super().base_module_arguments(),
),
supports_check_mode=True,
)

View file

@ -4,6 +4,8 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations
DOCUMENTATION = """
---
module: rdns
@ -130,7 +132,7 @@ hcloud_rdns:
sample: example.com
"""
from typing import Any, Dict, Optional, Union
from typing import Any
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
@ -149,8 +151,8 @@ from ..module_utils.vendor.hcloud.servers import BoundServer
class AnsibleHCloudReverseDNS(AnsibleHCloud):
represent = "hcloud_rdns"
hcloud_resource: Optional[Union[BoundServer, BoundFloatingIP, BoundLoadBalancer, BoundPrimaryIP]] = None
hcloud_rdns: Optional[Dict[str, Any]] = None
hcloud_resource: BoundServer | BoundFloatingIP | BoundLoadBalancer | BoundPrimaryIP | None = None
hcloud_rdns: dict[str, Any] | None = None
def _prepare_result(self):
result = {
@ -331,7 +333,7 @@ class AnsibleHCloudReverseDNS(AnsibleHCloud):
"choices": ["absent", "present"],
"default": "present",
},
**super().base_module_arguments()
**super().base_module_arguments(),
),
required_one_of=[["server", "floating_ip", "load_balancer", "primary_ip"]],
mutually_exclusive=[["server", "floating_ip", "load_balancer", "primary_ip"]],

View file

@ -4,6 +4,8 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations
DOCUMENTATION = """
---
module: route
@ -83,8 +85,6 @@ hcloud_route:
sample: 10.0.0.1
"""
from typing import Optional
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
@ -96,8 +96,8 @@ from ..module_utils.vendor.hcloud.networks import BoundNetwork, NetworkRoute
class AnsibleHCloudRoute(AnsibleHCloud):
represent = "hcloud_route"
hcloud_network: Optional[BoundNetwork] = None
hcloud_route: Optional[NetworkRoute] = None
hcloud_network: BoundNetwork | None = None
hcloud_route: NetworkRoute | None = None
def _prepare_result(self):
return {
@ -167,7 +167,7 @@ class AnsibleHCloudRoute(AnsibleHCloud):
"choices": ["absent", "present"],
"default": "present",
},
**super().base_module_arguments()
**super().base_module_arguments(),
),
supports_check_mode=True,
)

View file

@ -4,6 +4,8 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations
DOCUMENTATION = """
---
module: server
@ -334,7 +336,6 @@ hcloud_server:
"""
from datetime import datetime, timedelta, timezone
from typing import Optional
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
@ -354,7 +355,7 @@ from ..module_utils.vendor.hcloud.volumes import Volume
class AnsibleHCloudServer(AnsibleHCloud):
represent = "hcloud_server"
hcloud_server: Optional[BoundServer] = None
hcloud_server: BoundServer | None = None
def _prepare_result(self):
image = None if self.hcloud_server.image is None else to_native(self.hcloud_server.image.name)

View file

@ -4,6 +4,8 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations
DOCUMENTATION = """
---
module: server_info
@ -143,8 +145,6 @@ hcloud_server_info:
version_added: "0.1.0"
"""
from typing import List, Optional
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
@ -156,7 +156,7 @@ from ..module_utils.vendor.hcloud.servers import BoundServer
class AnsibleHCloudServerInfo(AnsibleHCloud):
represent = "hcloud_server_info"
hcloud_server_info: Optional[List[BoundServer]] = None
hcloud_server_info: list[BoundServer] | None = None
def _prepare_result(self):
tmp = []
@ -217,7 +217,7 @@ class AnsibleHCloudServerInfo(AnsibleHCloud):
id={"type": "int"},
name={"type": "str"},
label_selector={"type": "str"},
**super().base_module_arguments()
**super().base_module_arguments(),
),
supports_check_mode=True,
)

View file

@ -4,6 +4,8 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations
DOCUMENTATION = """
---
module: server_network
@ -108,8 +110,6 @@ hcloud_server_network:
sample: [10.1.0.1, ...]
"""
from typing import Optional
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
@ -122,9 +122,9 @@ from ..module_utils.vendor.hcloud.servers import BoundServer, PrivateNet
class AnsibleHCloudServerNetwork(AnsibleHCloud):
represent = "hcloud_server_network"
hcloud_network: Optional[BoundNetwork] = None
hcloud_server: Optional[BoundServer] = None
hcloud_server_network: Optional[PrivateNet] = None
hcloud_network: BoundNetwork | None = None
hcloud_server: BoundServer | None = None
hcloud_server_network: PrivateNet | None = None
def _prepare_result(self):
return {
@ -223,7 +223,7 @@ class AnsibleHCloudServerNetwork(AnsibleHCloud):
"choices": ["absent", "present"],
"default": "present",
},
**super().base_module_arguments()
**super().base_module_arguments(),
),
supports_check_mode=True,
)

View file

@ -4,6 +4,8 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations
DOCUMENTATION = """
---
module: server_type_info
@ -121,8 +123,6 @@ hcloud_server_type_info:
"""
from typing import List, Optional
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
@ -134,7 +134,7 @@ from ..module_utils.vendor.hcloud.server_types import BoundServerType
class AnsibleHCloudServerTypeInfo(AnsibleHCloud):
represent = "hcloud_server_type_info"
hcloud_server_type_info: Optional[List[BoundServerType]] = None
hcloud_server_type_info: list[BoundServerType] | None = None
def _prepare_result(self):
tmp = []

View file

@ -4,6 +4,8 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations
DOCUMENTATION = """
---
module: ssh_key
@ -110,8 +112,6 @@ hcloud_ssh_key:
mylabel: 123
"""
from typing import Optional
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
@ -123,7 +123,7 @@ from ..module_utils.vendor.hcloud.ssh_keys import BoundSSHKey
class AnsibleHCloudSSHKey(AnsibleHCloud):
represent = "hcloud_ssh_key"
hcloud_ssh_key: Optional[BoundSSHKey] = None
hcloud_ssh_key: BoundSSHKey | None = None
def _prepare_result(self):
return {
@ -209,7 +209,7 @@ class AnsibleHCloudSSHKey(AnsibleHCloud):
"choices": ["absent", "present"],
"default": "present",
},
**super().base_module_arguments()
**super().base_module_arguments(),
),
required_one_of=[["id", "name", "fingerprint"]],
required_if=[["state", "present", ["name"]]],

View file

@ -4,6 +4,8 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations
DOCUMENTATION = """
---
module: ssh_key_info
@ -75,7 +77,6 @@ hcloud_ssh_key_info:
returned: always
type: dict
"""
from typing import List, Optional
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
@ -88,7 +89,7 @@ from ..module_utils.vendor.hcloud.ssh_keys import BoundSSHKey
class AnsibleHCloudSSHKeyInfo(AnsibleHCloud):
represent = "hcloud_ssh_key_info"
hcloud_ssh_key_info: Optional[List[BoundSSHKey]] = None
hcloud_ssh_key_info: list[BoundSSHKey] | None = None
def _prepare_result(self):
ssh_keys = []
@ -134,7 +135,7 @@ class AnsibleHCloudSSHKeyInfo(AnsibleHCloud):
name={"type": "str"},
fingerprint={"type": "str"},
label_selector={"type": "str"},
**super().base_module_arguments()
**super().base_module_arguments(),
),
supports_check_mode=True,
)

View file

@ -4,6 +4,8 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations
DOCUMENTATION = """
---
module: subnetwork
@ -120,8 +122,6 @@ hcloud_subnetwork:
sample: 10.0.0.1
"""
from typing import Optional
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
@ -133,8 +133,8 @@ from ..module_utils.vendor.hcloud.networks import BoundNetwork, NetworkSubnet
class AnsibleHCloudSubnetwork(AnsibleHCloud):
represent = "hcloud_subnetwork"
hcloud_network: Optional[BoundNetwork] = None
hcloud_subnetwork: Optional[NetworkSubnet] = None
hcloud_network: BoundNetwork | None = None
hcloud_subnetwork: NetworkSubnet | None = None
def _prepare_result(self):
return {
@ -213,7 +213,7 @@ class AnsibleHCloudSubnetwork(AnsibleHCloud):
"choices": ["absent", "present"],
"default": "present",
},
**super().base_module_arguments()
**super().base_module_arguments(),
),
supports_check_mode=True,
)

View file

@ -4,6 +4,8 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations
DOCUMENTATION = """
---
module: volume
@ -157,8 +159,6 @@ hcloud_volume:
version_added: "0.1.0"
"""
from typing import Optional
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
@ -170,7 +170,7 @@ from ..module_utils.vendor.hcloud.volumes import BoundVolume
class AnsibleHCloudVolume(AnsibleHCloud):
represent = "hcloud_volume"
hcloud_volume: Optional[BoundVolume] = None
hcloud_volume: BoundVolume | None = None
def _prepare_result(self):
server_name = None
@ -305,7 +305,7 @@ class AnsibleHCloudVolume(AnsibleHCloud):
"choices": ["absent", "present"],
"default": "present",
},
**super().base_module_arguments()
**super().base_module_arguments(),
),
required_one_of=[["id", "name"]],
mutually_exclusive=[["location", "server"]],

View file

@ -4,6 +4,8 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations
DOCUMENTATION = """
---
module: volume_info
@ -92,8 +94,6 @@ hcloud_volume_info:
type: dict
"""
from typing import List, Optional
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
@ -105,7 +105,7 @@ from ..module_utils.vendor.hcloud.volumes import BoundVolume
class AnsibleHCloudVolumeInfo(AnsibleHCloud):
represent = "hcloud_volume_info"
hcloud_volume_info: Optional[List[BoundVolume]] = None
hcloud_volume_info: list[BoundVolume] | None = None
def _prepare_result(self):
tmp = []
@ -153,7 +153,7 @@ class AnsibleHCloudVolumeInfo(AnsibleHCloud):
id={"type": "int"},
name={"type": "str"},
label_selector={"type": "str"},
**super().base_module_arguments()
**super().base_module_arguments(),
),
supports_check_mode=True,
)

View file

@ -4,6 +4,7 @@ line-length = 120
[tool.isort]
profile = "black"
combine_as_imports = true
add_imports = ["from __future__ import annotations"]
[tool.pylint.main]
py-version = "3.8"

View file

@ -8,6 +8,8 @@ Fetch the desired version `HCLOUD_VERSION` from https://github.com/hetznercloud/
move the modified files at the vendor location `HCLOUD_VENDOR_PATH`.
"""
from __future__ import annotations
import logging
import re
from argparse import ArgumentParser

View file

@ -0,0 +1,64 @@
plugins/inventory/hcloud.py validate-modules:illegal-future-imports
plugins/inventory/hcloud.py validate-modules:import-before-documentation
plugins/modules/certificate_info.py validate-modules:illegal-future-imports
plugins/modules/certificate_info.py validate-modules:import-before-documentation
plugins/modules/certificate.py validate-modules:illegal-future-imports
plugins/modules/certificate.py validate-modules:import-before-documentation
plugins/modules/datacenter_info.py validate-modules:illegal-future-imports
plugins/modules/datacenter_info.py validate-modules:import-before-documentation
plugins/modules/firewall.py validate-modules:illegal-future-imports
plugins/modules/firewall.py validate-modules:import-before-documentation
plugins/modules/floating_ip_info.py validate-modules:illegal-future-imports
plugins/modules/floating_ip_info.py validate-modules:import-before-documentation
plugins/modules/floating_ip.py validate-modules:illegal-future-imports
plugins/modules/floating_ip.py validate-modules:import-before-documentation
plugins/modules/image_info.py validate-modules:illegal-future-imports
plugins/modules/image_info.py validate-modules:import-before-documentation
plugins/modules/iso_info.py validate-modules:illegal-future-imports
plugins/modules/iso_info.py validate-modules:import-before-documentation
plugins/modules/load_balancer_info.py validate-modules:illegal-future-imports
plugins/modules/load_balancer_info.py validate-modules:import-before-documentation
plugins/modules/load_balancer_network.py validate-modules:illegal-future-imports
plugins/modules/load_balancer_network.py validate-modules:import-before-documentation
plugins/modules/load_balancer_service.py validate-modules:illegal-future-imports
plugins/modules/load_balancer_service.py validate-modules:import-before-documentation
plugins/modules/load_balancer_target.py validate-modules:illegal-future-imports
plugins/modules/load_balancer_target.py validate-modules:import-before-documentation
plugins/modules/load_balancer_type_info.py validate-modules:illegal-future-imports
plugins/modules/load_balancer_type_info.py validate-modules:import-before-documentation
plugins/modules/load_balancer.py validate-modules:illegal-future-imports
plugins/modules/load_balancer.py validate-modules:import-before-documentation
plugins/modules/location_info.py validate-modules:illegal-future-imports
plugins/modules/location_info.py validate-modules:import-before-documentation
plugins/modules/network_info.py validate-modules:illegal-future-imports
plugins/modules/network_info.py validate-modules:import-before-documentation
plugins/modules/network.py validate-modules:illegal-future-imports
plugins/modules/network.py validate-modules:import-before-documentation
plugins/modules/placement_group.py validate-modules:illegal-future-imports
plugins/modules/placement_group.py validate-modules:import-before-documentation
plugins/modules/primary_ip_info.py validate-modules:illegal-future-imports
plugins/modules/primary_ip_info.py validate-modules:import-before-documentation
plugins/modules/primary_ip.py validate-modules:illegal-future-imports
plugins/modules/primary_ip.py validate-modules:import-before-documentation
plugins/modules/rdns.py validate-modules:illegal-future-imports
plugins/modules/rdns.py validate-modules:import-before-documentation
plugins/modules/route.py validate-modules:illegal-future-imports
plugins/modules/route.py validate-modules:import-before-documentation
plugins/modules/server_info.py validate-modules:illegal-future-imports
plugins/modules/server_info.py validate-modules:import-before-documentation
plugins/modules/server_network.py validate-modules:illegal-future-imports
plugins/modules/server_network.py validate-modules:import-before-documentation
plugins/modules/server_type_info.py validate-modules:illegal-future-imports
plugins/modules/server_type_info.py validate-modules:import-before-documentation
plugins/modules/server.py validate-modules:illegal-future-imports
plugins/modules/server.py validate-modules:import-before-documentation
plugins/modules/ssh_key_info.py validate-modules:illegal-future-imports
plugins/modules/ssh_key_info.py validate-modules:import-before-documentation
plugins/modules/ssh_key.py validate-modules:illegal-future-imports
plugins/modules/ssh_key.py validate-modules:import-before-documentation
plugins/modules/subnetwork.py validate-modules:illegal-future-imports
plugins/modules/subnetwork.py validate-modules:import-before-documentation
plugins/modules/volume_info.py validate-modules:illegal-future-imports
plugins/modules/volume_info.py validate-modules:import-before-documentation
plugins/modules/volume.py validate-modules:illegal-future-imports
plugins/modules/volume.py validate-modules:import-before-documentation

View file

@ -0,0 +1,63 @@
plugins/inventory/hcloud.py validate-modules:illegal-future-imports
plugins/modules/certificate_info.py validate-modules:illegal-future-imports
plugins/modules/certificate_info.py validate-modules:import-before-documentation
plugins/modules/certificate.py validate-modules:illegal-future-imports
plugins/modules/certificate.py validate-modules:import-before-documentation
plugins/modules/datacenter_info.py validate-modules:illegal-future-imports
plugins/modules/datacenter_info.py validate-modules:import-before-documentation
plugins/modules/firewall.py validate-modules:illegal-future-imports
plugins/modules/firewall.py validate-modules:import-before-documentation
plugins/modules/floating_ip_info.py validate-modules:illegal-future-imports
plugins/modules/floating_ip_info.py validate-modules:import-before-documentation
plugins/modules/floating_ip.py validate-modules:illegal-future-imports
plugins/modules/floating_ip.py validate-modules:import-before-documentation
plugins/modules/image_info.py validate-modules:illegal-future-imports
plugins/modules/image_info.py validate-modules:import-before-documentation
plugins/modules/iso_info.py validate-modules:illegal-future-imports
plugins/modules/iso_info.py validate-modules:import-before-documentation
plugins/modules/load_balancer_info.py validate-modules:illegal-future-imports
plugins/modules/load_balancer_info.py validate-modules:import-before-documentation
plugins/modules/load_balancer_network.py validate-modules:illegal-future-imports
plugins/modules/load_balancer_network.py validate-modules:import-before-documentation
plugins/modules/load_balancer_service.py validate-modules:illegal-future-imports
plugins/modules/load_balancer_service.py validate-modules:import-before-documentation
plugins/modules/load_balancer_target.py validate-modules:illegal-future-imports
plugins/modules/load_balancer_target.py validate-modules:import-before-documentation
plugins/modules/load_balancer_type_info.py validate-modules:illegal-future-imports
plugins/modules/load_balancer_type_info.py validate-modules:import-before-documentation
plugins/modules/load_balancer.py validate-modules:illegal-future-imports
plugins/modules/load_balancer.py validate-modules:import-before-documentation
plugins/modules/location_info.py validate-modules:illegal-future-imports
plugins/modules/location_info.py validate-modules:import-before-documentation
plugins/modules/network_info.py validate-modules:illegal-future-imports
plugins/modules/network_info.py validate-modules:import-before-documentation
plugins/modules/network.py validate-modules:illegal-future-imports
plugins/modules/network.py validate-modules:import-before-documentation
plugins/modules/placement_group.py validate-modules:illegal-future-imports
plugins/modules/placement_group.py validate-modules:import-before-documentation
plugins/modules/primary_ip_info.py validate-modules:illegal-future-imports
plugins/modules/primary_ip_info.py validate-modules:import-before-documentation
plugins/modules/primary_ip.py validate-modules:illegal-future-imports
plugins/modules/primary_ip.py validate-modules:import-before-documentation
plugins/modules/rdns.py validate-modules:illegal-future-imports
plugins/modules/rdns.py validate-modules:import-before-documentation
plugins/modules/route.py validate-modules:illegal-future-imports
plugins/modules/route.py validate-modules:import-before-documentation
plugins/modules/server_info.py validate-modules:illegal-future-imports
plugins/modules/server_info.py validate-modules:import-before-documentation
plugins/modules/server_network.py validate-modules:illegal-future-imports
plugins/modules/server_network.py validate-modules:import-before-documentation
plugins/modules/server_type_info.py validate-modules:illegal-future-imports
plugins/modules/server_type_info.py validate-modules:import-before-documentation
plugins/modules/server.py validate-modules:illegal-future-imports
plugins/modules/server.py validate-modules:import-before-documentation
plugins/modules/ssh_key_info.py validate-modules:illegal-future-imports
plugins/modules/ssh_key_info.py validate-modules:import-before-documentation
plugins/modules/ssh_key.py validate-modules:illegal-future-imports
plugins/modules/ssh_key.py validate-modules:import-before-documentation
plugins/modules/subnetwork.py validate-modules:illegal-future-imports
plugins/modules/subnetwork.py validate-modules:import-before-documentation
plugins/modules/volume_info.py validate-modules:illegal-future-imports
plugins/modules/volume_info.py validate-modules:import-before-documentation
plugins/modules/volume.py validate-modules:illegal-future-imports
plugins/modules/volume.py validate-modules:import-before-documentation

View file

@ -1,3 +1,5 @@
from __future__ import annotations
import traceback
from datetime import datetime, timezone
from unittest.mock import MagicMock