|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from typing import TYPE_CHECKING, Any, NamedTuple |
| 4 | + |
| 5 | +from ..core import BoundModelBase, Meta, ResourceClientBase |
| 6 | +from .domain import StorageBoxType |
| 7 | + |
| 8 | +if TYPE_CHECKING: |
| 9 | + from .._client import Client |
| 10 | + |
| 11 | + |
| 12 | +class BoundStorageBoxType(BoundModelBase, StorageBoxType): |
| 13 | + _client: StorageBoxTypesClient |
| 14 | + |
| 15 | + model = StorageBoxType |
| 16 | + |
| 17 | + |
| 18 | +class StorageBoxTypesPageResult(NamedTuple): |
| 19 | + storage_box_types: list[BoundStorageBoxType] |
| 20 | + meta: Meta |
| 21 | + |
| 22 | + |
| 23 | +class StorageBoxTypesClient(ResourceClientBase): |
| 24 | + """ |
| 25 | + A client for the Storage Box Types API. |
| 26 | +
|
| 27 | + See https://docs.hetzner.cloud/reference/hetzner#storage-box-types. |
| 28 | +
|
| 29 | + Experimental: |
| 30 | + Storage Box support is experimental, breaking changes may occur within minor releases. |
| 31 | + """ |
| 32 | + |
| 33 | + _base_url = "/storage_box_types" |
| 34 | + |
| 35 | + def __init__(self, client: Client): |
| 36 | + super().__init__(client) |
| 37 | + self._client = client._client_hetzner |
| 38 | + |
| 39 | + def get_by_id(self, id: int) -> BoundStorageBoxType: |
| 40 | + """ |
| 41 | + Returns a specific Storage Box Type. |
| 42 | +
|
| 43 | + See https://docs.hetzner.cloud/reference/hetzner#storage-box-types-get-a-storage-box-type |
| 44 | +
|
| 45 | + :param id: ID of the Storage Box Type. |
| 46 | +
|
| 47 | + Experimental: |
| 48 | + Storage Box support is experimental, breaking changes may occur within minor releases. |
| 49 | + """ |
| 50 | + response = self._client.request( |
| 51 | + method="GET", |
| 52 | + url=f"{self._base_url}/{id}", |
| 53 | + ) |
| 54 | + return BoundStorageBoxType(self, response["storage_box_type"]) |
| 55 | + |
| 56 | + def get_by_name(self, name: str) -> BoundStorageBoxType | None: |
| 57 | + """ |
| 58 | + Returns a specific Storage Box Type. |
| 59 | +
|
| 60 | + See https://docs.hetzner.cloud/reference/hetzner#storage-box-types-list-storage-box-types |
| 61 | +
|
| 62 | + :param name: Name of the Storage Box Type. |
| 63 | +
|
| 64 | + Experimental: |
| 65 | + Storage Box support is experimental, breaking changes may occur within minor releases. |
| 66 | + """ |
| 67 | + return self._get_first_by(self.get_list, name=name) |
| 68 | + |
| 69 | + def get_list( |
| 70 | + self, |
| 71 | + name: str | None = None, |
| 72 | + page: int | None = None, |
| 73 | + per_page: int | None = None, |
| 74 | + ) -> StorageBoxTypesPageResult: |
| 75 | + """ |
| 76 | + Returns a list of Storage Box Types for a specific page. |
| 77 | +
|
| 78 | + See https://docs.hetzner.cloud/reference/hetzner#storage-box-types-list-storage-box-types |
| 79 | +
|
| 80 | + :param name: Name of the Storage Box Type. |
| 81 | + :param page: Page number to return. |
| 82 | + :param per_page: Maximum number of entries returned per page. |
| 83 | +
|
| 84 | + Experimental: |
| 85 | + Storage Box support is experimental, breaking changes may occur within minor releases. |
| 86 | + """ |
| 87 | + params: dict[str, Any] = {} |
| 88 | + if name is not None: |
| 89 | + params["name"] = name |
| 90 | + if page is not None: |
| 91 | + params["page"] = page |
| 92 | + if per_page is not None: |
| 93 | + params["per_page"] = per_page |
| 94 | + |
| 95 | + response = self._client.request( |
| 96 | + method="GET", |
| 97 | + url=f"{self._base_url}", |
| 98 | + params=params, |
| 99 | + ) |
| 100 | + return StorageBoxTypesPageResult( |
| 101 | + storage_box_types=[ |
| 102 | + BoundStorageBoxType(self, o) for o in response["storage_box_types"] |
| 103 | + ], |
| 104 | + meta=Meta.parse_meta(response), |
| 105 | + ) |
| 106 | + |
| 107 | + def get_all( |
| 108 | + self, |
| 109 | + name: str | None = None, |
| 110 | + ) -> list[BoundStorageBoxType]: |
| 111 | + """ |
| 112 | + Returns all Storage Box Types. |
| 113 | +
|
| 114 | + See https://docs.hetzner.cloud/reference/hetzner#storage-box-types-list-storage-box-types |
| 115 | +
|
| 116 | + :param name: Name of the Storage Box Type. |
| 117 | +
|
| 118 | + Experimental: |
| 119 | + Storage Box support is experimental, breaking changes may occur within minor releases. |
| 120 | + """ |
| 121 | + return self._iter_pages( |
| 122 | + self.get_list, |
| 123 | + name=name, |
| 124 | + ) |
0 commit comments