Пример #1
0
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))
Пример #2
0
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))
Пример #3
0
 def test_add_to_rcv3(self):
     """
     :func:`_rcv3.add_to_rcv3` attempts to perform the correct effect.
     """
     d = _rcv3.add_to_rcv3(self.request_bag, "lb_id", "server_id")
     (add_result, ) = self.successResultOf(d)
     self.assertEqual(add_result["cloud_server"], {"id": "server_id"})
     self.assertEqual(add_result["load_balancer_pool"], {"id": "lb_id"})
Пример #4
0
 def test_add_to_rcv3(self):
     """
     :func:`_rcv3.add_to_rcv3` attempts to perform the correct effect.
     """
     d = _rcv3.add_to_rcv3(self.request_bag, "lb_id", "server_id")
     (add_result,) = self.successResultOf(d)
     self.assertEqual(add_result["cloud_server"], {"id": "server_id"})
     self.assertEqual(add_result["load_balancer_pool"], {"id": "lb_id"})
Пример #5
0
 def test_add_to_rcv3(self):
     """
     :func:`_rcv3.add_to_rcv3` attempts to perform the correct effect.
     """
     disp = self.dispatcher("ba",
                            _rcv3_add_response_body("lb_id", "server_id"))
     request_bag = _RequestBag(dispatcher=disp, tenant_id="tid")
     d = _rcv3.add_to_rcv3(request_bag, "lb_id", "server_id")
     (add_result, ) = self.successResultOf(d)
     self.assertEqual(add_result["cloud_server"], {"id": "server_id"})
     self.assertEqual(add_result["load_balancer_pool"], {"id": "lb_id"})
Пример #6
0
 def test_add_to_rcv3(self):
     """
     :func:`_rcv3.add_to_rcv3` attempts to perform the correct effect.
     """
     disp = self.dispatcher(
         "ba", _rcv3_add_response_body("lb_id", "server_id"))
     request_bag = _RequestBag(dispatcher=disp, tenant_id="tid")
     d = _rcv3.add_to_rcv3(request_bag, "lb_id", "server_id")
     (add_result,) = self.successResultOf(d)
     self.assertEqual(add_result["cloud_server"], {"id": "server_id"})
     self.assertEqual(add_result["load_balancer_pool"], {"id": "lb_id"})