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

fix: add backward compatible datacenter name handling

This commit is contained in:
jo 2025-12-19 18:36:05 +01:00
parent 27f9a730d5
commit 32cec4523e
No known key found for this signature in database
GPG key ID: B2FEC9B22722B984
2 changed files with 14 additions and 3 deletions

View file

@ -231,7 +231,10 @@ class AnsiblePrimaryIP(AnsibleHCloud):
"after 1 July 2026. Please use the `location` argument instead. "
"See https://docs.hetzner.cloud/changelog#2025-12-16-phasing-out-datacenters."
)
params["datacenter"] = self.client.datacenters.get_by_name(value)
# Backward compatible datacenter argument.
# datacenter hel1-dc2 => location hel1
part1, _, _ = str(value).partition("-")
params["location"] = self.client.locations.get_by_name(part1)
elif (value := self.module.params.get("server")) is not None:
server: BoundServer = self._client_get_by_name_or_id("servers", value)
params["assignee_id"] = server.id

View file

@ -482,8 +482,16 @@ class AnsibleHCloudServer(AnsibleHCloud):
"after 1 July 2026. Please use the `location` argument instead. "
"See https://docs.hetzner.cloud/changelog#2025-12-16-phasing-out-datacenters."
)
params["datacenter"] = self._client_get_by_name_or_id("datacenters", self.module.params.get("datacenter"))
server_type_location = params["datacenter"].location
value: str = self.module.params.get("datacenter")
# Backward compatible datacenter argument.
# datacenter hel1-dc2 => location hel1
if value and not value.isdigit():
part1, _, _ = value.partition("-")
params["location"] = self.client.locations.get_by_name(part1)
server_type_location = params["location"]
else:
params["datacenter"] = self._client_get_by_name_or_id("datacenters", value)
server_type_location = params["datacenter"].location
if self.module.params.get("state") == "stopped" or self.module.params.get("state") == "created":
params["start_after_create"] = False