Skip to content

Commit b2b63c4

Browse files
committed
feat: add server and load balancer private_net_for helper method
1 parent 9f3e282 commit b2b63c4

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

hcloud/load_balancers/domain.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from ..load_balancer_types import BoundLoadBalancerType
1414
from ..locations import BoundLocation
1515
from ..metrics import Metrics
16-
from ..networks import BoundNetwork
16+
from ..networks import BoundNetwork, Network
1717
from ..servers import BoundServer
1818
from .client import BoundLoadBalancer
1919

@@ -107,6 +107,16 @@ def __init__(
107107
self.ingoing_traffic = ingoing_traffic
108108
self.included_traffic = included_traffic
109109

110+
def private_net_for(self, network: BoundNetwork | Network) -> PrivateNet | None:
111+
"""
112+
Returns the load balancer's network attachment information in the given Network,
113+
and None if no attachment was found.
114+
"""
115+
for o in self.private_net:
116+
if o.network.id == network.id:
117+
return o
118+
return None
119+
110120

111121
class LoadBalancerService(BaseDomain):
112122
"""LoadBalancerService Domain

hcloud/servers/domain.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from ..images import BoundImage
1515
from ..isos import BoundIso
1616
from ..metrics import Metrics
17-
from ..networks import BoundNetwork
17+
from ..networks import BoundNetwork, Network
1818
from ..placement_groups import BoundPlacementGroup
1919
from ..primary_ips import BoundPrimaryIP, PrimaryIP
2020
from ..server_types import BoundServerType
@@ -154,6 +154,16 @@ def __init__(
154154
self.primary_disk_size = primary_disk_size
155155
self.placement_group = placement_group
156156

157+
def private_net_for(self, network: BoundNetwork | Network) -> PrivateNet | None:
158+
"""
159+
Returns the server's network attachment information in the given Network,
160+
and None if no attachment was found.
161+
"""
162+
for o in self.private_net:
163+
if o.network.id == network.id:
164+
return o
165+
return None
166+
157167

158168
class CreateServerResponse(BaseDomain):
159169
"""Create Server Response Domain

0 commit comments

Comments
 (0)