Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add load balancer target health status field #288

Merged
merged 1 commit into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/api.clients.load_balancers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ LoadBalancerClient
.. autoclass:: hcloud.load_balancers.domain.LoadBalancerTarget
:members:

.. autoclass:: hcloud.load_balancers.domain.LoadBalancerTargetHealthStatus
:members:

.. autoclass:: hcloud.load_balancers.domain.LoadBalancerTargetLabelSelector
:members:

Expand Down
1 change: 1 addition & 0 deletions hcloud/load_balancers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
LoadBalancerService,
LoadBalancerServiceHttp,
LoadBalancerTarget,
LoadBalancerTargetHealthStatus,
LoadBalancerTargetIP,
LoadBalancerTargetLabelSelector,
PrivateNet,
Expand Down
12 changes: 12 additions & 0 deletions hcloud/load_balancers/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
LoadBalancerService,
LoadBalancerServiceHttp,
LoadBalancerTarget,
LoadBalancerTargetHealthStatus,
LoadBalancerTargetIP,
LoadBalancerTargetLabelSelector,
PrivateNet,
Expand Down Expand Up @@ -83,6 +84,17 @@ def __init__(self, client: LoadBalancersClient, data: dict, complete: bool = Tru
tmp_target.use_private_ip = target["use_private_ip"]
elif target["type"] == "ip":
tmp_target.ip = LoadBalancerTargetIP(ip=target["ip"]["ip"])

target_health_status = target.get("health_status")
apricote marked this conversation as resolved.
Show resolved Hide resolved
if target_health_status is not None:
tmp_target.health_status = [
LoadBalancerTargetHealthStatus(
listen_port=target_health_status_item["listen_port"],
status=target_health_status_item["status"],
)
for target_health_status_item in target_health_status
]

tmp_targets.append(tmp_target)
data["targets"] = tmp_targets

Expand Down
20 changes: 20 additions & 0 deletions hcloud/load_balancers/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ class LoadBalancerTarget(BaseDomain):
Target IP
:param use_private_ip: bool
use the private IP instead of primary public IP
:param health_status: list
List of health statuses of the services on this target. Only present for target types "server" and "ip".
"""

def __init__(
Expand All @@ -322,12 +324,14 @@ def __init__(
label_selector: LoadBalancerTargetLabelSelector | None = None,
ip: LoadBalancerTargetIP | None = None,
use_private_ip: bool | None = None,
health_status: list[LoadBalancerTargetHealthStatus] | None = None,
):
self.type = type
self.server = server
self.label_selector = label_selector
self.ip = ip
self.use_private_ip = use_private_ip
self.health_status = health_status

def to_payload(self) -> dict[str, Any]:
payload: dict[str, Any] = {
Expand All @@ -354,6 +358,22 @@ def to_payload(self) -> dict[str, Any]:
return payload


class LoadBalancerTargetHealthStatus(BaseDomain):
jooola marked this conversation as resolved.
Show resolved Hide resolved
"""LoadBalancerTargetHealthStatus Domain

:param listen_port: Load Balancer Target listen port
:param status: Load Balancer Target status. Choices: healthy, unhealthy, unknown
"""

def __init__(
self,
listen_port: int | None = None,
status: str | None = None,
):
self.listen_port = listen_port
self.status = status


class LoadBalancerTargetLabelSelector(BaseDomain):
"""LoadBalancerTargetLabelSelector Domain

Expand Down