Skip to content
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
2 changes: 2 additions & 0 deletions hcloud/load_balancers/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ def _load_balancer_target(
LoadBalancerTargetHealthStatus(
listen_port=item["listen_port"],
status=item["status"],
detail=item.get("detail"),
http_status_code=item.get("http_status_code"),
)
for item in raw_health_status
]
Expand Down
11 changes: 11 additions & 0 deletions hcloud/load_balancers/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,21 +488,32 @@ class LoadBalancerTargetHealthStatus(BaseDomain):

:param listen_port: Load Balancer Target listen port
:param status: Load Balancer Target status. Choices: healthy, unhealthy, unknown
:param detail: Additional details about why the health check failed. Only present when `status` is `unhealthy`.
Choices: unspecified, layer4_no_connection, layer4_timeout, layer7_timeout, unexpected_http_status,
unexpected_http_content
:param http_status_code: HTTP status code returned by the target during the last health check. Only present when
`status` is `unhealthy` and `detail` is `unexpected_http_status`.
"""

__api_properties__ = (
"listen_port",
"status",
"detail",
"http_status_code",
)
__slots__ = __api_properties__

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


class LoadBalancerTargetLabelSelector(BaseDomain):
Expand Down
17 changes: 15 additions & 2 deletions tests/unit/load_balancers/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,15 @@ def response_load_balancer():
{
"type": "server",
"server": {"id": 80},
"health_status": [{"listen_port": 443, "status": "healthy"}],
"health_status": [
{"listen_port": 443, "status": "healthy"},
{
"listen_port": 80,
"status": "unhealthy",
"detail": "unexpected_http_status",
"http_status_code": 503,
},
],
"label_selector": None,
"use_private_ip": False,
},
Expand All @@ -99,7 +107,12 @@ def response_load_balancer():
"use_private_ip": True,
"health_status": [
{"listen_port": 443, "status": "healthy"},
{"listen_port": 3000, "status": "healthy"},
{
"listen_port": 3000,
"status": "unhealthy",
"detail": "unexpected_http_status",
"http_status_code": 503,
},
],
}
],
Expand Down
6 changes: 5 additions & 1 deletion tests/unit/load_balancers/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,12 @@ def test_init_label_selector_nested_targets(self, response_load_balancer):
assert len(nested.health_status) == 2
assert nested.health_status[0].listen_port == 443
assert nested.health_status[0].status == "healthy"
assert nested.health_status[0].detail is None
assert nested.health_status[0].http_status_code is None
assert nested.health_status[1].listen_port == 3000
assert nested.health_status[1].status == "healthy"
assert nested.health_status[1].status == "unhealthy"
assert nested.health_status[1].detail == "unexpected_http_status"
assert nested.health_status[1].http_status_code == 503


class TestLoadBalancerslient:
Expand Down
Loading