Example #1
0
    def _validate_port_and_fill_or_validate_subnet(load_balancer):
        port = validate.port_exists(port_id=load_balancer.vip_port_id)
        validate.check_port_in_use(port)
        load_balancer.vip_network_id = port.network_id

        # validate the request vip port whether applied the qos_policy and
        # store the port_qos_policy to loadbalancer obj if possible. The
        # default behavior is that if 'vip_qos_policy_id' is specified in the
        # request, it will override the qos_policy applied on vip_port.
        port_qos_policy_id = port.qos_policy_id
        if (port_qos_policy_id and isinstance(load_balancer.vip_qos_policy_id,
                                              wtypes.UnsetType)):
            load_balancer.vip_qos_policy_id = port_qos_policy_id

        # Identify the subnet for this port
        if load_balancer.vip_subnet_id:
            validate.subnet_exists(subnet_id=load_balancer.vip_subnet_id)
        else:
            if load_balancer.vip_address:
                for port_fixed_ip in port.fixed_ips:
                    if port_fixed_ip.ip_address == load_balancer.vip_address:
                        load_balancer.vip_subnet_id = port_fixed_ip.subnet_id
                        break
                if not load_balancer.vip_subnet_id:
                    raise exceptions.ValidationException(
                        detail=_("Specified VIP address not found on the "
                                 "specified VIP port."))
            elif len(port.fixed_ips) == 1:
                load_balancer.vip_subnet_id = port.fixed_ips[0].subnet_id
            else:
                raise exceptions.ValidationException(detail=_(
                    "VIP port's subnet could not be determined. Please "
                    "specify either a VIP subnet or address."))
Example #2
0
    def _validate_port_and_fill_or_validate_subnet(load_balancer):
        port = validate.port_exists(port_id=load_balancer.vip_port_id)
        validate.check_port_in_use(port)
        load_balancer.vip_network_id = port.network_id

        # validate the request vip port whether applied the qos_policy and
        # store the port_qos_policy to loadbalancer obj if possible. The
        # default behavior is that if 'vip_qos_policy_id' is specified in the
        # request, it will override the qos_policy applied on vip_port.
        port_qos_policy_id = port.qos_policy_id
        if (port_qos_policy_id and
                isinstance(load_balancer.vip_qos_policy_id, wtypes.UnsetType)):
            load_balancer.vip_qos_policy_id = port_qos_policy_id

        # Identify the subnet for this port
        if load_balancer.vip_subnet_id:
            validate.subnet_exists(subnet_id=load_balancer.vip_subnet_id)
        else:
            if load_balancer.vip_address:
                for port_fixed_ip in port.fixed_ips:
                    if port_fixed_ip.ip_address == load_balancer.vip_address:
                        load_balancer.vip_subnet_id = port_fixed_ip.subnet_id
                        break
                if not load_balancer.vip_subnet_id:
                    raise exceptions.ValidationException(detail=_(
                        "Specified VIP address not found on the "
                        "specified VIP port."))
            elif len(port.fixed_ips) == 1:
                load_balancer.vip_subnet_id = port.fixed_ips[0].subnet_id
            else:
                raise exceptions.ValidationException(detail=_(
                    "VIP port's subnet could not be determined. Please "
                    "specify either a VIP subnet or address."))
Example #3
0
    def _validate_port_and_fill_or_validate_subnet(load_balancer,
                                                   context=None):
        port = validate.port_exists(port_id=load_balancer.vip_port_id,
                                    context=context)
        validate.check_port_in_use(port)
        load_balancer.vip_network_id = port.network_id

        # validate the request vip port whether applied the qos_policy and
        # store the port_qos_policy to loadbalancer obj if possible. The
        # default behavior is that if 'vip_qos_policy_id' is specified in the
        # request, it will override the qos_policy applied on vip_port.
        port_qos_policy_id = port.qos_policy_id
        if (port_qos_policy_id and
                isinstance(load_balancer.vip_qos_policy_id, wtypes.UnsetType)):
            load_balancer.vip_qos_policy_id = port_qos_policy_id

        if load_balancer.vip_subnet_id:
            # If we were provided a subnet_id, validate it exists and that
            # there is a fixed_ip on the port that matches the provided subnet
            validate.subnet_exists(subnet_id=load_balancer.vip_subnet_id,
                                   context=context)
            for port_fixed_ip in port.fixed_ips:
                if port_fixed_ip.subnet_id == load_balancer.vip_subnet_id:
                    load_balancer.vip_address = port_fixed_ip.ip_address
                    break  # Just pick the first address found in the subnet
            if not load_balancer.vip_address:
                raise exceptions.ValidationException(detail=_(
                    "No VIP address found on the specified VIP port within "
                    "the specified subnet."))
        elif load_balancer.vip_address:
            normalized_lb_ip = ipaddress.ip_address(
                load_balancer.vip_address).compressed
            for port_fixed_ip in port.fixed_ips:
                normalized_port_ip = ipaddress.ip_address(
                    port_fixed_ip.ip_address).compressed
                if normalized_port_ip == normalized_lb_ip:
                    load_balancer.vip_subnet_id = port_fixed_ip.subnet_id
                    break
            if not load_balancer.vip_subnet_id:
                raise exceptions.ValidationException(detail=_(
                    "Specified VIP address not found on the "
                    "specified VIP port."))
        elif len(port.fixed_ips) == 1:
            # User provided only a port, get the subnet and address from it
            load_balancer.vip_subnet_id = port.fixed_ips[0].subnet_id
            load_balancer.vip_address = port.fixed_ips[0].ip_address
        else:
            raise exceptions.ValidationException(detail=_(
                "VIP port's subnet could not be determined. Please "
                "specify either a VIP subnet or address."))