Skip to content

Commit d565239

Browse files
committed
refactor: use parent to access other resources clients (2)
1 parent 1703985 commit d565239

File tree

9 files changed

+31
-31
lines changed

9 files changed

+31
-31
lines changed

hcloud/datacenters/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,25 @@ class BoundDatacenter(BoundModelBase, Datacenter):
1616
def __init__(self, client: DatacentersClient, data: dict):
1717
location = data.get("location")
1818
if location is not None:
19-
data["location"] = BoundLocation(client._client.locations, location)
19+
data["location"] = BoundLocation(client._parent.locations, location)
2020

2121
server_types = data.get("server_types")
2222
if server_types is not None:
2323
available = [
2424
BoundServerType(
25-
client._client.server_types, {"id": server_type}, complete=False
25+
client._parent.server_types, {"id": server_type}, complete=False
2626
)
2727
for server_type in server_types["available"]
2828
]
2929
supported = [
3030
BoundServerType(
31-
client._client.server_types, {"id": server_type}, complete=False
31+
client._parent.server_types, {"id": server_type}, complete=False
3232
)
3333
for server_type in server_types["supported"]
3434
]
3535
available_for_migration = [
3636
BoundServerType(
37-
client._client.server_types, {"id": server_type}, complete=False
37+
client._parent.server_types, {"id": server_type}, complete=False
3838
)
3939
for server_type in server_types["available_for_migration"]
4040
]

hcloud/firewalls/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def __init__(self, client: FirewallsClient, data: dict, complete: bool = True):
5252
type=resource["type"],
5353
server=(
5454
BoundServer(
55-
client._client.servers,
55+
client._parent.servers,
5656
resource.get("server"),
5757
complete=False,
5858
)
@@ -68,7 +68,7 @@ def __init__(self, client: FirewallsClient, data: dict, complete: bool = True):
6868
FirewallResource(
6969
type=firewall_resource["type"],
7070
server=BoundServer(
71-
client._client.servers,
71+
client._parent.servers,
7272
firewall_resource["server"],
7373
complete=False,
7474
),

hcloud/floating_ips/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ def __init__(self, client: FloatingIPsClient, data: dict, complete: bool = True)
2525
server = data.get("server")
2626
if server is not None:
2727
data["server"] = BoundServer(
28-
client._client.servers, {"id": server}, complete=False
28+
client._parent.servers, {"id": server}, complete=False
2929
)
3030

3131
home_location = data.get("home_location")
3232
if home_location is not None:
3333
data["home_location"] = BoundLocation(
34-
client._client.locations, home_location
34+
client._parent.locations, home_location
3535
)
3636

3737
super().__init__(client, data, complete)

hcloud/images/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ def __init__(self, client: ImagesClient, data: dict):
2323
created_from = data.get("created_from")
2424
if created_from is not None:
2525
data["created_from"] = BoundServer(
26-
client._client.servers, created_from, complete=False
26+
client._parent.servers, created_from, complete=False
2727
)
2828
bound_to = data.get("bound_to")
2929
if bound_to is not None:
3030
data["bound_to"] = BoundServer(
31-
client._client.servers, {"id": bound_to}, complete=False
31+
client._parent.servers, {"id": bound_to}, complete=False
3232
)
3333

3434
super().__init__(client, data)

hcloud/load_balancers/client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def __init__(self, client: LoadBalancersClient, data: dict, complete: bool = Tru
6464
private_nets = [
6565
PrivateNet(
6666
network=BoundNetwork(
67-
client._client.networks,
67+
client._parent.networks,
6868
{"id": private_net["network"]},
6969
complete=False,
7070
),
@@ -81,7 +81,7 @@ def __init__(self, client: LoadBalancersClient, data: dict, complete: bool = Tru
8181
tmp_target = LoadBalancerTarget(type=target["type"])
8282
if target["type"] == "server":
8383
tmp_target.server = BoundServer(
84-
client._client.servers, data=target["server"], complete=False
84+
client._parent.servers, data=target["server"], complete=False
8585
)
8686
tmp_target.use_private_ip = target["use_private_ip"]
8787
elif target["type"] == "label_selector":
@@ -124,7 +124,7 @@ def __init__(self, client: LoadBalancersClient, data: dict, complete: bool = Tru
124124
)
125125
tmp_service.http.certificates = [
126126
BoundCertificate(
127-
client._client.certificates,
127+
client._parent.certificates,
128128
{"id": certificate},
129129
complete=False,
130130
)
@@ -152,12 +152,12 @@ def __init__(self, client: LoadBalancersClient, data: dict, complete: bool = Tru
152152
load_balancer_type = data.get("load_balancer_type")
153153
if load_balancer_type is not None:
154154
data["load_balancer_type"] = BoundLoadBalancerType(
155-
client._client.load_balancer_types, load_balancer_type
155+
client._parent.load_balancer_types, load_balancer_type
156156
)
157157

158158
location = data.get("location")
159159
if location is not None:
160-
data["location"] = BoundLocation(client._client.locations, location)
160+
data["location"] = BoundLocation(client._parent.locations, location)
161161

162162
super().__init__(client, data, complete)
163163

hcloud/networks/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def __init__(self, client: NetworksClient, data: dict, complete: bool = True):
3232
servers = data.get("servers", [])
3333
if servers is not None:
3434
servers = [
35-
BoundServer(client._client.servers, {"id": server}, complete=False)
35+
BoundServer(client._parent.servers, {"id": server}, complete=False)
3636
for server in servers
3737
]
3838
data["servers"] = servers

hcloud/primary_ips/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def __init__(self, client: PrimaryIPsClient, data: dict, complete: bool = True):
2222

2323
datacenter = data.get("datacenter", {})
2424
if datacenter:
25-
data["datacenter"] = BoundDatacenter(client._client.datacenters, datacenter)
25+
data["datacenter"] = BoundDatacenter(client._parent.datacenters, datacenter)
2626

2727
super().__init__(client, data, complete)
2828

hcloud/servers/client.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,28 +57,28 @@ class BoundServer(BoundModelBase, Server):
5757
def __init__(self, client: ServersClient, data: dict, complete: bool = True):
5858
datacenter = data.get("datacenter")
5959
if datacenter is not None:
60-
data["datacenter"] = BoundDatacenter(client._client.datacenters, datacenter)
60+
data["datacenter"] = BoundDatacenter(client._parent.datacenters, datacenter)
6161

6262
volumes = data.get("volumes", [])
6363
if volumes:
6464
volumes = [
65-
BoundVolume(client._client.volumes, {"id": volume}, complete=False)
65+
BoundVolume(client._parent.volumes, {"id": volume}, complete=False)
6666
for volume in volumes
6767
]
6868
data["volumes"] = volumes
6969

7070
image = data.get("image", None)
7171
if image is not None:
72-
data["image"] = BoundImage(client._client.images, image)
72+
data["image"] = BoundImage(client._parent.images, image)
7373

7474
iso = data.get("iso", None)
7575
if iso is not None:
76-
data["iso"] = BoundIso(client._client.isos, iso)
76+
data["iso"] = BoundIso(client._parent.isos, iso)
7777

7878
server_type = data.get("server_type")
7979
if server_type is not None:
8080
data["server_type"] = BoundServerType(
81-
client._client.server_types, server_type
81+
client._parent.server_types, server_type
8282
)
8383

8484
public_net = data.get("public_net")
@@ -90,7 +90,7 @@ def __init__(self, client: ServersClient, data: dict, complete: bool = True):
9090
)
9191
ipv4_primary_ip = (
9292
BoundPrimaryIP(
93-
client._client.primary_ips,
93+
client._parent.primary_ips,
9494
{"id": public_net["ipv4"]["id"]},
9595
complete=False,
9696
)
@@ -104,7 +104,7 @@ def __init__(self, client: ServersClient, data: dict, complete: bool = True):
104104
)
105105
ipv6_primary_ip = (
106106
BoundPrimaryIP(
107-
client._client.primary_ips,
107+
client._parent.primary_ips,
108108
{"id": public_net["ipv6"]["id"]},
109109
complete=False,
110110
)
@@ -113,14 +113,14 @@ def __init__(self, client: ServersClient, data: dict, complete: bool = True):
113113
)
114114
floating_ips = [
115115
BoundFloatingIP(
116-
client._client.floating_ips, {"id": floating_ip}, complete=False
116+
client._parent.floating_ips, {"id": floating_ip}, complete=False
117117
)
118118
for floating_ip in public_net["floating_ips"]
119119
]
120120
firewalls = [
121121
PublicNetworkFirewall(
122122
BoundFirewall(
123-
client._client.firewalls, {"id": firewall["id"]}, complete=False
123+
client._parent.firewalls, {"id": firewall["id"]}, complete=False
124124
),
125125
status=firewall["status"],
126126
)
@@ -143,7 +143,7 @@ def __init__(self, client: ServersClient, data: dict, complete: bool = True):
143143
private_nets = [
144144
PrivateNet(
145145
network=BoundNetwork(
146-
client._client.networks,
146+
client._parent.networks,
147147
{"id": private_net["network"]},
148148
complete=False,
149149
),
@@ -158,7 +158,7 @@ def __init__(self, client: ServersClient, data: dict, complete: bool = True):
158158
placement_group = data.get("placement_group")
159159
if placement_group:
160160
placement_group = BoundPlacementGroup(
161-
client._client.placement_groups, placement_group
161+
client._parent.placement_groups, placement_group
162162
)
163163
data["placement_group"] = placement_group
164164

@@ -996,7 +996,7 @@ def create_image(
996996
)
997997
return CreateImageResponse(
998998
action=BoundAction(self._parent.actions, response["action"]),
999-
image=BoundImage(self._client.images, response["image"]),
999+
image=BoundImage(self._parent.images, response["image"]),
10001000
)
10011001

10021002
def rebuild(

hcloud/volumes/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ class BoundVolume(BoundModelBase, Volume):
2121
def __init__(self, client: VolumesClient, data: dict, complete: bool = True):
2222
location = data.get("location")
2323
if location is not None:
24-
data["location"] = BoundLocation(client._client.locations, location)
24+
data["location"] = BoundLocation(client._parent.locations, location)
2525

2626
# pylint: disable=import-outside-toplevel
2727
from ..servers import BoundServer
2828

2929
server = data.get("server")
3030
if server is not None:
3131
data["server"] = BoundServer(
32-
client._client.servers, {"id": server}, complete=False
32+
client._parent.servers, {"id": server}, complete=False
3333
)
3434
super().__init__(client, data, complete)
3535

0 commit comments

Comments
 (0)