Skip to content

Commit

Permalink
feat!: return full rebuild response in Client.servers.rebuild (#406)
Browse files Browse the repository at this point in the history
The single action returned was deprecated and is now removed in favor of
the full rebuild response with a root password.
  • Loading branch information
jooola committed Jul 3, 2024
1 parent 8375261 commit 1970d84
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 21 deletions.
20 changes: 4 additions & 16 deletions hcloud/servers/client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import warnings
from datetime import datetime
from typing import TYPE_CHECKING, Any, NamedTuple

Expand Down Expand Up @@ -1006,9 +1005,9 @@ def rebuild(
self,
server: Server | BoundServer,
image: Image | BoundImage,
*,
return_response: bool = False,
) -> RebuildResponse | BoundAction:
# pylint: disable=unused-argument
**kwargs: Any,
) -> RebuildResponse:
"""Rebuilds a server overwriting its disk with the content of an image, thereby destroying all data on the target server.
:param server: Server to rebuild
Expand All @@ -1022,22 +1021,11 @@ def rebuild(
json=data,
)

rebuild_response = RebuildResponse(
return RebuildResponse(
action=BoundAction(self._client.actions, response["action"]),
root_password=response.get("root_password"),
)

if not return_response:
warnings.warn(
"Returning only the 'action' is deprecated, please set the "
"'return_response' keyword argument to 'True' to return the full "
"rebuild response and update your code accordingly.",
DeprecationWarning,
stacklevel=2,
)
return rebuild_response.action
return rebuild_response

def enable_backup(self, server: Server | BoundServer) -> BoundAction:
"""Enables and configures the automatic daily backup option for the server. Enabling automatic backups will increase the price of the server by 20%.
Expand Down
5 changes: 0 additions & 5 deletions tests/unit/servers/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1085,11 +1085,6 @@ def test_rebuild(self, servers_client, server, generic_action):
assert response.action.progress == 0
assert response.root_password is None or isinstance(response.root_password, str)

def test_rebuild_return_response_deprecation(self, servers_client, generic_action):
servers_client._client.request.return_value = generic_action
with pytest.deprecated_call():
servers_client.rebuild(Server(id=1), Image(name="ubuntu-20.04"))

@pytest.mark.parametrize(
"server", [Server(id=1), BoundServer(mock.MagicMock(), dict(id=1))]
)
Expand Down

0 comments on commit 1970d84

Please sign in to comment.