Ejemplo n.º 1
0
  def _CreateBackendMessage(self, messages, group_uri, balancing_mode, args):
    """Create a backend message.

    Args:
      messages: The available API proto messages.
      group_uri: String. The backend instance group uri.
      balancing_mode: Backend.BalancingModeValueValuesEnum. The backend load
        balancing mode.
      args: argparse Namespace. The arguments given to the add-backend command.

    Returns:
      A new Backend message with its fields set according to the given
      arguments.
    """

    backend_services_utils.ValidateBalancingModeArgs(messages, args)
    return messages.Backend(
        balancingMode=balancing_mode,
        capacityScaler=args.capacity_scaler,
        description=args.description,
        group=group_uri,
        maxRate=args.max_rate,
        maxRatePerInstance=args.max_rate_per_instance,
        maxRatePerEndpoint=args.max_rate_per_endpoint,
        maxUtilization=args.max_utilization,
        maxConnections=args.max_connections,
        maxConnectionsPerInstance=args.max_connections_per_instance,
        maxConnectionsPerEndpoint=args.max_connections_per_endpoint)
Ejemplo n.º 2
0
def _ModifyBalancingModeArgs(messages, args, backend_to_update):
    """Update balancing mode fields in backend_to_update according to args.

  Args:
    messages: API messages class, determined by the release track.
    args: The arguments given to the update-backend command.
    backend_to_update: The backend message to modify.
  """

    backend_services_utils.ValidateBalancingModeArgs(
        messages, args, backend_to_update.balancingMode)

    if args.balancing_mode:
        backend_to_update.balancingMode = (
            messages.Backend.BalancingModeValueValuesEnum(args.balancing_mode))

        # If the balancing mode is being changed to RATE (CONNECTION), we must
        # clear the max utilization and max connections (rate) fields, otherwise
        # the server will reject the request.
        if (backend_to_update.balancingMode ==
                messages.Backend.BalancingModeValueValuesEnum.RATE):
            backend_to_update.maxUtilization = None
            backend_to_update.maxConnections = None
            backend_to_update.maxConnectionsPerInstance = None
        elif (backend_to_update.balancingMode ==
              messages.Backend.BalancingModeValueValuesEnum.CONNECTION):
            backend_to_update.maxUtilization = None
            backend_to_update.maxRate = None
            backend_to_update.maxRatePerInstance = None

    # Now, we set the parameters that control load balancing.
    # ValidateBalancingModeArgs takes care that the control parameters
    # are compatible with the balancing mode.
    if args.max_utilization is not None:
        backend_to_update.maxUtilization = args.max_utilization

    # max_rate, max_rate_per_instance, max_connections and
    # max_connections_per_instance are mutually exclusive arguments.
    if args.max_rate is not None:
        _ClearMutualExclusiveBackendCapacityThresholds(backend_to_update)
        backend_to_update.maxRate = args.max_rate
    elif args.max_rate_per_instance is not None:
        _ClearMutualExclusiveBackendCapacityThresholds(backend_to_update)
        backend_to_update.maxRatePerInstance = args.max_rate_per_instance
    elif args.max_connections is not None:
        _ClearMutualExclusiveBackendCapacityThresholds(backend_to_update)
        backend_to_update.maxConnections = args.max_connections
    elif args.max_connections_per_instance is not None:
        _ClearMutualExclusiveBackendCapacityThresholds(backend_to_update)
        backend_to_update.maxConnectionsPerInstance = (
            args.max_connections_per_instance)

    if args.capacity_scaler is not None:
        backend_to_update.capacityScaler = args.capacity_scaler
Ejemplo n.º 3
0
  def _CreateBackendMessage(self, messages, group_uri, balancing_mode, args):
    """Overrides."""

    backend_services_utils.ValidateBalancingModeArgs(messages, args)
    return messages.Backend(
        balancingMode=balancing_mode,
        capacityScaler=args.capacity_scaler,
        description=args.description,
        group=group_uri,
        maxRate=args.max_rate,
        maxRatePerInstance=args.max_rate_per_instance,
        maxRatePerEndpoint=args.max_rate_per_endpoint,
        maxUtilization=args.max_utilization,
        maxConnections=args.max_connections,
        maxConnectionsPerInstance=args.max_connections_per_instance,
        maxConnectionsPerEndpoint=args.max_connections_per_endpoint,
        failover=args.failover)