Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_bound_load_balancer_init(self, response_load_balancer):
bound_load_balancer = BoundLoadBalancer(
client=mock.MagicMock(),
data=response_load_balancer['load_balancer']
)
assert bound_load_balancer.id == 4711
assert bound_load_balancer.name == 'Web Frontend'
@pytest.mark.parametrize("load_balancer", [LoadBalancer(id=4711), BoundLoadBalancer(mock.MagicMock(), dict(id=1))])
def test_add_target(self, hetzner_client, load_balancer):
action = hetzner_client.load_balancers.add_target(load_balancer, LoadBalancerTarget(type="server", server=Server(id=1)))
assert action.id == 13
assert action.command == "add_target"
def bound_load_balancer(self, hetzner_client):
return BoundLoadBalancer(client=hetzner_client.load_balancers, data=dict(id=42))
def bound_load_balancer(self, hetzner_client):
return BoundLoadBalancer(client=hetzner_client.load_balancers, data=dict(id=14))
domain=service['health_check']['http']['domain'], path=service['health_check']['http']['path'],
response=service['health_check']['http']['response'],
tls=service['health_check']['http']['tls'],
status_codes=service['health_check']['http']['status_codes'])
tmp_services.append(tmp_service)
data['services'] = tmp_services
load_balancer_type = data.get("load_balancer_type")
if load_balancer_type is not None:
data['load_balancer_type'] = BoundLoadBalancerType(client._client.load_balancer_types, load_balancer_type)
location = data.get("location")
if location is not None:
data['location'] = BoundLocation(client._client.locations, location)
super(BoundLoadBalancer, self).__init__(client, data, complete)
New name to set
:param labels: Dict[str, str] (optional)
User-defined labels (key-value pairs)
:return: :class:`BoundLoadBalancer `
"""
data = {}
if name is not None:
data.update({"name": name})
if labels is not None:
data.update({"labels": labels})
response = self._client.request(
url="/load_balancers/{load_balancer_id}".format(load_balancer_id=load_balancer.id),
method="PUT",
json=data,
)
return BoundLoadBalancer(self, response["load_balancer"])
:return: (List[:class:`BoundLoadBalancer `], :class:`Meta `)
"""
params = {}
if name is not None:
params["name"] = name
if label_selector is not None:
params["label_selector"] = label_selector
if page is not None:
params["page"] = page
if per_page is not None:
params["per_page"] = per_page
response = self._client.request(url="/load_balancers", method="GET", params=params)
ass_load_balancers = [
BoundLoadBalancer(self, load_balancer_data) for load_balancer_data in response["load_balancers"]
]
return self._add_meta_to_result(ass_load_balancers, response)
def get_by_id(self, id):
# type: (int) -> BoundLoadBalancer
"""Get a specific Load Balancer
:param id: int
:return: :class:`BoundLoadBalancer
"""
response = self._client.request(
url="/load_balancers/{load_balancer_id}".format(load_balancer_id=id), method="GET"
)
return BoundLoadBalancer(self, response["load_balancer"])
"type": target.type,
"server": target.server,
"use_private_ip": target.use_private_ip
}
target_list.append(target_data)
data["targets"] = target_list
if network_zone is not None:
data["network_zone"] = network_zone
if location is not None:
data["location"] = location.id_or_name
response = self._client.request(url="/load_balancers", method="POST", json=data)
return CreateLoadBalancerResponse(load_balancer=BoundLoadBalancer(self, response["load_balancer"]),
action=BoundAction(self._client.actions, response['action']))