mirror of
https://github.com/ansible-collections/hetzner.hcloud
synced 2024-12-05 01:59:14 +00:00
deps: update dependency hcloud to v1.33.0 (#430)
[![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.32.0` -> `1.33.0` | [![age](https://developer.mend.io/api/mc/badges/age/pypi/hcloud/1.33.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/pypi/hcloud/1.33.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/pypi/hcloud/1.32.0/1.33.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/pypi/hcloud/1.32.0/1.33.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>hetznercloud/hcloud-python (hcloud)</summary> ### [`v1.33.0`](https://togithub.com/hetznercloud/hcloud-python/blob/HEAD/CHANGELOG.md#1330-2023-12-19) [Compare Source](https://togithub.com/hetznercloud/hcloud-python/compare/v1.32.0...v1.33.0) ##### Features - add metrics endpoint for load balancers and servers ([#​331](https://togithub.com/hetznercloud/hcloud-python/issues/331)) ([ee3c54f](ee3c54fd1b
)) ##### Bug Fixes - fallback to error code when message is unset ([#​328](https://togithub.com/hetznercloud/hcloud-python/issues/328)) ([1c94153](1c94153d93
)) ##### Dependencies - update actions/setup-python action to v5 ([#​335](https://togithub.com/hetznercloud/hcloud-python/issues/335)) ([2ac252d](2ac252d18b
)) - update dependency sphinx-rtd-theme to v2 ([#​330](https://togithub.com/hetznercloud/hcloud-python/issues/330)) ([7cc4335](7cc4335cac
)) - update pre-commit hook psf/black-pre-commit-mirror to v23.12.0 ([#​338](https://togithub.com/hetznercloud/hcloud-python/issues/338)) ([38e4748](38e4748d3d
)) - update pre-commit hook pycqa/isort to v5.13.0 ([#​336](https://togithub.com/hetznercloud/hcloud-python/issues/336)) ([3244cfe](3244cfef2f
)) - update pre-commit hook pycqa/isort to v5.13.1 ([#​337](https://togithub.com/hetznercloud/hcloud-python/issues/337)) ([020a0ef](020a0eff6b
)) - update pre-commit hook pycqa/isort to v5.13.2 ([#​339](https://togithub.com/hetznercloud/hcloud-python/issues/339)) ([b46df8c](b46df8cbb2
)) </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:eyJjcmVhdGVkSW5WZXIiOiIzNy4xMDMuMSIsInVwZGF0ZWRJblZlciI6IjM3LjEwMy4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9--> --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: jo <ljonas@riseup.net>
This commit is contained in:
parent
1e6e3a04e3
commit
b7beb0971f
11 changed files with 250 additions and 6 deletions
|
@ -10,8 +10,8 @@ class HCloudException(Exception):
|
|||
class APIException(HCloudException):
|
||||
"""There was an error while performing an API Request"""
|
||||
|
||||
def __init__(self, code: int | str, message: str, details: Any):
|
||||
super().__init__(message)
|
||||
def __init__(self, code: int | str, message: str | None, details: Any):
|
||||
super().__init__(code if message is None and isinstance(code, str) else message)
|
||||
self.code = code
|
||||
self.message = message
|
||||
self.details = details
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
from __future__ import annotations
|
||||
|
||||
VERSION = "1.32.0" # x-release-please-version
|
||||
VERSION = "1.33.0" # x-release-please-version
|
||||
|
|
|
@ -7,6 +7,7 @@ from .client import ( # noqa: F401
|
|||
)
|
||||
from .domain import ( # noqa: F401
|
||||
CreateLoadBalancerResponse,
|
||||
GetMetricsResponse,
|
||||
IPv4Address,
|
||||
IPv6Network,
|
||||
LoadBalancer,
|
||||
|
|
|
@ -1,16 +1,24 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
from typing import TYPE_CHECKING, Any, NamedTuple
|
||||
|
||||
try:
|
||||
from dateutil.parser import isoparse
|
||||
except ImportError:
|
||||
isoparse = None
|
||||
|
||||
from ..actions import ActionsPageResult, BoundAction, ResourceActionsClient
|
||||
from ..certificates import BoundCertificate
|
||||
from ..core import BoundModelBase, ClientEntityBase, Meta
|
||||
from ..load_balancer_types import BoundLoadBalancerType
|
||||
from ..locations import BoundLocation
|
||||
from ..metrics import Metrics
|
||||
from ..networks import BoundNetwork
|
||||
from ..servers import BoundServer
|
||||
from .domain import (
|
||||
CreateLoadBalancerResponse,
|
||||
GetMetricsResponse,
|
||||
IPv4Address,
|
||||
IPv6Network,
|
||||
LoadBalancer,
|
||||
|
@ -23,6 +31,7 @@ from .domain import (
|
|||
LoadBalancerTargetHealthStatus,
|
||||
LoadBalancerTargetIP,
|
||||
LoadBalancerTargetLabelSelector,
|
||||
MetricsType,
|
||||
PrivateNet,
|
||||
PublicNetwork,
|
||||
)
|
||||
|
@ -177,6 +186,28 @@ class BoundLoadBalancer(BoundModelBase, LoadBalancer):
|
|||
"""
|
||||
return self._client.delete(self)
|
||||
|
||||
def get_metrics(
|
||||
self,
|
||||
type: MetricsType,
|
||||
start: datetime | str,
|
||||
end: datetime | str,
|
||||
step: float | None = None,
|
||||
) -> GetMetricsResponse:
|
||||
"""Get Metrics for a LoadBalancer.
|
||||
|
||||
:param type: Type of metrics to get.
|
||||
:param start: Start of period to get Metrics for (in ISO-8601 format).
|
||||
:param end: End of period to get Metrics for (in ISO-8601 format).
|
||||
:param step: Resolution of results in seconds.
|
||||
"""
|
||||
return self._client.get_metrics(
|
||||
self,
|
||||
type=type,
|
||||
start=start,
|
||||
end=end,
|
||||
step=step,
|
||||
)
|
||||
|
||||
def get_actions_list(
|
||||
self,
|
||||
status: list[str] | None = None,
|
||||
|
@ -533,6 +564,46 @@ class LoadBalancersClient(ClientEntityBase):
|
|||
)
|
||||
return True
|
||||
|
||||
def get_metrics(
|
||||
self,
|
||||
load_balancer: LoadBalancer | BoundLoadBalancer,
|
||||
type: MetricsType | list[MetricsType],
|
||||
start: datetime | str,
|
||||
end: datetime | str,
|
||||
step: float | None = None,
|
||||
) -> GetMetricsResponse:
|
||||
"""Get Metrics for a LoadBalancer.
|
||||
|
||||
:param load_balancer: The Load Balancer to get the metrics for.
|
||||
:param type: Type of metrics to get.
|
||||
:param start: Start of period to get Metrics for (in ISO-8601 format).
|
||||
:param end: End of period to get Metrics for (in ISO-8601 format).
|
||||
:param step: Resolution of results in seconds.
|
||||
"""
|
||||
if not isinstance(type, list):
|
||||
type = [type]
|
||||
if isinstance(start, str):
|
||||
start = isoparse(start)
|
||||
if isinstance(end, str):
|
||||
end = isoparse(end)
|
||||
|
||||
params: dict[str, Any] = {
|
||||
"type": ",".join(type),
|
||||
"start": start.isoformat(),
|
||||
"end": end.isoformat(),
|
||||
}
|
||||
if step is not None:
|
||||
params["step"] = step
|
||||
|
||||
response = self._client.request(
|
||||
url=f"/load_balancers/{load_balancer.id}/metrics",
|
||||
method="GET",
|
||||
params=params,
|
||||
)
|
||||
return GetMetricsResponse(
|
||||
metrics=Metrics(**response["metrics"]),
|
||||
)
|
||||
|
||||
def get_actions_list(
|
||||
self,
|
||||
load_balancer: LoadBalancer | BoundLoadBalancer,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Any
|
||||
from typing import TYPE_CHECKING, Any, Literal
|
||||
|
||||
try:
|
||||
from dateutil.parser import isoparse
|
||||
|
@ -14,6 +14,7 @@ if TYPE_CHECKING:
|
|||
from ..certificates import BoundCertificate
|
||||
from ..load_balancer_types import BoundLoadBalancerType
|
||||
from ..locations import BoundLocation
|
||||
from ..metrics import Metrics
|
||||
from ..networks import BoundNetwork
|
||||
from ..servers import BoundServer
|
||||
from .client import BoundLoadBalancer
|
||||
|
@ -511,3 +512,26 @@ class CreateLoadBalancerResponse(BaseDomain):
|
|||
):
|
||||
self.load_balancer = load_balancer
|
||||
self.action = action
|
||||
|
||||
|
||||
MetricsType = Literal[
|
||||
"open_connections",
|
||||
"connections_per_second",
|
||||
"requests_per_second",
|
||||
"bandwidth",
|
||||
]
|
||||
|
||||
|
||||
class GetMetricsResponse(BaseDomain):
|
||||
"""Get a Load Balancer Metrics Response Domain
|
||||
|
||||
:param metrics: The Load Balancer metrics
|
||||
"""
|
||||
|
||||
__slots__ = ("metrics",)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
metrics: Metrics,
|
||||
):
|
||||
self.metrics = metrics
|
||||
|
|
3
plugins/module_utils/vendor/hcloud/metrics/__init__.py
vendored
Normal file
3
plugins/module_utils/vendor/hcloud/metrics/__init__.py
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from .domain import Metrics, TimeSeries # noqa: F401
|
49
plugins/module_utils/vendor/hcloud/metrics/domain.py
vendored
Normal file
49
plugins/module_utils/vendor/hcloud/metrics/domain.py
vendored
Normal file
|
@ -0,0 +1,49 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Dict, List, Literal, Tuple
|
||||
|
||||
try:
|
||||
from dateutil.parser import isoparse
|
||||
except ImportError:
|
||||
isoparse = None
|
||||
|
||||
from ..core import BaseDomain
|
||||
|
||||
TimeSeries = Dict[str, Dict[Literal["values"], List[Tuple[float, str]]]]
|
||||
|
||||
|
||||
class Metrics(BaseDomain):
|
||||
"""Metrics Domain
|
||||
|
||||
:param start: Start of period of metrics reported.
|
||||
:param end: End of period of metrics reported.
|
||||
:param step: Resolution of results in seconds.
|
||||
:param time_series: Dict with time series data, using the name of the time series as
|
||||
key. The metrics timestamps and values are stored in a list of tuples
|
||||
``[(timestamp, value), ...]``.
|
||||
"""
|
||||
|
||||
start: datetime
|
||||
end: datetime
|
||||
step: float
|
||||
time_series: TimeSeries
|
||||
|
||||
__slots__ = (
|
||||
"start",
|
||||
"end",
|
||||
"step",
|
||||
"time_series",
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
start: str,
|
||||
end: str,
|
||||
step: float,
|
||||
time_series: TimeSeries,
|
||||
):
|
||||
self.start = isoparse(start)
|
||||
self.end = isoparse(end)
|
||||
self.step = step
|
||||
self.time_series = time_series
|
|
@ -4,6 +4,7 @@ from .client import BoundServer, ServersClient, ServersPageResult # noqa: F401
|
|||
from .domain import ( # noqa: F401
|
||||
CreateServerResponse,
|
||||
EnableRescueResponse,
|
||||
GetMetricsResponse,
|
||||
IPv4Address,
|
||||
IPv6Network,
|
||||
PrivateNet,
|
||||
|
|
|
@ -1,8 +1,14 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import warnings
|
||||
from datetime import datetime
|
||||
from typing import TYPE_CHECKING, Any, NamedTuple
|
||||
|
||||
try:
|
||||
from dateutil.parser import isoparse
|
||||
except ImportError:
|
||||
isoparse = None
|
||||
|
||||
from ..actions import ActionsPageResult, BoundAction, ResourceActionsClient
|
||||
from ..core import BoundModelBase, ClientEntityBase, Meta
|
||||
from ..datacenters import BoundDatacenter
|
||||
|
@ -10,6 +16,7 @@ from ..firewalls import BoundFirewall
|
|||
from ..floating_ips import BoundFloatingIP
|
||||
from ..images import BoundImage, CreateImageResponse
|
||||
from ..isos import BoundIso
|
||||
from ..metrics import Metrics
|
||||
from ..placement_groups import BoundPlacementGroup
|
||||
from ..primary_ips import BoundPrimaryIP
|
||||
from ..server_types import BoundServerType
|
||||
|
@ -17,8 +24,10 @@ from ..volumes import BoundVolume
|
|||
from .domain import (
|
||||
CreateServerResponse,
|
||||
EnableRescueResponse,
|
||||
GetMetricsResponse,
|
||||
IPv4Address,
|
||||
IPv6Network,
|
||||
MetricsType,
|
||||
PrivateNet,
|
||||
PublicNetwork,
|
||||
PublicNetworkFirewall,
|
||||
|
@ -210,6 +219,29 @@ class BoundServer(BoundModelBase, Server):
|
|||
"""
|
||||
return self._client.update(self, name, labels)
|
||||
|
||||
def get_metrics(
|
||||
self,
|
||||
type: MetricsType | list[MetricsType],
|
||||
start: datetime | str,
|
||||
end: datetime | str,
|
||||
step: float | None = None,
|
||||
) -> GetMetricsResponse:
|
||||
"""Get Metrics for a Server.
|
||||
|
||||
:param server: The Server to get the metrics for.
|
||||
:param type: Type of metrics to get.
|
||||
:param start: Start of period to get Metrics for (in ISO-8601 format).
|
||||
:param end: End of period to get Metrics for (in ISO-8601 format).
|
||||
:param step: Resolution of results in seconds.
|
||||
"""
|
||||
return self._client.get_metrics(
|
||||
self,
|
||||
type=type,
|
||||
start=start,
|
||||
end=end,
|
||||
step=step,
|
||||
)
|
||||
|
||||
def delete(self) -> BoundAction:
|
||||
"""Deletes a server. This immediately removes the server from your account, and it is no longer accessible.
|
||||
|
||||
|
@ -742,6 +774,46 @@ class ServersClient(ClientEntityBase):
|
|||
)
|
||||
return BoundServer(self, response["server"])
|
||||
|
||||
def get_metrics(
|
||||
self,
|
||||
server: Server | BoundServer,
|
||||
type: MetricsType | list[MetricsType],
|
||||
start: datetime | str,
|
||||
end: datetime | str,
|
||||
step: float | None = None,
|
||||
) -> GetMetricsResponse:
|
||||
"""Get Metrics for a Server.
|
||||
|
||||
:param server: The Server to get the metrics for.
|
||||
:param type: Type of metrics to get.
|
||||
:param start: Start of period to get Metrics for (in ISO-8601 format).
|
||||
:param end: End of period to get Metrics for (in ISO-8601 format).
|
||||
:param step: Resolution of results in seconds.
|
||||
"""
|
||||
if not isinstance(type, list):
|
||||
type = [type]
|
||||
if isinstance(start, str):
|
||||
start = isoparse(start)
|
||||
if isinstance(end, str):
|
||||
end = isoparse(end)
|
||||
|
||||
params: dict[str, Any] = {
|
||||
"type": ",".join(type),
|
||||
"start": start.isoformat(),
|
||||
"end": end.isoformat(),
|
||||
}
|
||||
if step is not None:
|
||||
params["step"] = step
|
||||
|
||||
response = self._client.request(
|
||||
url=f"/servers/{server.id}/metrics",
|
||||
method="GET",
|
||||
params=params,
|
||||
)
|
||||
return GetMetricsResponse(
|
||||
metrics=Metrics(**response["metrics"]),
|
||||
)
|
||||
|
||||
def delete(self, server: Server | BoundServer) -> BoundAction:
|
||||
"""Deletes a server. This immediately removes the server from your account, and it is no longer accessible.
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import TYPE_CHECKING, Literal
|
||||
|
||||
try:
|
||||
from dateutil.parser import isoparse
|
||||
|
@ -16,6 +16,7 @@ if TYPE_CHECKING:
|
|||
from ..floating_ips import BoundFloatingIP
|
||||
from ..images import BoundImage
|
||||
from ..isos import BoundIso
|
||||
from ..metrics import Metrics
|
||||
from ..networks import BoundNetwork
|
||||
from ..placement_groups import BoundPlacementGroup
|
||||
from ..primary_ips import BoundPrimaryIP, PrimaryIP
|
||||
|
@ -430,3 +431,25 @@ class ServerCreatePublicNetwork(BaseDomain):
|
|||
self.ipv6 = ipv6
|
||||
self.enable_ipv4 = enable_ipv4
|
||||
self.enable_ipv6 = enable_ipv6
|
||||
|
||||
|
||||
MetricsType = Literal[
|
||||
"cpu",
|
||||
"disk",
|
||||
"network",
|
||||
]
|
||||
|
||||
|
||||
class GetMetricsResponse(BaseDomain):
|
||||
"""Get a Server Metrics Response Domain
|
||||
|
||||
:param metrics: The Server metrics
|
||||
"""
|
||||
|
||||
__slots__ = ("metrics",)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
metrics: Metrics,
|
||||
):
|
||||
self.metrics = metrics
|
||||
|
|
|
@ -22,7 +22,7 @@ from textwrap import dedent
|
|||
logger = logging.getLogger("vendor")
|
||||
|
||||
HCLOUD_SOURCE_URL = "https://github.com/hetznercloud/hcloud-python"
|
||||
HCLOUD_VERSION = "v1.32.0"
|
||||
HCLOUD_VERSION = "v1.33.0"
|
||||
HCLOUD_VENDOR_PATH = "plugins/module_utils/vendor/hcloud"
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue