-
Notifications
You must be signed in to change notification settings - Fork 46
Description
Bug Report
I'm not exactly sure whether this is a bug in the API client or rather in the backend service.
Current Behavior
Before rescaling a server, it needs to be shut down. However, issuing a rescale request directly after the shutdown has completed will still lead to an APIException: server must be stopped before changing type (server_not_stopped). If you check the server's status after the shutdown action completes, it's still running for several seconds.
Input Code
server = client.servers.get_by_name("bojack")
action = server.shutdown()
action.wait_until_finished()
# Now, action.finished has a timestamp, i.e. the action has been completed.
# We should be able to do this now:
server.change_type(server_type="cax31", upgrade_disk=False)
# But it'll throw a "server_not_stopped" exception instead.Expected behavior/code
I should be able to issue the change_type request instantly after wait_until_finished() has returned. But I can't. The only option that's left for me at this point is to wait until the status is actually off like this:
server = client.servers.get_by_name("bojack")
action = server.shutdown()
action.wait_until_finished()
for i in range(10):
if client.servers.get_by_name("bojack").status == "off":
break
time.sleep(5)
server.change_type(server_type="cax31", upgrade_disk=False)Environment
- Python Version: 3.13.1
- Hcloud-Python Version: 2.5.1
Possible Solution
As I said, I'm not sure whether this is an issue in this library at all or the API server or backend is to blame, but right now it's kind of counter-intuitive.
You know what might actually the most convenient solution? Add two options to the rescale API call: shutdown: bool and power_off: bool. Both should default to false, but it I set one of them to true, the server will be ACPI shut down or forcefully powered off (respectively) before the rescale. That way, users wouldn't even have to do multiple API calls for this operation.