mirror of
https://github.com/ansible-collections/hetzner.hcloud.git
synced 2026-02-03 23:51:48 +00:00
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [hcloud](https://redirect.github.com/hetznercloud/hcloud-python) ([changelog](https://redirect.github.com/hetznercloud/hcloud-python/blob/main/CHANGELOG.md)) | `2.12.0` -> `2.13.0` |  |  | --- ### Release Notes <details> <summary>hetznercloud/hcloud-python (hcloud)</summary> ### [`v2.13.0`](https://redirect.github.com/hetznercloud/hcloud-python/blob/HEAD/CHANGELOG.md#v2130) [Compare Source](https://redirect.github.com/hetznercloud/hcloud-python/compare/v2.12.0...v2.13.0) ##### Features - add per primary ip actions list operations ([#​608](https://redirect.github.com/hetznercloud/hcloud-python/issues/608)) - deprecate datacenter in `primary ips` and `servers` ([#​609](https://redirect.github.com/hetznercloud/hcloud-python/issues/609)) </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 was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/ansible-collections/hetzner.hcloud). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi41OS4wIiwidXBkYXRlZEluVmVyIjoiNDIuNTkuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==--> --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: jo <ljonas@riseup.net>
126 lines
3.1 KiB
Python
126 lines
3.1 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING, Any, Literal, TypedDict
|
|
|
|
from .._exceptions import HCloudException
|
|
from ..core import BaseDomain
|
|
|
|
if TYPE_CHECKING:
|
|
from .client import BoundAction
|
|
|
|
__all__ = [
|
|
"ActionStatus",
|
|
"Action",
|
|
"ActionResource",
|
|
"ActionError",
|
|
"ActionException",
|
|
"ActionFailedException",
|
|
"ActionTimeoutException",
|
|
]
|
|
|
|
ActionStatus = Literal[
|
|
"running",
|
|
"success",
|
|
"error",
|
|
]
|
|
|
|
|
|
class Action(BaseDomain):
|
|
"""Action Domain
|
|
|
|
:param id: int ID of an action
|
|
:param command: Command executed in the action
|
|
:param status: Status of the action
|
|
:param progress: Progress of action in percent
|
|
:param started: Point in time when the action was started
|
|
:param datetime,None finished: Point in time when the action was finished. Only set if the action is finished otherwise None
|
|
:param resources: Resources the action relates to
|
|
:param error: Error message for the action if error occurred, otherwise None.
|
|
"""
|
|
|
|
STATUS_RUNNING = "running"
|
|
"""Action Status running"""
|
|
STATUS_SUCCESS = "success"
|
|
"""Action Status success"""
|
|
STATUS_ERROR = "error"
|
|
"""Action Status error"""
|
|
|
|
__api_properties__ = (
|
|
"id",
|
|
"command",
|
|
"status",
|
|
"progress",
|
|
"resources",
|
|
"error",
|
|
"started",
|
|
"finished",
|
|
)
|
|
__slots__ = __api_properties__
|
|
|
|
def __init__(
|
|
self,
|
|
id: int,
|
|
command: str | None = None,
|
|
status: ActionStatus | None = None,
|
|
progress: int | None = None,
|
|
started: str | None = None,
|
|
finished: str | None = None,
|
|
resources: list[ActionResource] | None = None,
|
|
error: ActionError | None = None,
|
|
):
|
|
self.id = id
|
|
self.command = command
|
|
|
|
self.status = status
|
|
self.progress = progress
|
|
self.started = self._parse_datetime(started)
|
|
self.finished = self._parse_datetime(finished)
|
|
self.resources = resources
|
|
self.error = error
|
|
|
|
|
|
class ActionResource(TypedDict):
|
|
id: int
|
|
type: str
|
|
|
|
|
|
class ActionError(TypedDict):
|
|
code: str
|
|
message: str
|
|
details: dict[str, Any]
|
|
|
|
|
|
class ActionException(HCloudException):
|
|
"""A generic action exception"""
|
|
|
|
def __init__(self, action: Action | BoundAction):
|
|
assert self.__doc__ is not None
|
|
message = self.__doc__
|
|
|
|
extras = []
|
|
if (
|
|
action.error is not None
|
|
and "code" in action.error
|
|
and "message" in action.error
|
|
):
|
|
message += f": {action.error['message']}"
|
|
|
|
extras.append(action.error["code"])
|
|
else:
|
|
if action.command is not None:
|
|
extras.append(action.command)
|
|
|
|
extras.append(str(action.id))
|
|
message += f" ({', '.join(extras)})"
|
|
|
|
super().__init__(message)
|
|
self.message = message
|
|
self.action = action
|
|
|
|
|
|
class ActionFailedException(ActionException):
|
|
"""The pending action failed"""
|
|
|
|
|
|
class ActionTimeoutException(ActionException):
|
|
"""The pending action timed out"""
|