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

fix: also check server type deprecation after server creation (#696)

##### SUMMARY

Because the location of a server is not mandatory for creating a server,
we must also check server type deprecation after server creation.

##### ISSUE TYPE

- Bugfix Pull Request


##### COMPONENT NAME
server
This commit is contained in:
Jonas L. 2025-09-29 14:34:54 +02:00 committed by GitHub
parent 2864379079
commit c4dc19c675
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 7 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- server - Also check server type deprecation after server creation.

View file

@ -18,7 +18,7 @@ def deprecated_server_type_warning(
module: AnsibleModule, module: AnsibleModule,
server_type: BoundServerType, server_type: BoundServerType,
location: BoundLocation | None = None, location: BoundLocation | None = None,
) -> None: ) -> bool:
with warnings.catch_warnings(): with warnings.catch_warnings():
warnings.simplefilter("ignore") warnings.simplefilter("ignore")
if server_type.deprecation is not None: if server_type.deprecation is not None:
@ -40,7 +40,7 @@ def deprecated_server_type_warning(
) )
+ DEPRECATED_EXISTING_SERVERS, + DEPRECATED_EXISTING_SERVERS,
) )
return return True
deprecated_locations: list[ServerTypeLocation] = [] deprecated_locations: list[ServerTypeLocation] = []
unavailable_locations: list[ServerTypeLocation] = [] unavailable_locations: list[ServerTypeLocation] = []
@ -52,13 +52,13 @@ def deprecated_server_type_warning(
unavailable_locations.append(o) unavailable_locations.append(o)
if not deprecated_locations: if not deprecated_locations:
return return False
# Warn when the server type is deprecated in the given location # Warn when the server type is deprecated in the given location
if location: if location:
found = [o for o in deprecated_locations if location.name == o.location.name] found = [o for o in deprecated_locations if location.name == o.location.name]
if not found: if not found:
return return False
deprecated_location = found[0] deprecated_location = found[0]
@ -83,11 +83,11 @@ def deprecated_server_type_warning(
+ DEPRECATED_EXISTING_SERVERS, + DEPRECATED_EXISTING_SERVERS,
) )
return return True
# No location given, only warn when all locations are deprecated # No location given, only warn when all locations are deprecated
if len(server_type.locations) != len(deprecated_locations): if len(server_type.locations) != len(deprecated_locations):
return return False
if unavailable_locations: if unavailable_locations:
@ -122,3 +122,5 @@ def deprecated_server_type_warning(
) )
+ DEPRECATED_EXISTING_SERVERS, + DEPRECATED_EXISTING_SERVERS,
) )
return True

View file

@ -475,7 +475,7 @@ class AnsibleHCloudServer(AnsibleHCloud):
if self.module.params.get("state") == "stopped" or self.module.params.get("state") == "created": if self.module.params.get("state") == "stopped" or self.module.params.get("state") == "created":
params["start_after_create"] = False params["start_after_create"] = False
deprecated_server_type_warning( server_type_deprecation_printed = deprecated_server_type_warning(
self.module, self.module,
server_type, server_type,
server_type_location, server_type_location,
@ -484,6 +484,14 @@ class AnsibleHCloudServer(AnsibleHCloud):
if not self.module.check_mode: if not self.module.check_mode:
try: try:
resp = self.client.servers.create(**params) resp = self.client.servers.create(**params)
if not server_type_deprecation_printed:
deprecated_server_type_warning(
self.module,
resp.server.server_type,
resp.server.datacenter.location,
)
self.result["root_password"] = resp.root_password self.result["root_password"] = resp.root_password
# Action should take 60 to 90 seconds on average, but can be >10m when creating a # Action should take 60 to 90 seconds on average, but can be >10m when creating a
# server from a custom images # server from a custom images