def _Run(args, holder, include_l7_internal_load_balancing=False):
  """Issues the request necessary for adding the health check."""
  client = holder.client

  health_check_ref = flags.HealthCheckArgument(
      'UDP',
      include_l7_internal_load_balancing=include_l7_internal_load_balancing
  ).ResolveAsResource(args, holder.resources)

  # Check that request and response are not None and empty.
  if not args.request:
    raise exceptions.ArgumentError('"request" field for UDP can not be empty.')
  if not args.response:
    raise exceptions.ArgumentError('"response" field for UDP can not be empty.')

  if health_checks_utils.IsRegionalHealthCheckRef(health_check_ref):
    request = client.messages.ComputeRegionHealthChecksInsertRequest(
        healthCheck=client.messages.HealthCheck(
            name=health_check_ref.Name(),
            description=args.description,
            type=client.messages.HealthCheck.TypeValueValuesEnum.UDP,
            udpHealthCheck=client.messages.UDPHealthCheck(
                request=args.request,
                response=args.response,
                port=args.port,
                portName=args.port_name),
            checkIntervalSec=args.check_interval,
            timeoutSec=args.timeout,
            healthyThreshold=args.healthy_threshold,
            unhealthyThreshold=args.unhealthy_threshold,
        ),
        project=health_check_ref.project,
        region=health_check_ref.region)
    collection = client.apitools_client.regionHealthChecks
  else:
    request = client.messages.ComputeHealthChecksInsertRequest(
        healthCheck=client.messages.HealthCheck(
            name=health_check_ref.Name(),
            description=args.description,
            type=client.messages.HealthCheck.TypeValueValuesEnum.UDP,
            udpHealthCheck=client.messages.UDPHealthCheck(
                request=args.request,
                response=args.response,
                port=args.port,
                portName=args.port_name),
            checkIntervalSec=args.check_interval,
            timeoutSec=args.timeout,
            healthyThreshold=args.healthy_threshold,
            unhealthyThreshold=args.unhealthy_threshold,
        ),
        project=health_check_ref.project)
    collection = client.apitools_client.healthChecks

  return client.MakeRequests([(collection, 'Insert', request)])
示例#2
0
  def Run(self, args):
    """Issues requests necessary to update UDP Health Checks."""
    holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
    client = holder.client

    health_checks_utils.CheckProtocolAgnosticArgs(args)

    args_unset = not (args.port
                      or args.check_interval
                      or args.timeout
                      or args.healthy_threshold
                      or args.unhealthy_threshold
                      or args.request
                      or args.response)
    if args.description is None and args.port_name is None and args_unset:
      raise exceptions.ArgumentError('At least one property must be modified.')

    # Check that request and response are not empty. It is acceptable for it to
    # be None.
    if args.request is not None and not args.request:
      raise exceptions.ArgumentError(
          '"request" field for UDP can not be empty.')
    if args.response is not None and not args.response:
      raise exceptions.ArgumentError(
          '"response" field for UDP can not be empty.')

    health_check_ref = self.HEALTH_CHECK_ARG.ResolveAsResource(
        args, holder.resources)
    if health_checks_utils.IsRegionalHealthCheckRef(health_check_ref):
      get_request = self._GetRegionalGetRequest(client, health_check_ref)
    else:
      get_request = self._GetGetRequest(client, health_check_ref)

    objects = client.MakeRequests([get_request])

    new_object = self.Modify(client, args, objects[0])

    # If existing object is equal to the proposed object or if
    # Modify() returns None, then there is no work to be done, so we
    # print the resource and return.
    if objects[0] == new_object:
      log.status.Print(
          'No change requested; skipping update for [{0}].'.format(
              objects[0].name))
      return objects

    if health_checks_utils.IsRegionalHealthCheckRef(health_check_ref):
      set_request = self._GetRegionalSetRequest(client, health_check_ref,
                                                new_object)
    else:
      set_request = self._GetSetRequest(client, health_check_ref, new_object)

    return client.MakeRequests([set_request])
def CheckProtocolAgnosticArgs(args):
    """Raises exception if any protocol-agnostic args are invalid."""

    if (args.check_interval is not None
            and (args.check_interval < CHECK_INTERVAL_LOWER_BOUND_SEC
                 or args.check_interval > CHECK_INTERVAL_UPPER_BOUND_SEC)):
        raise hc_exceptions.ArgumentError(
            '[--check-interval] must not be less than {0} second or greater '
            'than {1} seconds; received [{2}] seconds.'.format(
                CHECK_INTERVAL_LOWER_BOUND_SEC, CHECK_INTERVAL_UPPER_BOUND_SEC,
                args.check_interval))

    if (args.timeout is not None
            and (args.timeout < TIMEOUT_LOWER_BOUND_SEC
                 or args.timeout > TIMEOUT_UPPER_BOUND_SEC)):
        raise hc_exceptions.ArgumentError(
            '[--timeout] must not be less than {0} second or greater than {1} '
            'seconds; received: [{2}] seconds.'.format(
                TIMEOUT_LOWER_BOUND_SEC, TIMEOUT_UPPER_BOUND_SEC,
                args.timeout))

    if (args.healthy_threshold is not None
            and (args.healthy_threshold < THRESHOLD_LOWER_BOUND
                 or args.healthy_threshold > THRESHOLD_UPPER_BOUND)):
        raise hc_exceptions.ArgumentError(
            '[--healthy-threshold] must be an integer between {0} and {1}, '
            'inclusive; received: [{2}].'.format(THRESHOLD_LOWER_BOUND,
                                                 THRESHOLD_UPPER_BOUND,
                                                 args.healthy_threshold))

    if (args.unhealthy_threshold is not None
            and (args.unhealthy_threshold < THRESHOLD_LOWER_BOUND
                 or args.unhealthy_threshold > THRESHOLD_UPPER_BOUND)):
        raise hc_exceptions.ArgumentError(
            '[--unhealthy-threshold] must be an integer between {0} and {1}, '
            'inclusive; received [{2}].'.format(THRESHOLD_LOWER_BOUND,
                                                THRESHOLD_UPPER_BOUND,
                                                args.unhealthy_threshold))
示例#4
0
def _ValidateArgs(args, include_log_config):
  """Validates given args and raises exception if any args are invalid."""
  health_checks_utils.CheckProtocolAgnosticArgs(args)

  args_unset = not (args.port or args.check_interval or args.timeout or
                    args.healthy_threshold or args.unhealthy_threshold or
                    args.use_serving_port)

  if include_log_config:
    args_unset = (args.enable_logging is None and args_unset)

  if (args.description is None and args.grpc_service_name is None and
      args_unset):
    raise exceptions.ArgumentError('At least one property must be modified.')
    def GetResources(self, args, errors):
        health_checks = super(List, self).GetResources(args, errors)

        # If a protocol is specified, check that it is one we support, and convert
        # it to a number.
        protocol_value = None
        if args.protocol is not None:
            protocol_value = self._ConvertProtocolArgToValue(args)
            if protocol_value not in self._ProtocolAllowlist():
                raise exceptions.ArgumentError(
                    'Invalid health check protocol ' + args.protocol + '.')

        for health_check in health_checks:
            if (protocol_value is None
                    or health_check['type'] == args.protocol.upper()):
                yield health_check
def _ValidateArgs(args,
                  include_log_config,
                  include_weighted_load_balancing=False):
    """Validates given args and raises exception if any args are invalid."""
    health_checks_utils.CheckProtocolAgnosticArgs(args)

    args_unset = not (args.port or args.request_path or args.check_interval
                      or args.timeout or args.healthy_threshold
                      or args.unhealthy_threshold or args.proxy_header
                      or args.use_serving_port)

    if include_log_config:
        args_unset = (args.enable_logging is None and args_unset)

    weight_report_mode_modified = False
    if include_weighted_load_balancing and args.IsSpecified(
            'weight_report_mode'):
        weight_report_mode_modified = True

    if (args.description is None and args.host is None
            and args.response is None and args.port_name is None
            and not weight_report_mode_modified and args_unset):
        raise exceptions.ArgumentError(
            'At least one property must be modified.')
    def Run(self, args):
        """Issues requests necessary to update the HTTPS Health Checks."""
        holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
        client = holder.client

        if (args.check_interval is not None
                and (args.check_interval < CHECK_INTERVAL_LOWER_BOUND_SEC
                     or args.check_interval > CHECK_INTERVAL_UPPER_BOUND_SEC)):
            raise exceptions.ArgumentError(
                '[--check-interval] must not be less than {0} second or greater '
                'than {1} seconds; received [{2}] seconds.'.format(
                    CHECK_INTERVAL_LOWER_BOUND_SEC,
                    CHECK_INTERVAL_UPPER_BOUND_SEC, args.check_interval))

        if (args.timeout is not None
                and (args.timeout < TIMEOUT_LOWER_BOUND_SEC
                     or args.timeout > TIMEOUT_UPPER_BOUND_SEC)):
            raise exceptions.ArgumentError(
                '[--timeout] must not be less than {0} second or greater than {1} '
                'seconds; received: [{2}] seconds.'.format(
                    TIMEOUT_LOWER_BOUND_SEC, TIMEOUT_UPPER_BOUND_SEC,
                    args.timeout))

        if (args.healthy_threshold is not None
                and (args.healthy_threshold < THRESHOLD_LOWER_BOUND
                     or args.healthy_threshold > THRESHOLD_UPPER_BOUND)):
            raise exceptions.ArgumentError(
                '[--healthy-threshold] must be an integer between {0} and {1}, '
                'inclusive; received: [{2}].'.format(THRESHOLD_LOWER_BOUND,
                                                     THRESHOLD_UPPER_BOUND,
                                                     args.healthy_threshold))

        if (args.unhealthy_threshold is not None
                and (args.unhealthy_threshold < THRESHOLD_LOWER_BOUND
                     or args.unhealthy_threshold > THRESHOLD_UPPER_BOUND)):
            raise exceptions.ArgumentError(
                '[--unhealthy-threshold] must be an integer between {0} and {1}, '
                'inclusive; received [{2}].'.format(THRESHOLD_LOWER_BOUND,
                                                    THRESHOLD_UPPER_BOUND,
                                                    args.unhealthy_threshold))

        args_unset = not (args.port or args.request_path or args.check_interval
                          or args.timeout or args.healthy_threshold
                          or args.unhealthy_threshold)
        if args.description is None and args.host is None and args_unset:
            raise exceptions.ArgumentError(
                'At least one property must be modified.')

        https_health_check_ref = self.HTTPS_HEALTH_CHECKS_ARG.ResolveAsResource(
            args, holder.resources)
        get_request = self.GetGetRequest(client, https_health_check_ref)

        objects = client.MakeRequests([get_request])

        new_object = self.Modify(client, args, objects[0])

        # If existing object is equal to the proposed object or if
        # Modify() returns None, then there is no work to be done, so we
        # print the resource and return.
        if objects[0] == new_object:
            log.status.Print(
                'No change requested; skipping update for [{0}].'.format(
                    objects[0].name))
            return objects

        return client.MakeRequests(
            [self.GetSetRequest(client, https_health_check_ref, new_object)])