1
0
Fork 0
mirror of https://github.com/ansible-collections/hetzner.hcloud.git synced 2026-02-04 08:01:49 +00:00

chore(deps): update dependency hcloud to v2.10.0 (#728)

This commit is contained in:
renovate[bot] 2025-11-10 10:23:01 +01:00 committed by GitHub
parent 008045092e
commit 871bc897bf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 75 additions and 38 deletions

View file

View file

@ -5,6 +5,8 @@ from typing import Literal
from ansible.errors import AnsibleFilterError
from ansible.module_utils.common.text.converters import to_native
from ..module_utils.vendor.hcloud.exp.zone import format_txt_record
# pylint: disable=unused-argument
def load_balancer_status(load_balancer: dict, *args, **kwargs) -> Literal["unknown", "unhealthy", "healthy"]:
@ -50,18 +52,11 @@ def load_balancer_status(load_balancer: dict, *args, **kwargs) -> Literal["unkno
# pylint: disable=unused-argument
def txt_record(record: str, *args, **kwargs) -> str:
"""
Return the status of a Load Balancer based on its targets.
Format a TXT record by splitting it in quoted strings of 255 characters.
Existing quotes will be escaped.
"""
try:
record = record.replace('"', '\\"')
parts = []
for start in range(0, len(record), 255):
end = min(start + 255, len(record))
parts.append('"' + record[start:end] + '"')
record = " ".join(parts)
return record
return format_txt_record(record)
except Exception as exc:
raise AnsibleFilterError(f"txt_record - {to_native(exc)}", orig_exc=exc) from exc

View file

@ -1,3 +1,3 @@
from __future__ import annotations
__version__ = "2.9.0" # x-releaser-pleaser-version
__version__ = "2.10.0" # x-releaser-pleaser-version

View file

@ -0,0 +1,4 @@
"""
The `exp` module is a namespace that holds experimental features for the `hcloud-python`
library, breaking changes may occur within minor releases.
"""

View file

@ -0,0 +1,35 @@
"""
The `exp.zone` module is a namespace that holds experimental features for the `hcloud-python`
library, breaking changes may occur within minor releases.
"""
from __future__ import annotations
def is_txt_record_quoted(value: str) -> bool:
"""
Check whether a TXT record is already quoted.
- hello world => false
- "hello world" => true
"""
return value.startswith('"') and value.endswith('"')
def format_txt_record(value: str) -> str:
"""
Format a TXT record by splitting it in quoted strings of 255 characters.
Existing quotes will be escaped.
- hello world => "hello world"
- hello "world" => "hello \"world\""
"""
value = value.replace('"', '\\"')
parts = []
for start in range(0, len(value), 255):
end = min(start + 255, len(value))
parts.append('"' + value[start:end] + '"')
value = " ".join(parts)
return value

View file

@ -16,7 +16,7 @@ if TYPE_CHECKING:
from ..load_balancer_types import BoundLoadBalancerType
from ..locations import BoundLocation
from ..metrics import Metrics
from ..networks import BoundNetwork
from ..networks import BoundNetwork, Network
from ..servers import BoundServer
from .client import BoundLoadBalancer
@ -110,6 +110,16 @@ class LoadBalancer(BaseDomain, DomainIdentityMixin):
self.ingoing_traffic = ingoing_traffic
self.included_traffic = included_traffic
def private_net_for(self, network: BoundNetwork | Network) -> PrivateNet | None:
"""
Returns the load balancer's network attachment information in the given Network,
and None if no attachment was found.
"""
for o in self.private_net or []:
if o.network.id == network.id:
return o
return None
class LoadBalancerService(BaseDomain):
"""LoadBalancerService Domain

View file

@ -17,7 +17,7 @@ if TYPE_CHECKING:
from ..images import BoundImage
from ..isos import BoundIso
from ..metrics import Metrics
from ..networks import BoundNetwork
from ..networks import BoundNetwork, Network
from ..placement_groups import BoundPlacementGroup
from ..primary_ips import BoundPrimaryIP, PrimaryIP
from ..server_types import BoundServerType
@ -157,6 +157,16 @@ class Server(BaseDomain, DomainIdentityMixin):
self.primary_disk_size = primary_disk_size
self.placement_group = placement_group
def private_net_for(self, network: BoundNetwork | Network) -> PrivateNet | None:
"""
Returns the server's network attachment information in the given Network,
and None if no attachment was found.
"""
for o in self.private_net or []:
if o.network.id == network.id:
return o
return None
class CreateServerResponse(BaseDomain):
"""Create Server Response Domain

View file

@ -127,6 +127,8 @@ class AnsibleHCloudLoadBalancerNetwork(AnsibleHCloud):
def _get_load_balancer_and_network(self):
try:
self.hcloud_load_balancer_network = None
self.hcloud_network = self._client_get_by_name_or_id(
"networks",
self.module.params.get("network"),
@ -135,17 +137,10 @@ class AnsibleHCloudLoadBalancerNetwork(AnsibleHCloud):
"load_balancers",
self.module.params.get("load_balancer"),
)
self.hcloud_load_balancer_network = None
self.hcloud_load_balancer_network = self.hcloud_load_balancer.private_net_for(self.hcloud_network)
except HCloudException as exception:
self.fail_json_hcloud(exception)
def _get_load_balancer_network(self):
self.hcloud_load_balancer_network = None
for private_net in self.hcloud_load_balancer.private_net:
if private_net.network.id == self.hcloud_network.id:
self.hcloud_load_balancer_network = private_net
def _attach(self):
params = {
"network": self.hcloud_network,
@ -185,7 +180,6 @@ class AnsibleHCloudLoadBalancerNetwork(AnsibleHCloud):
self._attach()
self._get_load_balancer_and_network()
self._get_load_balancer_network()
def _update_load_balancer_network(self):
ip_range = self.module.params.get("ip_range")
@ -202,12 +196,10 @@ class AnsibleHCloudLoadBalancerNetwork(AnsibleHCloud):
# No further updates needed, exit
self._get_load_balancer_and_network()
self._get_load_balancer_network()
return
def present_load_balancer_network(self):
self._get_load_balancer_and_network()
self._get_load_balancer_network()
if self.hcloud_load_balancer_network is None:
self._create_load_balancer_network()
else:
@ -215,7 +207,6 @@ class AnsibleHCloudLoadBalancerNetwork(AnsibleHCloud):
def delete_load_balancer_network(self):
self._get_load_balancer_and_network()
self._get_load_balancer_network()
if self.hcloud_load_balancer_network is not None and self.hcloud_load_balancer is not None:
self._detach()
self.hcloud_load_balancer_network = None
@ -230,7 +221,7 @@ class AnsibleHCloudLoadBalancerNetwork(AnsibleHCloud):
# pylint: disable=disallowed-name
for _ in range(10):
self.hcloud_load_balancer.reload()
self._get_load_balancer_network()
self.hcloud_load_balancer_network = self.hcloud_load_balancer.private_net_for(self.hcloud_network)
if done(self.hcloud_load_balancer_network):
break

View file

@ -148,6 +148,8 @@ class AnsibleHCloudServerNetwork(AnsibleHCloud):
def _get_server_and_network(self):
try:
self.hcloud_server_network = None
self.hcloud_network = self._client_get_by_name_or_id(
"networks",
self.module.params.get("network"),
@ -156,15 +158,10 @@ class AnsibleHCloudServerNetwork(AnsibleHCloud):
"servers",
self.module.params.get("server"),
)
self.hcloud_server_network = None
self.hcloud_server_network = self.hcloud_server.private_net_for(self.hcloud_network)
except HCloudException as exception:
self.fail_json_hcloud(exception)
def _get_server_network(self):
for private_net in self.hcloud_server.private_net:
if private_net.network.id == self.hcloud_network.id:
self.hcloud_server_network = private_net
def _attach(self):
params = {
"network": self.hcloud_network,
@ -199,7 +196,6 @@ class AnsibleHCloudServerNetwork(AnsibleHCloud):
def _create_server_network(self):
self._attach()
self._get_server_and_network()
self._get_server_network()
def _update_server_network(self):
ip_range = self.module.params.get("ip_range")
@ -216,7 +212,6 @@ class AnsibleHCloudServerNetwork(AnsibleHCloud):
# No further updates needed, exit
self._get_server_and_network()
self._get_server_network()
return
params = {
@ -236,11 +231,9 @@ class AnsibleHCloudServerNetwork(AnsibleHCloud):
self._mark_as_changed()
self._get_server_and_network()
self._get_server_network()
def present_server_network(self):
self._get_server_and_network()
self._get_server_network()
if self.hcloud_server_network is None:
self._create_server_network()
else:
@ -248,7 +241,6 @@ class AnsibleHCloudServerNetwork(AnsibleHCloud):
def delete_server_network(self):
self._get_server_and_network()
self._get_server_network()
if self.hcloud_server_network is not None and self.hcloud_server is not None:
self._detach()
self.hcloud_server_network = None