Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package python-hcloud for openSUSE:Factory checked in at 2023-12-28 23:01:41 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-hcloud (Old) and /work/SRC/openSUSE:Factory/.python-hcloud.new.28375 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-hcloud" Thu Dec 28 23:01:41 2023 rev:6 rq:1135281 version:1.33.0 Changes: -------- --- /work/SRC/openSUSE:Factory/python-hcloud/python-hcloud.changes 2023-12-08 22:32:42.717453693 +0100 +++ /work/SRC/openSUSE:Factory/.python-hcloud.new.28375/python-hcloud.changes 2023-12-28 23:03:19.310517739 +0100 @@ -1,0 +2,7 @@ +Wed Dec 27 10:53:21 UTC 2023 - Dirk Müller <dmuel...@suse.com> + +- update to 1.33.0: + * add metrics endpoint for load balancers and servers (#331) + * fallback to error code when message is unset (#328) + +------------------------------------------------------------------- Old: ---- hcloud-1.32.0.tar.gz New: ---- hcloud-1.33.0.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-hcloud.spec ++++++ --- /var/tmp/diff_new_pack.2OBLtv/_old 2023-12-28 23:03:20.022543762 +0100 +++ /var/tmp/diff_new_pack.2OBLtv/_new 2023-12-28 23:03:20.022543762 +0100 @@ -17,7 +17,7 @@ Name: python-hcloud -Version: 1.32.0 +Version: 1.33.0 Release: 0 Summary: Hetzner Cloud Python library License: MIT ++++++ hcloud-1.32.0.tar.gz -> hcloud-1.33.0.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hcloud-1.32.0/CHANGELOG.md new/hcloud-1.33.0/CHANGELOG.md --- old/hcloud-1.32.0/CHANGELOG.md 2023-11-17 15:09:57.000000000 +0100 +++ new/hcloud-1.33.0/CHANGELOG.md 2023-12-19 17:33:48.000000000 +0100 @@ -1,5 +1,27 @@ # Changelog +## [1.33.0](https://github.com/hetznercloud/hcloud-python/compare/v1.32.0...v1.33.0) (2023-12-19) + + +### Features + +* add metrics endpoint for load balancers and servers ([#331](https://github.com/hetznercloud/hcloud-python/issues/331)) ([ee3c54f](https://github.com/hetznercloud/hcloud-python/commit/ee3c54fd1b6963533bc9d1e1f9ff57f6c5872cd5)) + + +### Bug Fixes + +* fallback to error code when message is unset ([#328](https://github.com/hetznercloud/hcloud-python/issues/328)) ([1c94153](https://github.com/hetznercloud/hcloud-python/commit/1c94153d93acd567548604b08b5fabeabd8d33d9)) + + +### Dependencies + +* update actions/setup-python action to v5 ([#335](https://github.com/hetznercloud/hcloud-python/issues/335)) ([2ac252d](https://github.com/hetznercloud/hcloud-python/commit/2ac252d18ba6079d5372c6ab9e3f67b4740db465)) +* update dependency sphinx-rtd-theme to v2 ([#330](https://github.com/hetznercloud/hcloud-python/issues/330)) ([7cc4335](https://github.com/hetznercloud/hcloud-python/commit/7cc4335cacab6073cf39a0ecbecf8890903d5bca)) +* update pre-commit hook psf/black-pre-commit-mirror to v23.12.0 ([#338](https://github.com/hetznercloud/hcloud-python/issues/338)) ([38e4748](https://github.com/hetznercloud/hcloud-python/commit/38e4748d3d194d37ea3d0c63683609f5db432e0d)) +* update pre-commit hook pycqa/isort to v5.13.0 ([#336](https://github.com/hetznercloud/hcloud-python/issues/336)) ([3244cfe](https://github.com/hetznercloud/hcloud-python/commit/3244cfef2f90ef52d0fb791d514d6afe481aa4d7)) +* update pre-commit hook pycqa/isort to v5.13.1 ([#337](https://github.com/hetznercloud/hcloud-python/issues/337)) ([020a0ef](https://github.com/hetznercloud/hcloud-python/commit/020a0eff6bc2b63d16b339fd5d4c3ea3610c0509)) +* update pre-commit hook pycqa/isort to v5.13.2 ([#339](https://github.com/hetznercloud/hcloud-python/issues/339)) ([b46df8c](https://github.com/hetznercloud/hcloud-python/commit/b46df8cbb263945c59ce4408e0a7189d19d9c597)) + ## [1.32.0](https://github.com/hetznercloud/hcloud-python/compare/v1.31.0...v1.32.0) (2023-11-17) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hcloud-1.32.0/PKG-INFO new/hcloud-1.33.0/PKG-INFO --- old/hcloud-1.32.0/PKG-INFO 2023-11-17 15:10:09.478945300 +0100 +++ new/hcloud-1.33.0/PKG-INFO 2023-12-19 17:34:00.156214000 +0100 @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: hcloud -Version: 1.32.0 +Version: 1.33.0 Summary: Official Hetzner Cloud python library Home-page: https://github.com/hetznercloud/hcloud-python Author: Hetzner Cloud GmbH @@ -28,7 +28,7 @@ Requires-Dist: requests>=2.20 Provides-Extra: docs Requires-Dist: sphinx<7.3,>=7.2.2; extra == "docs" -Requires-Dist: sphinx-rtd-theme<1.4,>=1.3.0; extra == "docs" +Requires-Dist: sphinx-rtd-theme<2.1,>=2; extra == "docs" Requires-Dist: myst-parser<2.1,>=2.0.0; extra == "docs" Requires-Dist: watchdog<3.1,>=3.0.0; extra == "docs" Provides-Extra: test diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hcloud-1.32.0/hcloud/__version__.py new/hcloud-1.33.0/hcloud/__version__.py --- old/hcloud-1.32.0/hcloud/__version__.py 2023-11-17 15:09:57.000000000 +0100 +++ new/hcloud-1.33.0/hcloud/__version__.py 2023-12-19 17:33:48.000000000 +0100 @@ -1,3 +1,3 @@ from __future__ import annotations -VERSION = "1.32.0" # x-release-please-version +VERSION = "1.33.0" # x-release-please-version diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hcloud-1.32.0/hcloud/_exceptions.py new/hcloud-1.33.0/hcloud/_exceptions.py --- old/hcloud-1.32.0/hcloud/_exceptions.py 2023-11-17 15:09:57.000000000 +0100 +++ new/hcloud-1.33.0/hcloud/_exceptions.py 2023-12-19 17:33:48.000000000 +0100 @@ -10,8 +10,8 @@ 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 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hcloud-1.32.0/hcloud/load_balancers/__init__.py new/hcloud-1.33.0/hcloud/load_balancers/__init__.py --- old/hcloud-1.32.0/hcloud/load_balancers/__init__.py 2023-11-17 15:09:57.000000000 +0100 +++ new/hcloud-1.33.0/hcloud/load_balancers/__init__.py 2023-12-19 17:33:48.000000000 +0100 @@ -7,6 +7,7 @@ ) from .domain import ( # noqa: F401 CreateLoadBalancerResponse, + GetMetricsResponse, IPv4Address, IPv6Network, LoadBalancer, diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hcloud-1.32.0/hcloud/load_balancers/client.py new/hcloud-1.33.0/hcloud/load_balancers/client.py --- old/hcloud-1.32.0/hcloud/load_balancers/client.py 2023-11-17 15:09:57.000000000 +0100 +++ new/hcloud-1.33.0/hcloud/load_balancers/client.py 2023-12-19 17:33:48.000000000 +0100 @@ -1,16 +1,21 @@ from __future__ import annotations +from datetime import datetime from typing import TYPE_CHECKING, Any, NamedTuple +from dateutil.parser import isoparse + 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 +28,7 @@ LoadBalancerTargetHealthStatus, LoadBalancerTargetIP, LoadBalancerTargetLabelSelector, + MetricsType, PrivateNet, PublicNetwork, ) @@ -177,6 +183,28 @@ """ 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 +561,46 @@ ) 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, diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hcloud-1.32.0/hcloud/load_balancers/domain.py new/hcloud-1.33.0/hcloud/load_balancers/domain.py --- old/hcloud-1.32.0/hcloud/load_balancers/domain.py 2023-11-17 15:09:57.000000000 +0100 +++ new/hcloud-1.33.0/hcloud/load_balancers/domain.py 2023-12-19 17:33:48.000000000 +0100 @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any +from typing import TYPE_CHECKING, Any, Literal from dateutil.parser import isoparse @@ -11,6 +11,7 @@ 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 @@ -508,3 +509,26 @@ ): 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 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hcloud-1.32.0/hcloud/metrics/__init__.py new/hcloud-1.33.0/hcloud/metrics/__init__.py --- old/hcloud-1.32.0/hcloud/metrics/__init__.py 1970-01-01 01:00:00.000000000 +0100 +++ new/hcloud-1.33.0/hcloud/metrics/__init__.py 2023-12-19 17:33:48.000000000 +0100 @@ -0,0 +1,3 @@ +from __future__ import annotations + +from .domain import Metrics, TimeSeries # noqa: F401 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hcloud-1.32.0/hcloud/metrics/domain.py new/hcloud-1.33.0/hcloud/metrics/domain.py --- old/hcloud-1.32.0/hcloud/metrics/domain.py 1970-01-01 01:00:00.000000000 +0100 +++ new/hcloud-1.33.0/hcloud/metrics/domain.py 2023-12-19 17:33:48.000000000 +0100 @@ -0,0 +1,46 @@ +from __future__ import annotations + +from datetime import datetime +from typing import Dict, List, Literal, Tuple + +from dateutil.parser import isoparse + +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 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hcloud-1.32.0/hcloud/servers/__init__.py new/hcloud-1.33.0/hcloud/servers/__init__.py --- old/hcloud-1.32.0/hcloud/servers/__init__.py 2023-11-17 15:09:57.000000000 +0100 +++ new/hcloud-1.33.0/hcloud/servers/__init__.py 2023-12-19 17:33:48.000000000 +0100 @@ -4,6 +4,7 @@ from .domain import ( # noqa: F401 CreateServerResponse, EnableRescueResponse, + GetMetricsResponse, IPv4Address, IPv6Network, PrivateNet, diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hcloud-1.32.0/hcloud/servers/client.py new/hcloud-1.33.0/hcloud/servers/client.py --- old/hcloud-1.32.0/hcloud/servers/client.py 2023-11-17 15:09:57.000000000 +0100 +++ new/hcloud-1.33.0/hcloud/servers/client.py 2023-12-19 17:33:48.000000000 +0100 @@ -1,8 +1,11 @@ from __future__ import annotations import warnings +from datetime import datetime from typing import TYPE_CHECKING, Any, NamedTuple +from dateutil.parser import isoparse + from ..actions import ActionsPageResult, BoundAction, ResourceActionsClient from ..core import BoundModelBase, ClientEntityBase, Meta from ..datacenters import BoundDatacenter @@ -10,6 +13,7 @@ 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 +21,10 @@ from .domain import ( CreateServerResponse, EnableRescueResponse, + GetMetricsResponse, IPv4Address, IPv6Network, + MetricsType, PrivateNet, PublicNetwork, PublicNetworkFirewall, @@ -210,6 +216,29 @@ """ 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 +771,46 @@ ) 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. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hcloud-1.32.0/hcloud/servers/domain.py new/hcloud-1.33.0/hcloud/servers/domain.py --- old/hcloud-1.32.0/hcloud/servers/domain.py 2023-11-17 15:09:57.000000000 +0100 +++ new/hcloud-1.33.0/hcloud/servers/domain.py 2023-12-19 17:33:48.000000000 +0100 @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Literal from dateutil.parser import isoparse @@ -13,6 +13,7 @@ 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 @@ -427,3 +428,25 @@ 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 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hcloud-1.32.0/hcloud.egg-info/PKG-INFO new/hcloud-1.33.0/hcloud.egg-info/PKG-INFO --- old/hcloud-1.32.0/hcloud.egg-info/PKG-INFO 2023-11-17 15:10:09.000000000 +0100 +++ new/hcloud-1.33.0/hcloud.egg-info/PKG-INFO 2023-12-19 17:34:00.000000000 +0100 @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: hcloud -Version: 1.32.0 +Version: 1.33.0 Summary: Official Hetzner Cloud python library Home-page: https://github.com/hetznercloud/hcloud-python Author: Hetzner Cloud GmbH @@ -28,7 +28,7 @@ Requires-Dist: requests>=2.20 Provides-Extra: docs Requires-Dist: sphinx<7.3,>=7.2.2; extra == "docs" -Requires-Dist: sphinx-rtd-theme<1.4,>=1.3.0; extra == "docs" +Requires-Dist: sphinx-rtd-theme<2.1,>=2; extra == "docs" Requires-Dist: myst-parser<2.1,>=2.0.0; extra == "docs" Requires-Dist: watchdog<3.1,>=3.0.0; extra == "docs" Provides-Extra: test diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hcloud-1.32.0/hcloud.egg-info/SOURCES.txt new/hcloud-1.33.0/hcloud.egg-info/SOURCES.txt --- old/hcloud-1.32.0/hcloud.egg-info/SOURCES.txt 2023-11-17 15:10:09.000000000 +0100 +++ new/hcloud-1.33.0/hcloud.egg-info/SOURCES.txt 2023-12-19 17:34:00.000000000 +0100 @@ -84,6 +84,8 @@ hcloud/locations/__init__.py hcloud/locations/client.py hcloud/locations/domain.py +hcloud/metrics/__init__.py +hcloud/metrics/domain.py hcloud/networks/__init__.py hcloud/networks/client.py hcloud/networks/domain.py diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hcloud-1.32.0/hcloud.egg-info/requires.txt new/hcloud-1.33.0/hcloud.egg-info/requires.txt --- old/hcloud-1.32.0/hcloud.egg-info/requires.txt 2023-11-17 15:10:09.000000000 +0100 +++ new/hcloud-1.33.0/hcloud.egg-info/requires.txt 2023-12-19 17:34:00.000000000 +0100 @@ -3,7 +3,7 @@ [docs] sphinx<7.3,>=7.2.2 -sphinx-rtd-theme<1.4,>=1.3.0 +sphinx-rtd-theme<2.1,>=2 myst-parser<2.1,>=2.0.0 watchdog<3.1,>=3.0.0 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hcloud-1.32.0/setup.py new/hcloud-1.33.0/setup.py --- old/hcloud-1.32.0/setup.py 2023-11-17 15:09:57.000000000 +0100 +++ new/hcloud-1.33.0/setup.py 2023-12-19 17:33:48.000000000 +0100 @@ -46,7 +46,7 @@ extras_require={ "docs": [ "sphinx>=7.2.2,<7.3", - "sphinx-rtd-theme>=1.3.0,<1.4", + "sphinx-rtd-theme>=2,<2.1", "myst-parser>=2.0.0,<2.1", "watchdog>=3.0.0,<3.1", ], diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hcloud-1.32.0/tests/unit/load_balancers/conftest.py new/hcloud-1.33.0/tests/unit/load_balancers/conftest.py --- old/hcloud-1.32.0/tests/unit/load_balancers/conftest.py 2023-11-17 15:09:57.000000000 +0100 +++ new/hcloud-1.33.0/tests/unit/load_balancers/conftest.py 2023-12-19 17:33:48.000000000 +0100 @@ -445,6 +445,26 @@ @pytest.fixture() +def response_get_metrics(): + return { + "metrics": { + "start": "2023-12-14T16:55:32+01:00", + "end": "2023-12-14T17:25:32+01:00", + "step": 9.0, + "time_series": { + "requests_per_second": { + "values": [ + [1702571114, "0.000000"], + [1702571123, "0.000000"], + [1702571132, "0.000000"], + ] + } + }, + } + } + + +@pytest.fixture() def response_add_service(): return { "action": { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hcloud-1.32.0/tests/unit/load_balancers/test_client.py new/hcloud-1.33.0/tests/unit/load_balancers/test_client.py --- old/hcloud-1.32.0/tests/unit/load_balancers/test_client.py 2023-11-17 15:09:57.000000000 +0100 +++ new/hcloud-1.33.0/tests/unit/load_balancers/test_client.py 2023-12-19 17:33:48.000000000 +0100 @@ -96,6 +96,30 @@ assert delete_success is True + def test_get_metrics( + self, + hetzner_client, + response_get_metrics, + bound_load_balancer: BoundLoadBalancer, + ): + hetzner_client.request.return_value = response_get_metrics + response = bound_load_balancer.get_metrics( + type=["requests_per_second"], + start="2023-12-14T16:55:32+01:00", + end="2023-12-14T16:55:32+01:00", + ) + hetzner_client.request.assert_called_with( + url="/load_balancers/14/metrics", + method="GET", + params={ + "type": "requests_per_second", + "start": "2023-12-14T16:55:32+01:00", + "end": "2023-12-14T16:55:32+01:00", + }, + ) + assert "requests_per_second" in response.metrics.time_series + assert len(response.metrics.time_series["requests_per_second"]["values"]) == 3 + def test_add_service( self, hetzner_client, response_add_service, bound_load_balancer ): diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hcloud-1.32.0/tests/unit/servers/conftest.py new/hcloud-1.33.0/tests/unit/servers/conftest.py --- old/hcloud-1.32.0/tests/unit/servers/conftest.py 2023-11-17 15:09:57.000000000 +0100 +++ new/hcloud-1.33.0/tests/unit/servers/conftest.py 2023-12-19 17:33:48.000000000 +0100 @@ -339,6 +339,54 @@ @pytest.fixture() +def response_get_metrics(): + return { + "metrics": { + "start": "2023-12-14T17:40:00+01:00", + "end": "2023-12-14T17:50:00+01:00", + "step": 3.0, + "time_series": { + "cpu": { + "values": [ + [1702572594, "0.3746000025854892"], + [1702572597, "0.35842215349409734"], + [1702572600, "0.7381525488039541"], + ] + }, + "disk.0.iops.read": { + "values": [ + [1702572594, "0"], + [1702572597, "0"], + [1702572600, "0"], + ] + }, + "disk.0.bandwidth.read": { + "values": [ + [1702572594, "0"], + [1702572597, "0"], + [1702572600, "0"], + ] + }, + "disk.0.bandwidth.write": { + "values": [ + [1702572594, "24064"], + [1702572597, "2048"], + [1702572600, "0"], + ] + }, + "disk.0.iops.write": { + "values": [ + [1702572594, "4.875"], + [1702572597, "0.25"], + [1702572600, "0"], + ] + }, + }, + } + } + + +@pytest.fixture() def response_simple_servers(): return { "servers": [ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hcloud-1.32.0/tests/unit/servers/test_client.py new/hcloud-1.33.0/tests/unit/servers/test_client.py --- old/hcloud-1.32.0/tests/unit/servers/test_client.py 2023-11-17 15:09:57.000000000 +0100 +++ new/hcloud-1.33.0/tests/unit/servers/test_client.py 2023-12-19 17:33:48.000000000 +0100 @@ -190,6 +190,32 @@ assert action.id == 1 assert action.progress == 0 + def test_get_metrics( + self, + hetzner_client, + bound_server: BoundServer, + response_get_metrics, + ): + hetzner_client.request.return_value = response_get_metrics + response = bound_server.get_metrics( + type=["cpu", "disk"], + start="2023-12-14T17:40:00+01:00", + end="2023-12-14T17:50:00+01:00", + ) + hetzner_client.request.assert_called_with( + url="/servers/14/metrics", + method="GET", + params={ + "type": "cpu,disk", + "start": "2023-12-14T17:40:00+01:00", + "end": "2023-12-14T17:50:00+01:00", + }, + ) + + assert "cpu" in response.metrics.time_series + assert "disk.0.iops.read" in response.metrics.time_series + assert len(response.metrics.time_series["disk.0.iops.read"]["values"]) == 3 + def test_power_off(self, hetzner_client, bound_server, generic_action): hetzner_client.request.return_value = generic_action action = bound_server.power_off()