ansible-collection-hetzner-.../plugins/module_utils/vendor/hcloud/locations/client.py
Jonas L 8a6157e8b2
feat: vendor hcloud python dependency (#244)
* chore: ignore venv directories

* chore: ignore integration test generated inventory

* feat: vendor hcloud package

* import https://github.com/hetznercloud/hcloud-python

* use vendored hcloud in modules

* update integration test requirements

* make vendor script self contained

* chore: add  check-hcloud-vendor pre-commit hook

* pin hcloud version to v.1.24.0

* move vendored __version__.py file to _version.py

* update comment about galaxy-importer filename lint
2023-07-11 11:15:08 +02:00

67 lines
2.4 KiB
Python

from ..core.client import BoundModelBase, ClientEntityBase, GetEntityByNameMixin
from .domain import Location
class BoundLocation(BoundModelBase):
model = Location
class LocationsClient(ClientEntityBase, GetEntityByNameMixin):
results_list_attribute_name = "locations"
def get_by_id(self, id):
# type: (int) -> locations.client.BoundLocation
"""Get a specific location by its ID.
:param id: int
:return: :class:`BoundLocation <hcloud.locations.client.BoundLocation>`
"""
response = self._client.request(url=f"/locations/{id}", method="GET")
return BoundLocation(self, response["location"])
def get_list(self, name=None, page=None, per_page=None):
# type: (Optional[str], Optional[int], Optional[int]) -> PageResult[List[BoundLocation], Meta]
"""Get a list of locations
:param name: str (optional)
Can be used to filter locations by their name.
:param page: int (optional)
Specifies the page to fetch
:param per_page: int (optional)
Specifies how many results are returned by page
:return: (List[:class:`BoundLocation <hcloud.locations.client.BoundLocation>`], :class:`Meta <hcloud.core.domain.Meta>`)
"""
params = {}
if name is not None:
params["name"] = name
if page is not None:
params["page"] = page
if per_page is not None:
params["per_page"] = per_page
response = self._client.request(url="/locations", method="GET", params=params)
locations = [
BoundLocation(self, location_data)
for location_data in response["locations"]
]
return self._add_meta_to_result(locations, response)
def get_all(self, name=None):
# type: (Optional[str]) -> List[BoundLocation]
"""Get all locations
:param name: str (optional)
Can be used to filter locations by their name.
:return: List[:class:`BoundLocation <hcloud.locations.client.BoundLocation>`]
"""
return super().get_all(name=name)
def get_by_name(self, name):
# type: (str) -> BoundLocation
"""Get location by name
:param name: str
Used to get location by name.
:return: :class:`BoundLocation <hcloud.locations.client.BoundLocation>`
"""
return super().get_by_name(name)