Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 109 additions & 1 deletion hcloud/primary_ips/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from typing import TYPE_CHECKING, Any, NamedTuple

from ..actions import BoundAction, ResourceActionsClient
from ..actions import ActionsPageResult, BoundAction, ResourceActionsClient
from ..core import BoundModelBase, Meta, ResourceClientBase
from .domain import CreatePrimaryIPResponse, PrimaryIP

Expand All @@ -26,6 +26,52 @@ def __init__(self, client: PrimaryIPsClient, data: dict, complete: bool = True):

super().__init__(client, data, complete)

def get_actions_list(
self,
status: list[str] | None = None,
sort: list[str] | None = None,
page: int | None = None,
per_page: int | None = None,
) -> ActionsPageResult:
"""
Returns a paginated list of Actions for a Primary IP.

See https://docs.hetzner.cloud/reference/cloud#zones-list-zones

:param primary_ip: Primary IP to fetch the Actions from.
:param status: Filter the actions by status. The response will only contain actions matching the specified statuses.
:param sort: Sort resources by field and direction.
:param page: Page number to return.
:param per_page: Maximum number of entries returned per page.
"""
return self._client.get_actions_list(
self,
status=status,
sort=sort,
page=page,
per_page=per_page,
)

def get_actions(
self,
status: list[str] | None = None,
sort: list[str] | None = None,
) -> list[BoundAction]:
"""
Returns all Actions for a Primary IP.

See https://docs.hetzner.cloud/reference/cloud#zones-list-zones

:param primary_ip: Primary IP to fetch the Actions from.
:param status: Filter the actions by status. The response will only contain actions matching the specified statuses.
:param sort: Sort resources by field and direction.
"""
return self._client.get_actions(
self,
status=status,
sort=sort,
)

def update(
self,
auto_delete: bool | None = None,
Expand Down Expand Up @@ -115,6 +161,68 @@ def __init__(self, client: Client):
super().__init__(client)
self.actions = ResourceActionsClient(client, self._base_url)

def get_actions_list(
self,
primary_ip: PrimaryIP | BoundPrimaryIP,
status: list[str] | None = None,
sort: list[str] | None = None,
page: int | None = None,
per_page: int | None = None,
) -> ActionsPageResult:
"""
Returns a paginated list of Actions for a Primary IP.

See https://docs.hetzner.cloud/reference/cloud#zones-list-zones

:param primary_ip: Primary IP to fetch the Actions from.
:param status: Filter the actions by status. The response will only contain actions matching the specified statuses.
:param sort: Sort resources by field and direction.
:param page: Page number to return.
:param per_page: Maximum number of entries returned per page.
"""
params: dict[str, Any] = {}
if status is not None:
params["status"] = status
if sort is not None:
params["sort"] = sort
if page is not None:
params["page"] = page
if per_page is not None:
params["per_page"] = per_page

response = self._client.request(
url=f"{self._base_url}/{primary_ip.id}/actions",
method="GET",
params=params,
)
actions = [
BoundAction(self._parent.actions, action_data)
for action_data in response["actions"]
]
return ActionsPageResult(actions, Meta.parse_meta(response))

def get_actions(
self,
primary_ip: PrimaryIP | BoundPrimaryIP,
status: list[str] | None = None,
sort: list[str] | None = None,
) -> list[BoundAction]:
"""
Returns all Actions for a Primary IP.

See https://docs.hetzner.cloud/reference/cloud#zones-list-zones

:param primary_ip: Primary IP to fetch the Actions from.
:param status: Filter the actions by status. The response will only contain actions matching the specified statuses.
:param sort: Sort resources by field and direction.
"""
return self._iter_pages(
self.get_actions_list,
primary_ip,
status=status,
sort=sort,
)

def get_by_id(self, id: int) -> BoundPrimaryIP:
"""Returns a specific Primary IP object.

Expand Down
4 changes: 0 additions & 4 deletions tests/unit/actions/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,6 @@ class TestResourceObjectActionsClient:

@pytest.fixture(params=resources_with_actions.keys())
def resource(self, request):
if request.param == "primary_ips":
pytest.skip("not implemented yet")
return request.param

@pytest.fixture()
Expand Down Expand Up @@ -322,8 +320,6 @@ class TestBoundModelActions:

@pytest.fixture(params=resources_with_actions.keys())
def resource(self, request):
if request.param == "primary_ips":
pytest.skip("not implemented yet")
return request.param

@pytest.fixture()
Expand Down