def add_to_load_balancer(log, request_bag, lb_config, server_details, undo, clock=None): """ Adds a given server to a given load balancer. :param log: A bound logger. :param callable request_bag: A request function. :param str lb_config: An ``lb_config`` dictionary specifying which load balancer to add the server to. :param dict server_details: The server details, as returned by Nova. :return: Deferred that fires with the load balancer response. The structure of this object depends on the load balancer type. """ 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 ip_address = _servicenet_address(server_details["server"]) return add_to_clb(log, endpoint, auth_token, lb_config, ip_address, undo, clock) elif lb_type == "RackConnectV3": lb_id = lb_config["loadBalancerId"] server_id = server_details["server"]["id"] return add_to_rcv3(request_bag, lb_id, server_id) else: raise RuntimeError( "Unknown cloud load balancer type! config: {}".format(lb_config))
def add_to_load_balancer(log, request_bag, lb_config, server_details, undo, clock=None): """ Adds a given server to a given load balancer. :param log: A bound logger. :param callable request_bag: A request function. :param str lb_config: An ``lb_config`` dictionary specifying which load balancer to add the server to. :param dict server_details: The server details, as returned by Nova. :return: Deferred that fires with the load balancer response. The structure of this object depends on the load balancer type. """ 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 ip_address = _servicenet_address(server_details["server"]) return add_to_clb(log, endpoint, auth_token, lb_config, ip_address, undo, clock) elif lb_type == "RackConnectV3": lb_id = lb_config["loadBalancerId"] server_id = server_details["server"]["id"] return add_to_rcv3(request_bag, lb_id, server_id) else: raise RuntimeError("Unknown cloud load balancer type! config: {}" .format(lb_config))
def test_no_servicenet_address(self): """ :func:`_servicenet_address` returns :data:`None` if the server has no ServiceNet address. """ del self.addresses["private"] self.assertEqual(_servicenet_address(self.server_dict), "")
def test_servicenet_address(self): """ :func:`_servicenet_address` returns the correct ServiceNet address, which is the first IPv4 address in the ``private`` group in the 10.x.x.x range. It even does this when there are other addresses in the ``private`` group. This happens when the tenant specifies their own network named ``private``. """ self.assertEqual(_servicenet_address(self.server_dict), "10.0.0.1")