Ejemplo n.º 1
0
def _Modify(client, args, existing_check, include_log_config):
  """Returns a modified HealthCheck message."""
  # We do not support using 'update grpc' with a health check of a
  # different protocol.
  if (existing_check.type !=
      client.messages.HealthCheck.TypeValueValuesEnum.GRPC):
    raise core_exceptions.Error(
        'update grpc subcommand applied to health check with protocol ' +
        existing_check.type.name)

  # Description, PortName, and GrpcServiceName are the only attributes that can
  # be cleared by passing in an empty string (but we don't want to set it to
  # an empty string).
  if args.description:
    description = args.description
  elif args.description is None:
    description = existing_check.description
  else:
    description = None

  if args.grpc_service_name:
    grpc_service_name = args.grpc_service_name
  elif args.grpc_service_name is None:
    grpc_service_name = existing_check.grpcHealthCheck.grpcServiceName
  else:
    grpc_service_name = None

  port, port_name, port_specification = health_checks_utils.\
    HandlePortRelatedFlagsForUpdate(
        args, existing_check.grpcHealthCheck)

  new_health_check = client.messages.HealthCheck(
      name=existing_check.name,
      description=description,
      type=client.messages.HealthCheck.TypeValueValuesEnum.GRPC,
      grpcHealthCheck=client.messages.GRPCHealthCheck(
          port=port,
          portName=port_name,
          portSpecification=port_specification,
          grpcServiceName=grpc_service_name),
      checkIntervalSec=(args.check_interval or existing_check.checkIntervalSec),
      timeoutSec=args.timeout or existing_check.timeoutSec,
      healthyThreshold=(args.healthy_threshold or
                        existing_check.healthyThreshold),
      unhealthyThreshold=(args.unhealthy_threshold or
                          existing_check.unhealthyThreshold),
  )

  if include_log_config:
    new_health_check.logConfig = health_checks_utils.ModifyLogConfig(
        client, args, existing_check.logConfig)
  return new_health_check
Ejemplo n.º 2
0
def _Modify(client, args, existing_check, include_log_config):
    """Returns a modified HealthCheck message."""
    # We do not support using 'update tcp' with a health check of a
    # different protocol.
    if (existing_check.type !=
            client.messages.HealthCheck.TypeValueValuesEnum.TCP):
        raise core_exceptions.Error(
            'update tcp subcommand applied to health check with protocol ' +
            existing_check.type.name)

    # Description, PortName, Request, and Response are the only attributes that
    # can be cleared by passing in an empty string (but we don't want to set it
    # to an empty string).
    if args.description:
        description = args.description
    elif args.description is None:
        description = existing_check.description
    else:
        description = None

    port, port_name, port_specification = health_checks_utils. \
      HandlePortRelatedFlagsForUpdate(args, existing_check.tcpHealthCheck)

    if args.request:
        request = args.request
    elif args.request is None:
        request = existing_check.tcpHealthCheck.request
    else:
        request = None

    if args.response:
        response = args.response
    elif args.response is None:
        response = existing_check.tcpHealthCheck.response
    else:
        response = None

    proxy_header = existing_check.tcpHealthCheck.proxyHeader
    if args.proxy_header is not None:
        proxy_header = client.messages.TCPHealthCheck.ProxyHeaderValueValuesEnum(
            args.proxy_header)
    new_health_check = client.messages.HealthCheck(
        name=existing_check.name,
        description=description,
        type=client.messages.HealthCheck.TypeValueValuesEnum.TCP,
        tcpHealthCheck=client.messages.TCPHealthCheck(
            request=request,
            response=response,
            port=port,
            portName=port_name,
            portSpecification=port_specification,
            proxyHeader=proxy_header),
        checkIntervalSec=(args.check_interval
                          or existing_check.checkIntervalSec),
        timeoutSec=args.timeout or existing_check.timeoutSec,
        healthyThreshold=(args.healthy_threshold
                          or existing_check.healthyThreshold),
        unhealthyThreshold=(args.unhealthy_threshold
                            or existing_check.unhealthyThreshold),
    )

    if include_log_config:
        new_health_check.logConfig = health_checks_utils.ModifyLogConfig(
            client, args, existing_check.logConfig)
    return new_health_check
def _Modify(client, args, existing_check, include_log_config,
            include_weighted_load_balancing):
    """Returns a modified HealthCheck message."""
    # We do not support using 'update http2' with a health check of a
    # different protocol.
    if (existing_check.type !=
            client.messages.HealthCheck.TypeValueValuesEnum.HTTP2):
        raise core_exceptions.Error(
            'update http2 subcommand applied to health check with protocol ' +
            existing_check.type.name)

    # Description, PortName, Response and Host are the only attributes that can
    # be cleared by passing in an empty string (but we don't want to set it to
    # an empty string).
    if args.description:
        description = args.description
    elif args.description is None:
        description = existing_check.description
    else:
        description = None

    if args.host:
        host = args.host
    elif args.host is None:
        host = existing_check.http2HealthCheck.host
    else:
        host = None

    if args.response:
        response = args.response
    elif args.response is None:
        response = existing_check.http2HealthCheck.response
    else:
        response = None

    port, port_name, port_specification = health_checks_utils.\
        HandlePortRelatedFlagsForUpdate(args, existing_check.http2HealthCheck)

    if include_weighted_load_balancing:
        weight_report_mode = existing_check.http2HealthCheck.weightReportMode
        if args.IsSpecified('weight_report_mode'):
            weight_report_mode = client.messages.HTTP2HealthCheck.WeightReportModeValueValuesEnum(
                args.weight_report_mode)

    proxy_header = existing_check.http2HealthCheck.proxyHeader
    if args.proxy_header is not None:
        proxy_header = (
            client.messages.HTTP2HealthCheck.ProxyHeaderValueValuesEnum(
                args.proxy_header))

    http2_health_check = client.messages.HTTP2HealthCheck(
        host=host,
        port=port,
        portName=port_name,
        portSpecification=port_specification,
        requestPath=(args.request_path
                     or existing_check.http2HealthCheck.requestPath),
        proxyHeader=proxy_header,
        response=response)

    if include_weighted_load_balancing:
        http2_health_check.weightReportMode = weight_report_mode

    new_health_check = client.messages.HealthCheck(
        name=existing_check.name,
        description=description,
        type=client.messages.HealthCheck.TypeValueValuesEnum.HTTP2,
        http2HealthCheck=http2_health_check,
        checkIntervalSec=(args.check_interval
                          or existing_check.checkIntervalSec),
        timeoutSec=args.timeout or existing_check.timeoutSec,
        healthyThreshold=(args.healthy_threshold
                          or existing_check.healthyThreshold),
        unhealthyThreshold=(args.unhealthy_threshold
                            or existing_check.unhealthyThreshold),
    )

    if include_log_config:
        new_health_check.logConfig = health_checks_utils.ModifyLogConfig(
            client, args, existing_check.logConfig)
    return new_health_check