def remove_from_load_balancer(log, request_bag, lb_config, lb_response, clock=None): """ Remove a node from a load balancer. :param BoundLog log: A bound logger. :param request_bag: A request function. :param dict lb_config: An ``lb_config`` dictionary. :param lb_response: The response the load balancer provided when the server being removed was added. Type and shape is dependant on type of load balancer. :param IReactorTime clock: An optional clock, for testing. Will be passed on to implementations of node removal logic for specific load balancer APIs, if they support a clock. :returns: A Deferred that fires with :data:`None` if the operation completed successfully, or errbacks with an RequestError. """ lb_type = lb_config.get("type", "CloudLoadBalancer") if lb_type == "CloudLoadBalancer": cloudLoadBalancers = config_value('cloudLoadBalancers') endpoint = public_endpoint_url(request_bag.service_catalog, cloudLoadBalancers, request_bag.lb_region) auth_token = request_bag.auth_token loadbalancer_id = lb_config["loadBalancerId"] node_id = next(node_info["id"] for node_info in lb_response["nodes"]) return _remove_from_clb(log, endpoint, auth_token, loadbalancer_id, node_id, clock) elif lb_type == "RackConnectV3": lb_id = lb_config["loadBalancerId"] node_id = next(pair["cloud_server"]["id"] for pair in lb_response) return remove_from_rcv3(request_bag, lb_id, node_id) else: raise RuntimeError("Unknown cloud load balancer type! config: {}" .format(lb_config))
def test_remove_from_rcv3(self): """ :func:`_rcv3.add_to_rcv3` attempts to perform the correct effect. """ disp = self.dispatcher("bd", None) request_bag = _RequestBag(dispatcher=disp, tenant_id="tid") d = _rcv3.remove_from_rcv3(request_bag, "lb_id", "server_id") self.assertIdentical(self.successResultOf(d), None)
def remove_from_load_balancer(log, request_bag, lb_config, lb_response, clock=None): """ Remove a node from a load balancer. :param BoundLog log: A bound logger. :param request_bag: A request function. :param dict lb_config: An ``lb_config`` dictionary. :param lb_response: The response the load balancer provided when the server being removed was added. Type and shape is dependant on type of load balancer. :param IReactorTime clock: An optional clock, for testing. Will be passed on to implementations of node removal logic for specific load balancer APIs, if they support a clock. :returns: A Deferred that fires with :data:`None` if the operation completed successfully, or errbacks with an RequestError. """ lb_type = lb_config.get("type", "CloudLoadBalancer") if lb_type == "CloudLoadBalancer": cloudLoadBalancers = config_value('cloudLoadBalancers') endpoint = public_endpoint_url(request_bag.service_catalog, cloudLoadBalancers, request_bag.lb_region) auth_token = request_bag.auth_token loadbalancer_id = lb_config["loadBalancerId"] node_id = next(node_info["id"] for node_info in lb_response["nodes"]) return _remove_from_clb(log, endpoint, auth_token, loadbalancer_id, node_id, clock) elif lb_type == "RackConnectV3": lb_id = lb_config["loadBalancerId"] node_id = next(pair["cloud_server"]["id"] for pair in lb_response) return remove_from_rcv3(request_bag, lb_id, node_id) else: raise RuntimeError( "Unknown cloud load balancer type! config: {}".format(lb_config))
def test_remove_from_rcv3(self): """ :func:`_rcv3.add_to_rcv3` attempts to perform the correct effect. """ d = _rcv3.remove_from_rcv3(self.request_bag, "lb_id", "server_id") self.assertIdentical(self.successResultOf(d), None)