Skip to content

Commit

Permalink
docs: use argument spec to mark force_upgrade as deprecated (ansibl…
Browse files Browse the repository at this point in the history
…e-collections#481)

##### SUMMARY

Leverage the alias feature from the argument spec, and re-declare the
deprecation of the `force_upgrade` argument.
  • Loading branch information
jooola authored Apr 4, 2024
1 parent 1d95b85 commit 022cca4
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions plugins/modules/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,13 @@
if it has any other value (including []), only those networks are attached to the server.
type: list
elements: str
force_upgrade:
description:
- Deprecated
- Force the upgrade of the server.
- Power off the server if it is running on upgrade.
type: bool
force:
description:
- Force the update of the server.
- May power off the server if update.
type: bool
default: false
aliases: [force_upgrade]
allow_deprecated_image:
description:
- Allows the creation of servers with deprecated images.
Expand Down Expand Up @@ -589,9 +584,6 @@ def _get_primary_ip(self, field):
return primary_ip

def _update_server(self):
if "force_upgrade" in self.module.params and self.module.params.get("force_upgrade") is not None:
self.module.warn("force_upgrade is deprecated, use force instead")

try:
previous_server_status = self.hcloud_server.status

Expand Down Expand Up @@ -825,18 +817,14 @@ def stop_server(self):
def stop_server_if_forced(self):
previous_server_status = self.hcloud_server.status
if previous_server_status == Server.STATUS_RUNNING and not self.module.check_mode:
if (
self.module.params.get("force_upgrade")
or self.module.params.get("force")
or self.module.params.get("state") == "stopped"
):
if self.module.params.get("force") or self.module.params.get("state") == "stopped":
self.stop_server() # Only stopped server can be upgraded
return previous_server_status
else:
self.module.warn(
f"You can not upgrade a running instance {self.hcloud_server.name}. "
"You need to stop the instance or use force=true."
)

self.module.warn(
f"You can not upgrade a running instance {self.hcloud_server.name}. "
"You need to stop the instance or use force=true."
)

return None

Expand Down Expand Up @@ -894,8 +882,14 @@ def define_module(cls):
ipv4={"type": "str"},
ipv6={"type": "str"},
private_networks={"type": "list", "elements": "str", "default": None},
force={"type": "bool", "default": False},
force_upgrade={"type": "bool"},
force={
"type": "bool",
"default": False,
"aliases": ["force_upgrade"],
"deprecated_aliases": [
{"collection_name": "hetzner.hcloud", "name": "force_upgrade", "version": "4.0.0"}
],
},
allow_deprecated_image={"type": "bool", "default": False},
rescue_mode={"type": "str"},
delete_protection={"type": "bool"},
Expand Down

0 comments on commit 022cca4

Please sign in to comment.