Skip to content

Commit

Permalink
chore(deps): update dependency hcloud to v2 (#523)
Browse files Browse the repository at this point in the history
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [hcloud](https://togithub.com/hetznercloud/hcloud-python)
([changelog](https://togithub.com/hetznercloud/hcloud-python/blob/main/CHANGELOG.md))
| `1.35.0` -> `2.0.1` |
[![age](https://developer.mend.io/api/mc/badges/age/pypi/hcloud/2.0.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/pypi/hcloud/2.0.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/pypi/hcloud/1.35.0/2.0.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/pypi/hcloud/1.35.0/2.0.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>hetznercloud/hcloud-python (hcloud)</summary>

###
[`v2.0.1`](https://togithub.com/hetznercloud/hcloud-python/blob/HEAD/CHANGELOG.md#201-2024-07-03)

[Compare
Source](https://togithub.com/hetznercloud/hcloud-python/compare/v2.0.0...v2.0.1)

##### Bug Fixes

- `assignee_type` is required when creating a primary ip
([#&#8203;409](https://togithub.com/hetznercloud/hcloud-python/issues/409))
([bce5e94](https://togithub.com/hetznercloud/hcloud-python/commit/bce5e940e27f2c6d9d50016b5828c79aadfc4401))
- clean unused arguments in the `Client.servers.rebuild` method
([#&#8203;407](https://togithub.com/hetznercloud/hcloud-python/issues/407))
([6d33c3c](https://togithub.com/hetznercloud/hcloud-python/commit/6d33c3cff5443686c7ed37eb8635e0461bb3b928))
- details are optional in API errors
([#&#8203;411](https://togithub.com/hetznercloud/hcloud-python/issues/411))
([f1c6594](https://togithub.com/hetznercloud/hcloud-python/commit/f1c6594dee7088872f2375359ee259e4e93b31d2))
- rename `trace_id` variable to `correlation_id`
([#&#8203;408](https://togithub.com/hetznercloud/hcloud-python/issues/408))
([66a0f54](https://togithub.com/hetznercloud/hcloud-python/commit/66a0f546998193f9078f70a4a2fb1fc11937c086))

###
[`v2.0.0`](https://togithub.com/hetznercloud/hcloud-python/blob/HEAD/CHANGELOG.md#200-2024-07-03)

[Compare
Source](https://togithub.com/hetznercloud/hcloud-python/compare/v1.35.0...v2.0.0)

##### ⚠ BREAKING CHANGES

- return full rebuild response in `Client.servers.rebuild`
([#&#8203;406](https://togithub.com/hetznercloud/hcloud-python/issues/406))
- make `datacenter` argument optional when creating a primary ip
([#&#8203;363](https://togithub.com/hetznercloud/hcloud-python/issues/363))
- remove deprecated `include_wildcard_architecture` argument in
`IsosClient.get_list` and `IsosClient.get_all`
([#&#8203;402](https://togithub.com/hetznercloud/hcloud-python/issues/402))
- make `Client.request` `tries` a private argument
([#&#8203;399](https://togithub.com/hetznercloud/hcloud-python/issues/399))
- make `Client.poll_interval` a private property
([#&#8203;398](https://togithub.com/hetznercloud/hcloud-python/issues/398))
- return empty dict on empty responses in `Client.request`
([#&#8203;400](https://togithub.com/hetznercloud/hcloud-python/issues/400))
- remove deprecated `hcloud.hcloud` module
([#&#8203;401](https://togithub.com/hetznercloud/hcloud-python/issues/401))
- move `hcloud.__version__.VERSION` to `hcloud.__version__`
([#&#8203;397](https://togithub.com/hetznercloud/hcloud-python/issues/397))

##### Features

- add `trace_id` to API exceptions
([#&#8203;404](https://togithub.com/hetznercloud/hcloud-python/issues/404))
([8375261](https://togithub.com/hetznercloud/hcloud-python/commit/8375261da3b84d6fece97263c7bea40ad2a6cfcf))
- allow using a custom poll_interval function
([#&#8203;403](https://togithub.com/hetznercloud/hcloud-python/issues/403))
([93eb56b](https://togithub.com/hetznercloud/hcloud-python/commit/93eb56ba4d1a69e175398bca42e723a7e8e46371))
- make `Client.poll_interval` a private property
([#&#8203;398](https://togithub.com/hetznercloud/hcloud-python/issues/398))
([d5f24db](https://togithub.com/hetznercloud/hcloud-python/commit/d5f24db2816a0d00b8c7936e2a0290d2c4bb1e92))
- make `Client.request` `tries` a private argument
([#&#8203;399](https://togithub.com/hetznercloud/hcloud-python/issues/399))
([428ea7e](https://togithub.com/hetznercloud/hcloud-python/commit/428ea7e3be03a16114f875146971db59aabaac2c))
- move `hcloud.__version__.VERSION` to `hcloud.__version__`
([#&#8203;397](https://togithub.com/hetznercloud/hcloud-python/issues/397))
([4e3f638](https://togithub.com/hetznercloud/hcloud-python/commit/4e3f638862c9d260df98182c3f7858282049c26c)),
closes
[#&#8203;234](https://togithub.com/hetznercloud/hcloud-python/issues/234)
- remove deprecated `hcloud.hcloud` module
([#&#8203;401](https://togithub.com/hetznercloud/hcloud-python/issues/401))
([db37e63](https://togithub.com/hetznercloud/hcloud-python/commit/db37e633ebbf73354d3b2f4858cf3eebf173bfbc))
- remove deprecated `include_wildcard_architecture` argument in
`IsosClient.get_list` and `IsosClient.get_all`
([#&#8203;402](https://togithub.com/hetznercloud/hcloud-python/issues/402))
([6b977e2](https://togithub.com/hetznercloud/hcloud-python/commit/6b977e2da5cec30110c32a91d572003e5b5c400a))
- return empty dict on empty responses in `Client.request`
([#&#8203;400](https://togithub.com/hetznercloud/hcloud-python/issues/400))
([9f46adb](https://togithub.com/hetznercloud/hcloud-python/commit/9f46adb946eb2770ee4f3a4e87cfc1c8b9b33c28))
- return full rebuild response in `Client.servers.rebuild`
([#&#8203;406](https://togithub.com/hetznercloud/hcloud-python/issues/406))
([1970d84](https://togithub.com/hetznercloud/hcloud-python/commit/1970d84bec2106c8c53d8e611b74d41eb5286e9b))

##### Bug Fixes

- make `datacenter` argument optional when creating a primary ip
([#&#8203;363](https://togithub.com/hetznercloud/hcloud-python/issues/363))
([ebef774](https://togithub.com/hetznercloud/hcloud-python/commit/ebef77464c4c3b0ce33460cad2747e89d35047c7))

##### Dependencies

- update dependency coverage to >=7.5,<7.6
([#&#8203;386](https://togithub.com/hetznercloud/hcloud-python/issues/386))
([5660691](https://togithub.com/hetznercloud/hcloud-python/commit/5660691ebd6122fa7ebec56a24bce9fce0577573))
- update dependency mypy to >=1.10,<1.11
([#&#8203;387](https://togithub.com/hetznercloud/hcloud-python/issues/387))
([35c933b](https://togithub.com/hetznercloud/hcloud-python/commit/35c933bd2108d42e74b74b01d6db74e159ec9142))
- update dependency myst-parser to v3
([#&#8203;385](https://togithub.com/hetznercloud/hcloud-python/issues/385))
([9f18270](https://togithub.com/hetznercloud/hcloud-python/commit/9f182704898cb96f1ea162511605906f87cff50c))
- update dependency pylint to >=3,<3.3
([#&#8203;391](https://togithub.com/hetznercloud/hcloud-python/issues/391))
([4a6f005](https://togithub.com/hetznercloud/hcloud-python/commit/4a6f005cb0488291ae91390a612bab6afc6d80b6))
- update dependency pytest to >=8,<8.3
([#&#8203;390](https://togithub.com/hetznercloud/hcloud-python/issues/390))
([584a36b](https://togithub.com/hetznercloud/hcloud-python/commit/584a36b658670297ffffa9afa70835d29d27fbca))
- update dependency sphinx to >=7.3.4,<7.4
([#&#8203;383](https://togithub.com/hetznercloud/hcloud-python/issues/383))
([69c2e16](https://togithub.com/hetznercloud/hcloud-python/commit/69c2e16073df9ef8520e3a635b3866403eba030e))
- update pre-commit hook asottile/pyupgrade to v3.16.0
([0ce5fbc](https://togithub.com/hetznercloud/hcloud-python/commit/0ce5fbccba4a4255e08a37abf1f21ab9cc85f287))
- update pre-commit hook pre-commit/pre-commit-hooks to v4.6.0
([5ef25ab](https://togithub.com/hetznercloud/hcloud-python/commit/5ef25ab3966d731c4c36ea3e785c2b5f20c69489))
- update pre-commit hook psf/black-pre-commit-mirror to v24.4.0
([0941fbf](https://togithub.com/hetznercloud/hcloud-python/commit/0941fbfab20ca8a59e768c4a5e6fc101393c97f0))
- update pre-commit hook psf/black-pre-commit-mirror to v24.4.1
([fec08c5](https://togithub.com/hetznercloud/hcloud-python/commit/fec08c5323359d0a4f0771123f483ff975aa68b0))
- update pre-commit hook psf/black-pre-commit-mirror to v24.4.2
([#&#8203;389](https://togithub.com/hetznercloud/hcloud-python/issues/389))
([2b2e21f](https://togithub.com/hetznercloud/hcloud-python/commit/2b2e21f61366b5ec0f2ff5558f652d2bfed9d138))
- update pre-commit hook pycqa/flake8 to v7.1.0
([3bc651d](https://togithub.com/hetznercloud/hcloud-python/commit/3bc651d50d85aa92ba76dbfeef1d604cabaa4628))

##### Documentation

- add v2 upgrade notes
([#&#8203;405](https://togithub.com/hetznercloud/hcloud-python/issues/405))
([c77f771](https://togithub.com/hetznercloud/hcloud-python/commit/c77f771e2bed176acd6aa5011be006c800181809))
- cx11 is name, not an id
([#&#8203;381](https://togithub.com/hetznercloud/hcloud-python/issues/381))
([b745d40](https://togithub.com/hetznercloud/hcloud-python/commit/b745d4049f720b93d840a9204a99d246ecb499e5))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/ansible-collections/hetzner.hcloud).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40MjEuOSIsInVwZGF0ZWRJblZlciI6IjM3LjQyMS45IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: jo <ljonas@riseup.net>
  • Loading branch information
renovate[bot] and jooola committed Jul 3, 2024
1 parent f3d697c commit 9adb8b3
Show file tree
Hide file tree
Showing 23 changed files with 126 additions and 150 deletions.
1 change: 1 addition & 0 deletions plugins/module_utils/vendor/hcloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
APIException as APIException,
HCloudException as HCloudException,
)
from ._version import __version__ # noqa
101 changes: 61 additions & 40 deletions plugins/module_utils/vendor/hcloud/_client.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from __future__ import annotations

import time
from typing import NoReturn
from typing import Protocol

try:
import requests
except ImportError:
requests = None

from ._version import VERSION
from ._exceptions import APIException
from ._version import __version__
from .actions import ActionsClient
from .certificates import CertificatesClient
from .datacenters import DatacentersClient
Expand All @@ -29,10 +29,19 @@
from .volumes import VolumesClient


class PollIntervalFunction(Protocol):
def __call__(self, retries: int) -> float:
"""
Return a interval in seconds to wait between each API call.
:param retries: Number of calls already made.
"""


class Client:
"""Base Client for accessing the Hetzner Cloud API"""

_version = VERSION
_version = __version__
_retry_wait_time = 0.5
__user_agent_prefix = "hcloud-python"

Expand All @@ -42,7 +51,8 @@ def __init__(
api_endpoint: str = "https://api.hetzner.cloud/v1",
application_name: str | None = None,
application_version: str | None = None,
poll_interval: int = 1,
poll_interval: int | float | PollIntervalFunction = 1.0,
poll_max_retries: int = 120,
timeout: float | tuple[float, float] | None = None,
):
"""Create a new Client instance
Expand All @@ -51,7 +61,11 @@ def __init__(
:param api_endpoint: Hetzner Cloud API endpoint
:param application_name: Your application name
:param application_version: Your application _version
:param poll_interval: Interval for polling information from Hetzner Cloud API in seconds
:param poll_interval:
Interval in seconds to use when polling actions from the API.
You may pass a function to compute a custom poll interval.
:param poll_max_retries:
Max retries before timeout when polling actions from the API.
:param timeout: Requests timeout in seconds
"""
self.token = token
Expand All @@ -60,7 +74,12 @@ def __init__(
self._application_version = application_version
self._requests_session = requests.Session()
self._requests_timeout = timeout
self.poll_interval = poll_interval

if isinstance(poll_interval, (int, float)):
self._poll_interval_func = lambda _: poll_interval # Constant poll interval
else:
self._poll_interval_func = poll_interval
self._poll_max_retries = poll_max_retries

self.datacenters = DatacentersClient(self)
"""DatacentersClient Instance
Expand Down Expand Up @@ -174,32 +193,18 @@ def _get_headers(self) -> dict:
}
return headers

def _raise_exception_from_response(self, response) -> NoReturn:
raise APIException(
code=response.status_code,
message=response.reason,
details={"content": response.content},
)

def _raise_exception_from_content(self, content: dict) -> NoReturn:
raise APIException(
code=content["error"]["code"],
message=content["error"]["message"],
details=content["error"]["details"],
)

def request( # type: ignore[no-untyped-def]
self,
method: str,
url: str,
tries: int = 1,
*,
_tries: int = 1,
**kwargs,
) -> dict:
"""Perform a request to the Hetzner Cloud API, wrapper around requests.request
:param method: HTTP Method to perform the Request
:param url: URL of the Endpoint
:param tries: Tries of the request (used internally, should not be set by the user)
:param timeout: Requests timeout in seconds
:return: Response
"""
Expand All @@ -213,24 +218,40 @@ def request( # type: ignore[no-untyped-def]
**kwargs,
)

content = response.content
correlation_id = response.headers.get("X-Correlation-Id")
payload = {}
try:
if len(content) > 0:
content = response.json()
except (TypeError, ValueError):
self._raise_exception_from_response(response)
if len(response.content) > 0:
payload = response.json()
except (TypeError, ValueError) as exc:
raise APIException(
code=response.status_code,
message=response.reason,
details={"content": response.content},
correlation_id=correlation_id,
) from exc

if not response.ok:
if content:
assert isinstance(content, dict)
if content["error"]["code"] == "rate_limit_exceeded" and tries < 5:
time.sleep(tries * self._retry_wait_time)
tries = tries + 1
return self.request(method, url, tries, **kwargs)

self._raise_exception_from_content(content)
else:
self._raise_exception_from_response(response)

# TODO: return an empty dict instead of an empty string when content == "".
return content # type: ignore[return-value]
if not payload or "error" not in payload:
raise APIException(
code=response.status_code,
message=response.reason,
details={"content": response.content},
correlation_id=correlation_id,
)

error: dict = payload["error"]

if error["code"] == "rate_limit_exceeded" and _tries < 5:
time.sleep(_tries * self._retry_wait_time)
_tries = _tries + 1
return self.request(method, url, _tries=_tries, **kwargs)

raise APIException(
code=error["code"],
message=error["message"],
details=error.get("details"),
correlation_id=correlation_id,
)

return payload
18 changes: 16 additions & 2 deletions plugins/module_utils/vendor/hcloud/_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,22 @@ class HCloudException(Exception):
class APIException(HCloudException):
"""There was an error while performing an API Request"""

def __init__(self, code: int | str, message: str | None, details: Any):
super().__init__(code if message is None and isinstance(code, str) else message)
def __init__(
self,
code: int | str,
message: str,
details: Any,
*,
correlation_id: str | None = None,
):
extras = [str(code)]
if correlation_id is not None:
extras.append(correlation_id)

error = f"{message} ({', '.join(extras)})"

super().__init__(error)
self.code = code
self.message = message
self.details = details
self.correlation_id = correlation_id
2 changes: 1 addition & 1 deletion plugins/module_utils/vendor/hcloud/_version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from __future__ import annotations

VERSION = "1.35.0" # x-release-please-version
__version__ = "2.0.1" # x-release-please-version
22 changes: 13 additions & 9 deletions plugins/module_utils/vendor/hcloud/actions/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,24 @@ class BoundAction(BoundModelBase, Action):

model = Action

def wait_until_finished(self, max_retries: int = 100) -> None:
"""Wait until the specific action has status="finished" (set Client.poll_interval to specify a delay between checks)
def wait_until_finished(self, max_retries: int | None = None) -> None:
"""Wait until the specific action has status=finished.
:param max_retries: int
Specify how many retries will be performed before an ActionTimeoutException will be raised
:raises: ActionFailedException when action is finished with status=="error"
:raises: ActionTimeoutException when Action is still in "running" state after max_retries reloads.
:param max_retries: int Specify how many retries will be performed before an ActionTimeoutException will be raised.
:raises: ActionFailedException when action is finished with status==error
:raises: ActionTimeoutException when Action is still in status==running after max_retries is reached.
"""
if max_retries is None:
# pylint: disable=protected-access
max_retries = self._client._client._poll_max_retries

retries = 0
while self.status == Action.STATUS_RUNNING:
if max_retries > 0:
if retries < max_retries:
self.reload()
retries += 1
# pylint: disable=protected-access
time.sleep(self._client._client.poll_interval)
max_retries = max_retries - 1
time.sleep(self._client._client._poll_interval_func(retries))
else:
raise ActionTimeoutException(action=self)

Expand Down
12 changes: 0 additions & 12 deletions plugins/module_utils/vendor/hcloud/hcloud.py

This file was deleted.

23 changes: 0 additions & 23 deletions plugins/module_utils/vendor/hcloud/isos/client.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

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

from ..core import BoundModelBase, ClientEntityBase, Meta
from .domain import Iso
Expand Down Expand Up @@ -37,7 +36,6 @@ def get_list(
self,
name: str | None = None,
architecture: list[str] | None = None,
include_wildcard_architecture: bool | None = None,
include_architecture_wildcard: bool | None = None,
page: int | None = None,
per_page: int | None = None,
Expand All @@ -48,8 +46,6 @@ def get_list(
Can be used to filter ISOs by their name.
:param architecture: List[str] (optional)
Can be used to filter ISOs by their architecture. Choices: x86 arm
:param include_wildcard_architecture: bool (optional)
Deprecated, please use `include_architecture_wildcard` instead.
:param include_architecture_wildcard: bool (optional)
Custom ISOs do not have an architecture set. You must also set this flag to True if you are filtering by
architecture and also want custom ISOs.
Expand All @@ -59,14 +55,6 @@ def get_list(
Specifies how many results are returned by page
:return: (List[:class:`BoundIso <hcloud.isos.client.BoundIso>`], :class:`Meta <hcloud.core.domain.Meta>`)
"""

if include_wildcard_architecture is not None:
warn(
"The `include_wildcard_architecture` argument is deprecated, please use the `include_architecture_wildcard` argument instead.",
DeprecationWarning,
)
include_architecture_wildcard = include_wildcard_architecture

params: dict[str, Any] = {}
if name is not None:
params["name"] = name
Expand All @@ -87,7 +75,6 @@ def get_all(
self,
name: str | None = None,
architecture: list[str] | None = None,
include_wildcard_architecture: bool | None = None,
include_architecture_wildcard: bool | None = None,
) -> list[BoundIso]:
"""Get all ISOs
Expand All @@ -96,21 +83,11 @@ def get_all(
Can be used to filter ISOs by their name.
:param architecture: List[str] (optional)
Can be used to filter ISOs by their architecture. Choices: x86 arm
:param include_wildcard_architecture: bool (optional)
Deprecated, please use `include_architecture_wildcard` instead.
:param include_architecture_wildcard: bool (optional)
Custom ISOs do not have an architecture set. You must also set this flag to True if you are filtering by
architecture and also want custom ISOs.
:return: List[:class:`BoundIso <hcloud.isos.client.BoundIso>`]
"""

if include_wildcard_architecture is not None:
warn(
"The `include_wildcard_architecture` argument is deprecated, please use the `include_architecture_wildcard` argument instead.",
DeprecationWarning,
)
include_architecture_wildcard = include_wildcard_architecture

return self._iter_pages(
self.get_list,
name=name,
Expand Down
17 changes: 7 additions & 10 deletions plugins/module_utils/vendor/hcloud/primary_ips/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,33 +189,30 @@ def get_by_name(self, name: str) -> BoundPrimaryIP | None:
def create(
self,
type: str,
# TODO: Make the datacenter argument optional
datacenter: Datacenter | BoundDatacenter | None,
name: str,
datacenter: Datacenter | BoundDatacenter | None = None,
assignee_type: str | None = "server",
assignee_id: int | None = None,
auto_delete: bool | None = False,
labels: dict | None = None,
) -> CreatePrimaryIPResponse:
"""Creates a new Primary IP assigned to a server.
:param type: str
Primary IP type Choices: ipv4, ipv6
:param assignee_type: str
:param assignee_id: int (optional)
:param datacenter: Datacenter
:param labels: Dict[str, str] (optional)
User-defined labels (key-value pairs)
:param type: str Primary IP type Choices: ipv4, ipv6
:param name: str
:param datacenter: Datacenter (optional)
:param assignee_type: str (optional)
:param assignee_id: int (optional)
:param auto_delete: bool (optional)
:param labels: Dict[str, str] (optional) User-defined labels (key-value pairs)
:return: :class:`CreatePrimaryIPResponse <hcloud.primary_ips.domain.CreatePrimaryIPResponse>`
"""

data: dict[str, Any] = {
"name": name,
"type": type,
"assignee_type": assignee_type,
"auto_delete": auto_delete,
"name": name,
}
if datacenter is not None:
data["datacenter"] = datacenter.id_or_name
Expand Down
Loading

0 comments on commit 9adb8b3

Please sign in to comment.