Beispiel #1
0
def GetConfigurationChanges(args):
    """Returns a list of changes to Configuration, based on the flags set."""
    changes = []
    if _HasEnvChanges(args):
        changes.append(_GetEnvChanges(args))

    if _HasCloudSQLChanges(args):
        region = GetRegion(args)
        project = (getattr(args, 'project', None)
                   or properties.VALUES.core.project.Get(required=True))
        _CheckCloudSQLApiEnablement()
        changes.append(config_changes.CloudSQLChanges(project, region, args))

    if 'cpu' in args and args.cpu:
        changes.append(config_changes.ResourceChanges(cpu=args.cpu))
    if 'memory' in args and args.memory:
        changes.append(config_changes.ResourceChanges(memory=args.memory))
    if 'concurrency' in args and args.concurrency:
        try:
            c = int(args.concurrency)
        except ValueError:
            c = args.concurrency
            if c != 'default':
                log.warning(
                    'Specifying concurrency as Single or Multi is deprecated; '
                    'an integer is preferred.')
        changes.append(config_changes.ConcurrencyChanges(concurrency=c))
    if 'timeout' in args and args.timeout:
        try:
            # A bare number is interpreted as seconds.
            timeout_secs = int(args.timeout)
        except ValueError:
            timeout_duration = times.ParseDuration(args.timeout)
            timeout_secs = int(timeout_duration.total_seconds)
        if timeout_secs <= 0:
            raise ArgumentError(
                'The --timeout argument must be a positive time duration.')
        changes.append(config_changes.TimeoutChanges(timeout=timeout_secs))
    if 'service_account' in args and args.service_account:
        changes.append(
            config_changes.ServiceAccountChanges(
                service_account=args.service_account))
    if _HasLabelChanges(args):
        diff = labels_util.Diff.FromUpdateArgs(args)
        if diff.MayHaveUpdates():
            changes.append(config_changes.LabelChanges(diff))
    if 'revision_suffix' in args and args.revision_suffix:
        changes.append(config_changes.RevisionNameChanges(
            args.revision_suffix))
    if 'vpc_connector' in args and args.vpc_connector:
        changes.append(config_changes.VpcConnectorChange(args.vpc_connector))
    if 'clear_vpc_connector' in args and args.clear_vpc_connector:
        changes.append(config_changes.ClearVpcConnectorChange())

    return changes
Beispiel #2
0
def GetConfigurationChanges(args):
  """Returns a list of changes to Configuration, based on the flags set."""
  changes = []
  changes.extend(_GetScalingChanges(args))
  if _HasEnvChanges(args):
    changes.append(_GetEnvChanges(args))

  if _HasTrafficChanges(args):
    changes.append(_GetTrafficChanges(args))

  if _HasCloudSQLChanges(args):
    region = GetRegion(args)
    project = (
        getattr(args, 'project', None) or
        properties.VALUES.core.project.Get(required=True))
    _CheckCloudSQLApiEnablement()
    changes.append(config_changes.CloudSQLChanges(project, region, args))

  if _HasSecretsChanges(args):
    changes.extend(_GetSecretsChanges(args))

  if _HasConfigMapsChanges(args):
    changes.extend(_GetConfigMapsChanges(args))

  if 'no_traffic' in args and args.no_traffic:
    changes.append(config_changes.NoTrafficChange())

  if 'cpu' in args and args.cpu:
    changes.append(config_changes.ResourceChanges(cpu=args.cpu))
  if 'memory' in args and args.memory:
    changes.append(config_changes.ResourceChanges(memory=args.memory))
  if 'concurrency' in args and args.concurrency:
    changes.append(config_changes.ConcurrencyChanges(
        concurrency=args.concurrency))
  if 'timeout' in args and args.timeout:
    try:
      # A bare number is interpreted as seconds.
      timeout_secs = int(args.timeout)
    except ValueError:
      timeout_duration = times.ParseDuration(args.timeout)
      timeout_secs = int(timeout_duration.total_seconds)
    if timeout_secs <= 0:
      raise ArgumentError(
          'The --timeout argument must be a positive time duration.')
    changes.append(config_changes.TimeoutChanges(timeout=timeout_secs))
  if 'service_account' in args and args.service_account:
    changes.append(
        config_changes.ServiceAccountChanges(
            service_account=args.service_account))
  if _HasLabelChanges(args):
    additions = (
        args.labels
        if _FlagIsExplicitlySet(args, 'labels') else args.update_labels)
    diff = labels_util.Diff(
        additions=additions,
        subtractions=args.remove_labels,
        clear=args.clear_labels)
    if diff.MayHaveUpdates():
      changes.append(config_changes.LabelChanges(diff))
  if 'revision_suffix' in args and args.revision_suffix:
    changes.append(config_changes.RevisionNameChanges(args.revision_suffix))
  if 'vpc_connector' in args and args.vpc_connector:
    changes.append(config_changes.VpcConnectorChange(args.vpc_connector))
  if 'clear_vpc_connector' in args and args.clear_vpc_connector:
    changes.append(config_changes.ClearVpcConnectorChange())
  if 'connectivity' in args and args.connectivity:
    if args.connectivity == 'internal':
      changes.append(config_changes.EndpointVisibilityChange(True))
    elif args.connectivity == 'external':
      changes.append(config_changes.EndpointVisibilityChange(False))
  if 'command' in args and args.command is not None:
    # Allow passing an empty string here to reset the field
    changes.append(config_changes.ContainerCommandChange(args.command))
  if 'args' in args and args.args is not None:
    # Allow passing an empty string here to reset the field
    changes.append(config_changes.ContainerArgsChange(args.args))
  if _FlagIsExplicitlySet(args, 'port'):
    changes.append(config_changes.ContainerPortChange(port=args.port))
  if _FlagIsExplicitlySet(args, 'use_http2'):
    changes.append(config_changes.ContainerPortChange(use_http2=args.use_http2))
  return changes