示例#1
0
def AddCapacityScalar(parser,
                      support_global_neg=False,
                      support_region_neg=False):
    """Adds capacity thresholds argument to the argparse."""
    help_text = """\
      A setting that applies to all balancing modes. This value is multiplied
      by the balancing mode value to set the current max usage of the instance
      group. Acceptable values are `0.0` (0%) through `1.0` (100%). Setting this
      value to `0.0` (0%) drains the backend service. Note that draining a
      backend service only prevents new connections to instances in the group.
      All existing connections are allowed to continue until they close by
      normal means. This cannot be used for internal load balancing.
      """
    incompatible_types = []
    if support_global_neg:
        incompatible_types.extend(['INTERNET_IP_PORT', 'INTERNET_FQDN_PORT'])
    if support_region_neg:
        incompatible_types.append('SERVERLESS')
    if incompatible_types:
        help_text += """\

    This cannot be used when the endpoint type of an attached network endpoint
    group is {0}.
    """.format(' or '.join(incompatible_types))
    parser.add_argument('--capacity-scaler',
                        type=arg_parsers.BoundedFloat(lower_bound=0.0,
                                                      upper_bound=1.0),
                        help=help_text)
示例#2
0
def AddCapacityScalar(parser,
                      support_global_neg=False,
                      support_region_neg=False):
  """Adds capacity thresholds argument to the argparse."""
  help_text = """\
      Scales down the target capacity (max utilization, max rate, or max
      connections) without changing the target capacity. For usage guidelines
      and examples, see
      <a href="https://cloud.google.com/load-balancing/docs/backend-service#capacity_scaler">Capacity
      scaler</a>.
      """
  incompatible_types = []
  if support_global_neg:
    incompatible_types.extend(['INTERNET_IP_PORT', 'INTERNET_FQDN_PORT'])
  if support_region_neg:
    incompatible_types.append('SERVERLESS')
  if incompatible_types:
    help_text += """\

    This cannot be used when the endpoint type of an attached network endpoint
    group is {0}.
    """.format(_JoinTypes(incompatible_types))
  parser.add_argument(
      '--capacity-scaler',
      type=arg_parsers.BoundedFloat(lower_bound=0.0, upper_bound=1.0),
      help=help_text)
示例#3
0
def AddMaxUtilization(parser):
    max_utilization = parser.add_argument(
        '--max-utilization',
        type=arg_parsers.BoundedFloat(lower_bound=0.0, upper_bound=1.0),
        help=('The target CPU utilization of the group as a '
              'float in the range [0.0, 1.0].'))
    max_utilization.detailed_help = """\
示例#4
0
def AddCapacityScalar(parser):
    capacity_scaler = parser.add_argument(
        '--capacity-scaler',
        type=arg_parsers.BoundedFloat(lower_bound=0.0, upper_bound=1.0),
        help=(
            'A float in the range [0.0, 1.0] that scales the maximum '
            'parameters for the group (e.g., max rate). The default is 1.0.'))
    capacity_scaler.detailed_help = """\
def AddMaxUtilization(parser):
  parser.add_argument(
      '--max-utilization',
      type=arg_parsers.BoundedFloat(lower_bound=0.0, upper_bound=1.0),
      help="""\
      The target CPU utilization for the group as a float in the range
      [0.0, 1.0]. This flag can only be provided when the balancing
      mode is *UTILIZATION*.
      """)
def AddCapacityScalar(parser):
  parser.add_argument(
      '--capacity-scaler',
      type=arg_parsers.BoundedFloat(lower_bound=0.0, upper_bound=1.0),
      help="""\
      A float in the range [0.0, 1.0] that scales the maximum
      parameters for the group (e.g., max rate). A value of 0.0 will
      cause no requests to be sent to the group (i.e., it adds the
      group in a ``drained'' state).""")
示例#7
0
def AddMaxUtilization(parser):
    parser.add_argument('--max-utilization',
                        type=arg_parsers.BoundedFloat(lower_bound=0.0,
                                                      upper_bound=1.0),
                        help="""\
      The maximum average CPU utilization of the backend service.
      Acceptable values are `0.0` (0%) through `1.0` (100%). This flag can only
      be provided when the balancing mode is *UTILIZATION*.
      """)
示例#8
0
def AddFailoverRatio(parser):
    """Adds the failover ratio argument to the argparse."""
    parser.add_argument('--failover-ratio',
                        type=arg_parsers.BoundedFloat(lower_bound=0.0,
                                                      upper_bound=1.0),
                        help="""\
      If the ratio of the healthy VMs in the primary backend is at or below this
      number, traffic arriving at the load-balanced IP will be directed to the
      failover backend(s). Not compatible with the --global flag.
      """)
示例#9
0
def AddCapacityScalar(parser):
    parser.add_argument('--capacity-scaler',
                        type=arg_parsers.BoundedFloat(lower_bound=0.0,
                                                      upper_bound=1.0),
                        help="""\
      A setting that applies to all balancing modes. This value is multiplied
      by the balancing mode value to set the current max usage of the instance
      group. Acceptable values are `0.0` (0%) through `1.0` (100%). Setting this
      value to `0.0` (0%) drains the backend service. Note that draining a
      backend service only prevents new connections to instances in the group.
      All existing connections are allowed to continue until they close by
      normal means.""")
示例#10
0
def AddLoggingSampleRate(parser):
    """Adds the logging sample rate argument to the argparse."""
    parser.add_argument('--logging-sample-rate',
                        type=arg_parsers.BoundedFloat(lower_bound=0.0,
                                                      upper_bound=1.0),
                        help="""\
      This field can only be specified if logging is enabled for the backend
      service. The value of the field must be a float in the range [0, 1]. This
      configures the sampling rate of requests to the load balancer where 1.0
      means all logged requests are reported and 0.0 means no logged requests
      are reported. The default value is 1.0.
      """)
示例#11
0
def AddMaxUtilization(parser):
  """Adds max utilization argument to the argparse."""
  parser.add_argument(
      '--max-utilization',
      type=arg_parsers.BoundedFloat(lower_bound=0.0, upper_bound=1.0),
      help="""\
      Defines the maximum target for average utilization of the backend instance
      group. Supported values are `0.0` (0%) through `1.0` (100%). This is an
      optional parameter for the `UTILIZATION` balancing mode.

      You can use this parameter with other parameters for defining target
      capacity. For usage guidelines, see
      <a href="https://cloud.google.com/load-balancing/docs/backend-service#balancing-mode-combos">Balancing
      mode combinations</a>.""")
示例#12
0
def AddMaxUtilization(parser):
    """Adds max utilization argument to the argparse."""
    parser.add_argument('--max-utilization',
                        type=arg_parsers.BoundedFloat(lower_bound=0.0,
                                                      upper_bound=1.0),
                        help="""\
      Defines the maximum target for average utilization of the backend instance
      in the backend instance group. Acceptable values are `0.0` (0%) through
      `1.0`(100%). Available for all backend service protocols, with
      `--balancing-mode=UTILIZATION`.

      For backend services that use SSL, TCP, or UDP protocols, the following
      configuration options are supported:

      * no additional parameter
      * only `--max-utilization`
      * only `--max-connections` (except for regional managed instance groups)
      * only `--max-connections-per-instance`
      * both `--max-utilization` and `--max-connections` (except for regional
        managed instance groups)
      * both `--max-utilization` and `--max-connections-per-instance`

      The meanings for `-max-connections` and `--max-connections-per-instance`
      are the same as for --balancing-mode=CONNECTION. If one is used  with
      `--max-utilization`, instances are considered at capacity
      when either maximum utilization or maximum connections is reached.

      For backend services that use HTTP, HTTPS, or HTTP/2 protocols, the
      following configuration options are supported:

      * no additional parameter
      * only `--max-utilization`
      * only `--max-rate` (except for regional managed instance groups)
      * only `--max-rate-per-instance`
      * both `--max-utilization` and `--max-rate` (except for regional managed
        instance groups)
      * both `--max-utilization` and `--max-rate-per-instance`

      The meanings for `--max-rate` and `--max-rate-per-instance` are the same
      as for --balancing-mode=RATE. If one is used in conjunction with
      `--max-utilization`, instances are considered at capacity when *either*
      maximum utilization or the maximum rate is reached.""")
示例#13
0
def AddMaxUtilization(parser):
    parser.add_argument('--max-utilization',
                        type=arg_parsers.BoundedFloat(lower_bound=0.0,
                                                      upper_bound=1.0),
                        help="""\
      Defines the maximum target for average CPU utilization of the backend
      instance in the backend instance group. Acceptable values are 0.0 (0%)
      through 1.0 (100%). Available for all backend service protocols,
      with --balancing-mode=UTILIZATION.

      For backend services that use SSL, TCP, or UDP protocols, you may specify
      either `--max-connections` or `--max-connections-per-instance`, either by
      themselves or one in conjunction with `--max-utilization`. In other words,
      the following configuration options are supported:
      * no additional parameter
      * just `--max-utilization`
      * just `--max-connections`
      * just `--max-connections-per-instance`
      * both `--max-utilization` and `--max-connections`
      * both `--max-utilization` and `--max-connections-per-instance`

      The meanings for `--max-connections` and `--max-connections-per-instance`
      are the same as for --balancing-mode=CONNECTION. If one is used in
      conjunction with `--max-utilization`, instances are considered at capacity
      when either maximum utilization or maximum connections is reached.

      For backend services that use HTTP, HTTPS, or HTTP/2 protocols, you may
      specify either `--max-rate` or `--max-rate-per-instance`, either by
      themselves or one in conjunction with `--max-utilization`. In other words,
      the following configuration options are supported:
      * no additional parameter
      * just `--max-utilization`
      * just `--max-rate`
      * just `--max-rate-per-instance`
      * both `--max-utilization` and `--max-rate`
      * both `--max-utilization` and `--max-rate-per-instance`

      The meanings for `--max-rate` and `--max-rate-per-instance` are the same
      as for --balancing-mode=RATE. If one is used in conjunction with
      `--max-utilization`, instances are considered at capacity when *either*
      maximum utilization or the maximum rate is reached.""")
示例#14
0
文件: create.py 项目: linsole/CS61A
def _AddArgs(parser, include_alpha_logging, include_l7_internal_load_balancing,
             include_private_ipv6_access, include_aggregate_purpose):
  """Add subnetwork create arguments to parser."""
  parser.display_info.AddFormat(flags.DEFAULT_LIST_FORMAT)

  flags.SubnetworkArgument().AddArgument(parser, operation_type='create')
  network_flags.NetworkArgumentForOtherResource(
      'The network to which the subnetwork belongs.').AddArgument(parser)

  messages = apis.GetMessagesModule('compute',
                                    compute_api.COMPUTE_GA_API_VERSION)

  parser.add_argument(
      '--description', help='An optional description of this subnetwork.')

  parser.add_argument(
      '--range',
      required=True,
      help='The IP space allocated to this subnetwork in CIDR format.')

  parser.add_argument(
      '--enable-private-ip-google-access',
      action='store_true',
      default=False,
      help=('Enable/disable access to Google Cloud APIs from this subnet for '
            'instances without a public ip address.'))

  parser.add_argument(
      '--secondary-range',
      type=arg_parsers.ArgDict(min_length=1),
      action='append',
      metavar='PROPERTY=VALUE',
      help="""\
      Adds a secondary IP range to the subnetwork for use in IP aliasing.

      For example, `--secondary-range range1=192.168.64.0/24` adds
      a secondary range 192.168.64.0/24 with name range1.

      * `RANGE_NAME` - Name of the secondary range.
      * `RANGE` - `IP range in CIDR format.`
      """)

  parser.add_argument(
      '--enable-flow-logs',
      action='store_true',
      default=None,
      help=('Enable/disable VPC flow logging for this subnet. More information '
            'for VPC flow logs can be found at '
            'https://cloud.google.com/vpc/docs/using-flow-logs.'))

  flags.AddLoggingAggregationInterval(parser, messages)
  parser.add_argument(
      '--logging-flow-sampling',
      type=arg_parsers.BoundedFloat(lower_bound=0.0, upper_bound=1.0),
      help="""\
      Can only be specified if VPC flow logging for this subnetwork is
      enabled. The value of the field must be in [0, 1]. Set the sampling rate
      of VPC flow logs within the subnetwork where 1.0 means all collected
      logs are reported and 0.0 means no logs are reported. Default is 0.5
      which means half of all collected logs are reported.
      """)

  if include_alpha_logging:
    messages = apis.GetMessagesModule('compute',
                                      compute_api.COMPUTE_ALPHA_API_VERSION)
    flags.AddLoggingAggregationIntervalDeprecated(parser, messages)
    parser.add_argument(
        '--flow-sampling',
        type=arg_parsers.BoundedFloat(lower_bound=0.0, upper_bound=1.0),
        help="""\
        Can only be specified if VPC flow logging for this subnetwork is
        enabled. The value of the field must be in [0, 1]. Set the sampling rate
        of VPC flow logs within the subnetwork where 1.0 means all collected
        logs are reported and 0.0 means no logs are reported. Default is 0.5
        which means half of all collected logs are reported.
        """)
    flags.AddLoggingMetadataDeprecated(parser, messages)

    parser.add_argument(
        '--logging-filter-expr',
        help="""\
        Can only be specified if VPC flow logs for this subnetwork is enabled.
        Export filter used to define which VPC flow logs should be logged.
        """)
    flags.AddLoggingMetadataAlpha(parser, messages)
    parser.add_argument(
        '--logging-metadata-fields',
        type=arg_parsers.ArgList(),
        metavar='METADATA_FIELD',
        default=None,
        help="""\
        Can only be specified if VPC flow logs for this subnetwork is enabled
        and "metadata" is set to CUSTOM_METADATA. The custom list of metadata
        fields that should be added to reported VPC flow logs.
        """)
  else:
    flags.AddLoggingMetadata(parser, messages)

  purpose_choices = {
      'PRIVATE':
          'Regular user created or automatically created subnet.',
      'INTERNAL_HTTPS_LOAD_BALANCER':
          'Reserved for Internal HTTP(S) Load Balancing.',
  }

  if include_aggregate_purpose:
    purpose_choices['AGGREGATE'] = (
        'Reserved for Aggregate Ranges used for aggregating '
        'private subnetworks.')

  # Subnetwork purpose is introduced with L7ILB feature. Aggregate purpose
  # will have to be enabled for a given release track only after L7ILB feature
  # is enabled for that release track. Hence if include_aggregate_purpose
  # true, this code assumes that L7ILB purpose is enabled.
  if include_l7_internal_load_balancing:
    parser.add_argument(
        '--purpose',
        choices=purpose_choices,
        type=arg_utils.ChoiceToEnumName,
        help='The purpose of this subnetwork.')

  if include_l7_internal_load_balancing:
    parser.add_argument(
        '--role',
        choices={
            'ACTIVE': 'The ACTIVE subnet that is currently used.',
            'BACKUP': 'The BACKUP subnet that could be promoted to ACTIVE.'
        },
        type=lambda x: x.replace('-', '_').upper(),
        help=('The role of subnetwork. This field is only used when'
              'purpose=INTERNAL_HTTPS_LOAD_BALANCER. The value can be set to '
              'ACTIVE or BACKUP. An ACTIVE subnetwork is one that is currently '
              'being used for Internal HTTP(S) Load Balancing. A BACKUP '
              'subnetwork is one that is ready to be promoted to ACTIVE or is '
              'currently draining.'))

  if include_private_ipv6_access:
    parser.add_argument(
        '--enable-private-ipv6-access',
        action='store_true',
        default=None,
        help=('Enable/disable private IPv6 access for the subnet.'))

    GetPrivateIpv6GoogleAccessTypeFlagMapper(messages).choice_arg.AddToParser(
        parser)

    parser.add_argument(
        '--private-ipv6-google-access-service-accounts',
        default=None,
        metavar='EMAIL',
        type=arg_parsers.ArgList(min_length=1),
        help="""\
        The service accounts can be used to selectively turn on Private IPv6
        Google Access only on the VMs primary service account matching the
        value.
        """)

  parser.display_info.AddCacheUpdater(network_flags.NetworksCompleter)
示例#15
0
def CommonFlags(parser):
  """Add common flags for local developement environments."""
  builder_group = parser.add_mutually_exclusive_group(required=False)
  builder_group.add_argument(
      '--dockerfile',
      default='Dockerfile',
      help='Dockerfile for the service image.')

  builder_group.add_argument(
      '--builder',
      help='Build with a given Cloud Native Computing Foundation Buildpack '
      'builder.')

  builder_group.add_argument(
      '--appengine',
      action='store_true',
      default=False,
      help='Build with a Cloud Native Computing Foundation Buildpack builder '
      'selected from gcr.io/gae-runtimes/buildpacks, according to the App '
      'Engine runtime specified in app.yaml.')

  parser.add_argument(
      '--service-name', required=False, help='Name of the service.')

  parser.add_argument(
      '--image', required=False, help='Name for the built image.')

  parser.add_argument(
      '--source',
      help='The directory containing the source to build. '
      'If not specified, the current directory is used.')

  credential_group = parser.add_mutually_exclusive_group(required=False)
  credential_group.add_argument(
      '--service-account',
      help='When connecting to Google Cloud Platform services, use a service '
      'account key.')

  credential_group.add_argument(
      '--application-default-credential',
      action='store_true',
      default=False,
      help='When connecting to Google Cloud Platform services, use the '
      'application default credential.')

  parser.add_argument(
      '--local-port',
      type=int,
      help='Local port to which the service connection is forwarded. If this '
      'flag is not set, then a random port is chosen.')

  parser.add_argument(
      '--cloudsql-instances',
      type=arg_parsers.ArgList(),
      metavar='CLOUDSQL_INSTANCE',
      help='Cloud SQL instance connection strings. Must be in the form '
      '<project>:<region>:<instance>.')

  parser.add_argument(
      '--cpu',
      type=arg_parsers.BoundedFloat(lower_bound=0.0),
      help='Container CPU limit. Limit is expressed as a number of CPUs. '
      'Fractional CPU limits are allowed (e.g. 1.5).')

  parser.add_argument(
      '--memory',
      type=arg_parsers.BinarySize(default_unit='B'),
      help='Container memory limit. Limit is expressed either as an integer '
      'representing the number of bytes or an integer followed by a unit '
      'suffix. Valid unit suffixes are "B", "KB", "MB", "GB", "TB", "KiB", '
      '"MiB", "GiB", "TiB", or "PiB".')

  # This flag launches the readiness probe feature. It is currently
  # default off. It will be moved to default on when ready and then
  # the feature will be always on.
  parser.add_argument(
      '--readiness-probe',
      default=False,
      action='store_true',
      hidden=True,
      help='Add a readiness probe to the list of containers that delays '
      'deployment stabilization until the application app has bound to $PORT')

  env_var_group = parser.add_mutually_exclusive_group(required=False)
  env_var_group.add_argument(
      '--env-vars',
      metavar='KEY=VALUE',
      action=arg_parsers.UpdateAction,
      type=arg_parsers.ArgDict(
          key_type=six.text_type, value_type=six.text_type),
      help='List of key-value pairs to set as environment variables.')

  env_var_group.add_argument(
      '--env-vars-file',
      metavar='FILE_PATH',
      type=map_util.ArgDictFile(
          key_type=six.text_type, value_type=six.text_type),
      help='Path to a local YAML file with definitions for all environment '
      'variables.')
示例#16
0
def _AddArgs(cls, parser, include_beta=False, include_alpha=False):
    """Add subnetwork create arguments to parser."""
    cls.SUBNETWORK_ARG = flags.SubnetworkArgument()
    cls.NETWORK_ARG = network_flags.NetworkArgumentForOtherResource(
        'The network to which the subnetwork belongs.')
    cls.SUBNETWORK_ARG.AddArgument(parser, operation_type='create')
    cls.NETWORK_ARG.AddArgument(parser)

    parser.add_argument('--description',
                        help='An optional description of this subnetwork.')

    parser.add_argument(
        '--range',
        required=True,
        help='The IP space allocated to this subnetwork in CIDR format.')

    parser.add_argument(
        '--enable-private-ip-google-access',
        action='store_true',
        default=False,
        help=(
            'Enable/disable access to Google Cloud APIs from this subnet for '
            'instances without a public ip address.'))

    parser.add_argument('--secondary-range',
                        type=arg_parsers.ArgDict(min_length=1),
                        action='append',
                        metavar='PROPERTY=VALUE',
                        help="""\
      Adds a secondary IP range to the subnetwork for use in IP aliasing.

      For example, `--secondary-range range1=192.168.64.0/24` adds
      a secondary range 192.168.64.0/24 with name range1.

      * `RANGE_NAME` - Name of the secondary range.
      * `RANGE` - `IP range in CIDR format.`
      """)

    parser.add_argument(
        '--enable-flow-logs',
        action='store_true',
        default=None,
        help=(
            'Enable/disable VPC flow logging for this subnet. More information '
            'for VPC flow logs can be found at '
            'https://cloud.google.com/vpc/docs/using-flow-logs.'))

    if include_beta:
        messages = apis.GetMessagesModule('compute',
                                          compute_api.COMPUTE_BETA_API_VERSION)

        flags.AddLoggingAggregationInterval(parser, messages)

        parser.add_argument('--logging-flow-sampling',
                            type=arg_parsers.BoundedFloat(lower_bound=0.0,
                                                          upper_bound=1.0),
                            help="""\
        Can only be specified if VPC flow logging for this subnetwork is
        enabled. The value of the field must be in [0, 1]. Set the sampling rate
        of VPC flow logs within the subnetwork where 1.0 means all collected
        logs are reported and 0.0 means no logs are reported. Default is 0.5
        which means half of all collected logs are reported.
        """)

        flags.AddLoggingMetadata(parser, messages)

    if include_alpha:
        messages = apis.GetMessagesModule(
            'compute', compute_api.COMPUTE_ALPHA_API_VERSION)

        parser.add_argument(
            '--purpose',
            choices={
                'PRIVATE':
                'Regular user created or automatically created subnet.',
                'INTERNAL_HTTPS_LOAD_BALANCER':
                'Reserved for Internal HTTP(S) Load Balancing.'
            },
            type=lambda x: x.replace('-', '_').upper(),
            help='The purpose of this subnetwork.')

        parser.add_argument(
            '--role',
            choices={
                'ACTIVE': 'The ACTIVE subnet that is currently used.',
                'BACKUP': 'The BACKUP subnet that could be promoted to ACTIVE.'
            },
            type=lambda x: x.replace('-', '_').upper(),
            help=
            ('The role of subnetwork. This field is only used when'
             'purpose=INTERNAL_HTTPS_LOAD_BALANCER. The value can be set to '
             'ACTIVE or BACKUP. An ACTIVE subnetwork is one that is currently '
             'being used for Internal HTTP(S) Load Balancing. A BACKUP '
             'subnetwork is one that is ready to be promoted to ACTIVE or is '
             'currently draining.'))

        flags.AddLoggingAggregationIntervalAlpha(parser, messages)

        parser.add_argument('--flow-sampling',
                            type=arg_parsers.BoundedFloat(lower_bound=0.0,
                                                          upper_bound=1.0),
                            help="""\
        Can only be specified if VPC flow logging for this subnetwork is
        enabled. The value of the field must be in [0, 1]. Set the sampling rate
        of VPC flow logs within the subnetwork where 1.0 means all collected
        logs are reported and 0.0 means no logs are reported. Default is 0.5
        which means half of all collected logs are reported.
        """)

        flags.AddLoggingMetadataAlpha(parser, messages)

        parser.add_argument(
            '--enable-private-ipv6-access',
            action='store_true',
            default=None,
            help=('Enable/disable private IPv6 access for the subnet.'))

        GetPrivateIpv6GoogleAccessTypeFlagMapper(
            messages).choice_arg.AddToParser(parser)
示例#17
0
def _AddArgs(parser, include_alpha_logging, include_global_managed_proxy,
             include_l7_internal_load_balancing, include_aggregate_purpose,
             include_private_service_connect,
             include_l2, include_private_nat, include_reserved_internal_range,
             api_version):
  """Add subnetwork create arguments to parser."""
  parser.display_info.AddFormat(flags.DEFAULT_LIST_FORMAT_WITH_IPV6_FIELD)

  flags.SubnetworkArgument().AddArgument(parser, operation_type='create')
  network_flags.NetworkArgumentForOtherResource(
      'The network to which the subnetwork belongs.').AddArgument(parser)

  messages = apis.GetMessagesModule('compute',
                                    compute_api.COMPUTE_GA_API_VERSION)

  parser.add_argument(
      '--description', help='An optional description of this subnetwork.')

  parser.add_argument(
      '--range',
      required=not include_reserved_internal_range,
      help='The IP space allocated to this subnetwork in CIDR format.')

  parser.add_argument(
      '--enable-private-ip-google-access',
      action='store_true',
      default=False,
      help=('Enable/disable access to Google Cloud APIs from this subnet for '
            'instances without a public ip address.'))

  parser.add_argument(
      '--secondary-range',
      type=arg_parsers.ArgDict(min_length=1),
      action='append',
      metavar='PROPERTY=VALUE',
      help="""\
      Adds a secondary IP range to the subnetwork for use in IP aliasing.

      For example, `--secondary-range range1=192.168.64.0/24` adds
      a secondary range 192.168.64.0/24 with name range1.

      * `RANGE_NAME` - Name of the secondary range.
      * `RANGE` - `IP range in CIDR format.`
      """)

  parser.add_argument(
      '--enable-flow-logs',
      action='store_true',
      default=None,
      help=('Enable/disable VPC Flow Logs for this subnet. More information '
            'for VPC Flow Logs can be found at '
            'https://cloud.google.com/vpc/docs/using-flow-logs.'))

  flags.AddLoggingAggregationInterval(parser, messages)
  parser.add_argument(
      '--logging-flow-sampling',
      type=arg_parsers.BoundedFloat(lower_bound=0.0, upper_bound=1.0),
      help="""\
      Can only be specified if VPC Flow Logs for this subnetwork is
      enabled. The value of the field must be in [0, 1]. Set the sampling rate
      of VPC flow logs within the subnetwork where 1.0 means all collected
      logs are reported and 0.0 means no logs are reported. Default is 0.5
      which means half of all collected logs are reported.
      """)

  parser.add_argument(
      '--logging-filter-expr',
      help="""\
        Can only be specified if VPC Flow Logs for this subnetwork is enabled.
        Export filter used to define which logs should be generated.
        """)
  flags.AddLoggingMetadata(parser, messages)
  parser.add_argument(
      '--logging-metadata-fields',
      type=arg_parsers.ArgList(),
      metavar='METADATA_FIELD',
      default=None,
      help="""\
      Can only be specified if VPC Flow Logs for this subnetwork is enabled
      and "metadata" is set to CUSTOM_METADATA. The comma-separated list of
      metadata fields that should be added to reported logs.
      """)

  if include_alpha_logging:
    messages = apis.GetMessagesModule('compute',
                                      compute_api.COMPUTE_ALPHA_API_VERSION)
    flags.AddLoggingAggregationIntervalDeprecated(parser, messages)
    parser.add_argument(
        '--flow-sampling',
        type=arg_parsers.BoundedFloat(lower_bound=0.0, upper_bound=1.0),
        help="""\
        Can only be specified if VPC flow logging for this subnetwork is
        enabled. The value of the field must be in [0, 1]. Set the sampling rate
        of VPC flow logs within the subnetwork where 1.0 means all collected
        logs are reported and 0.0 means no logs are reported. Default is 0.5
        which means half of all collected logs are reported.
        """)
    flags.AddLoggingMetadataDeprecated(parser, messages)

  purpose_choices = {
      'PRIVATE':
          'Regular user created or automatically created subnet.',
      'INTERNAL_HTTPS_LOAD_BALANCER':
          'Reserved for Internal HTTP(S) Load Balancing.',
      'REGIONAL_MANAGED_PROXY':
          'Reserved for Regional HTTP(S) Load Balancing.',
  }

  if include_global_managed_proxy:
    purpose_choices['GLOBAL_MANAGED_PROXY'] = (
        'Reserved for Global HTTP(S) Load Balancing.')

  if include_aggregate_purpose:
    purpose_choices['AGGREGATE'] = (
        'Reserved for Aggregate Ranges used for aggregating '
        'private subnetworks.')

  if include_private_service_connect:
    purpose_choices['PRIVATE_SERVICE_CONNECT'] = (
        'Reserved for Private Service Connect Internal Load Balancing.')

  if include_private_nat:
    purpose_choices['PRIVATE_NAT'] = (
        'Reserved for use as source range for Private NAT.')

  # Subnetwork purpose is introduced with L7ILB feature. Aggregate purpose
  # will have to be enabled for a given release track only after L7ILB feature
  # is enabled for that release track. Hence if include_aggregate_purpose
  # true, this code assumes that L7ILB purpose is enabled.
  if include_l7_internal_load_balancing:
    parser.add_argument(
        '--purpose',
        choices=purpose_choices,
        type=arg_utils.ChoiceToEnumName,
        help='The purpose of this subnetwork.')

  if include_l7_internal_load_balancing:
    if include_global_managed_proxy:
      help_text = (
          'The role of subnetwork. This field is required when the '
          'purpose is set to GLOBAL_MANAGED_PROXY, REGIONAL_MANAGED_PROXY or '
          'INTERNAL_HTTPS_LOAD_BALANCER.')
    else:
      help_text = ('The role of subnetwork. This field is required when the '
                   'purpose is set to REGIONAL_MANAGED_PROXY or '
                   'INTERNAL_HTTPS_LOAD_BALANCER.')

    parser.add_argument(
        '--role',
        choices={
            'ACTIVE': 'The ACTIVE subnet that is currently used.',
            'BACKUP': 'The BACKUP subnet that could be promoted to ACTIVE.'
        },
        type=lambda x: x.replace('-', '_').upper(),
        help=help_text)

  # Add private ipv6 google access enum based on api version.
  messages = apis.GetMessagesModule('compute', api_version)
  GetPrivateIpv6GoogleAccessTypeFlagMapper(messages).choice_arg.AddToParser(
      parser)

  parser.add_argument(
      '--stack-type',
      choices={
          'IPV4_ONLY':
              'New VMs in this subnet will only be assigned IPv4 addresses',
          'IPV4_IPV6':
              'New VMs in this subnet can have both IPv4 and IPv6 addresses'
      },
      type=arg_utils.ChoiceToEnumName,
      help=('The stack type for this subnet. Determines if IPv6 is enabled '
            'on the subnet. If not specified IPV4_ONLY will be used.'))

  ipv6_access_type_choices = {
      'EXTERNAL': 'VMs in this subnet can have external IPv6.',
      'INTERNAL': 'VMs in this subnet can have internal IPv6.'
  }
  parser.add_argument(
      '--ipv6-access-type',
      choices=ipv6_access_type_choices,
      type=arg_utils.ChoiceToEnumName,
      help=('IPv6 access type can be specified only when the subnet is '
            'created, or when the subnet is first updated to have a stack '
            'type of IPV4_IPV6. Once set, the access type is immutable.'))

  parser.display_info.AddCacheUpdater(network_flags.NetworksCompleter)

  if include_l2:
    l2_args = parser.add_group(help='L2 networking specifications.')
    l2_args.add_argument(
        '--enable-l2',
        action='store_true',
        required=True,
        help="""\
        If set to true, enables l2 networking capability on subnetwork.
        """)
    l2_args.add_argument(
        '--vlan',
        type=int,
        metavar='VLAN',
        help="""\
        Specifies ID of the vlan to tag the subnetwork.
        """)

  if include_reserved_internal_range:
    parser.add_argument(
        '--reserved-internal-range',
        help=("""
        If set, the primary IP range of the subnetwork will be
        associated with the given InternalRange resource.

        If --range is set, the subnetwork will only use the given IP range.
        It has to be contained by the IP range defined by the InternalRange resource.

        For example,
        --range=10.0.0.0/24
        --reserved-internal-range //networkconnectivity.googleapis.com/projects/PROJECT/locations/global/internalRanges/RANGE

        If --range is not set, the subnetwork will use the entire IP range
        defined by the InternalRange resource.

        For example, `--reserved-internal-range //networkconnectivity.googleapis.com/projects/PROJECT/locations/global/internalRanges/RANGE`

        """))
    parser.add_argument(
        '--secondary-range-with-reserved-internal-range',
        type=arg_parsers.ArgDict(min_length=1),
        action='append',
        metavar='RANGE_NAME=INTERNAL_RANGE_URL',
        help="""\
         Adds secondary IP ranges that are associated with InternalRange
         resources.

         For example, `--secondary-range-with-reserved-internal-range
         range1=//networkconnectivity.googleapis.com/projects/PROJECT/locations/global/internalRanges/RANGE`
         adds a secondary range with the reserved internal range resource.

         * `RANGE_NAME` - Name of the secondary range.
         * `INTERNAL_RANGE_URL` - `URL of an InternalRange resource.`
        """)
def AddAutoscalerArgs(parser,
                      queue_scaling_enabled=False,
                      autoscaling_file_enabled=False,
                      stackdriver_metrics_flags=False):
    """Adds commandline arguments to parser."""
    parser.add_argument(
        '--cool-down-period',
        type=arg_parsers.Duration(),
        help=(
            'The time period that the autoscaler should wait before it starts '
            'collecting information from a new instance. This prevents the '
            'autoscaler from collecting information when the instance is '
            'initializing, during which the collected usage would not be '
            'reliable. The default is 60 seconds.'))
    parser.add_argument('--description', help='Notes about Autoscaler.')
    parser.add_argument('--min-num-replicas',
                        type=arg_parsers.BoundedInt(0, sys.maxint),
                        help='Minimum number of replicas Autoscaler will set.')
    parser.add_argument('--max-num-replicas',
                        type=arg_parsers.BoundedInt(0, sys.maxint),
                        required=not autoscaling_file_enabled,
                        help='Maximum number of replicas Autoscaler will set.')
    parser.add_argument('--scale-based-on-cpu',
                        action='store_true',
                        help='Autoscaler will be based on CPU utilization.')
    parser.add_argument('--scale-based-on-load-balancing',
                        action='store_true',
                        help=('Use autoscaling based on load balancing '
                              'utilization.'))
    parser.add_argument(
        '--target-cpu-utilization',
        type=arg_parsers.BoundedFloat(0.0, 1.0),
        help='Autoscaler will aim to maintain CPU utilization at '
        'target level (0.0 to 1.0).')
    parser.add_argument(
        '--target-load-balancing-utilization',
        type=arg_parsers.BoundedFloat(0.0, None),
        help='Autoscaler will aim to maintain the load balancing '
        'utilization level (greater than 0.0).')
    custom_metric_utilization_help = """\
      Adds a target metric value for the Autoscaler to use.

      *metric*::: Protocol-free URL of a Google Cloud Monitoring metric.

      *utilization-target*::: Value of the metric Autoscaler will aim to
      maintain (greater than 0.0).

      *utilization-target-type*::: How target is expressed. Valid values: {0}.
      """.format(', '.join(_ALLOWED_UTILIZATION_TARGET_TYPES))
    if stackdriver_metrics_flags:
        custom_metric_utilization_help += (
            '\nMutually exclusive with `--update-stackdriver-metric`.')
    parser.add_argument(
        '--custom-metric-utilization',
        type=arg_parsers.ArgDict(spec={
            'metric': str,
            'utilization-target': float,
            'utilization-target-type': str,
        }, ),
        action='append',
        help=custom_metric_utilization_help,
    )

    if queue_scaling_enabled:
        parser.add_argument('--queue-scaling-cloud-pub-sub',
                            type=arg_parsers.ArgDict(spec={
                                'topic': str,
                                'subscription': str,
                            }, ),
                            help="""\
        Specifies queue-based scaling based on a Cloud Pub/Sub queuing system.
        Both topic and subscription are required.

        *topic*::: Topic specification. Can be just a name or a partial URL
        (starting with "projects/..."). Topic must belong to the same project as
        Autoscaler.

        *subscription*::: Subscription specification. Can be just a name or a
        partial URL (starting with "projects/..."). Subscription must belong to
        the same project as Autoscaler and must be connected to the specified
        topic.
        """)
        parser.add_argument(
            '--queue-scaling-acceptable-backlog-per-instance',
            type=arg_parsers.BoundedFloat(0.0, None),
            help='Queue-based scaling target: autoscaler will aim '
            'to assure that average number of tasks in the queue '
            'is no greater than this value.',
        )
        parser.add_argument(
            '--queue-scaling-single-worker-throughput',
            type=arg_parsers.BoundedFloat(0.0, None),
            help='Hint the autoscaler for queue-based scaling on '
            'how much throughput a single worker instance is able '
            'to consume.')
    if autoscaling_file_enabled:
        parser.add_argument(
            '--autoscaling-file',
            metavar='PATH',
            help=(
                'Path of the file from which autoscaling configuration will be '
                'loaded. This flag allows you to atomically setup complex '
                'autoscalers.'))
    if stackdriver_metrics_flags:
        parser.add_argument(
            '--remove-stackdriver-metric',
            metavar='METRIC',
            help=(
                'Stackdriver metric to remove from autoscaling configuration. '
                'If the metric is the only input used for autoscaling the '
                'command will fail.'))
        parser.add_argument(
            '--update-stackdriver-metric',
            metavar='METRIC',
            help=
            ('Stackdriver metric to use as an input for autoscaling. '
             'When using this flag you must also specify target value of the '
             'metric by specifying '
             '`--stackdriver-metric-single-instance-assignment` or '
             '`--stackdriver-metric-utilization-target` and '
             '`--stackdriver-metric-utilization-target-type`. '
             'Mutually exclusive with `--custom-metric-utilization`.'))
        parser.add_argument(
            '--stackdriver-metric-filter',
            metavar='FILTER',
            help=('Expression for filtering samples used to autoscale, see '
                  'https://cloud.google.com/monitoring/api/v3/filters.'))
        parser.add_argument(
            '--stackdriver-metric-utilization-target',
            metavar='TARGET',
            type=float,
            help=('Value of the metric Autoscaler will aim to maintain. When '
                  'specifying this flag you must also provide '
                  '`--stackdriver-metric-utilization-target-type`. Mutually '
                  'exclusive with '
                  '`--stackdriver-metric-single-instance-assignment` and '
                  '`--custom-metric-utilization`.'))

        parser.add_argument(
            '--stackdriver-metric-utilization-target-type',
            metavar='TARGET_TYPE',
            choices=_ALLOWED_UTILIZATION_TARGET_TYPES_LOWER,
            help=('Value of the metric Autoscaler will aim to maintain. When '
                  'specifying this flag you must also provide '
                  '`--stackdriver-metric-utilization-target`. Mutually '
                  'exclusive with '
                  '`--stackdriver-metric-single-instance-assignment` and '
                  '`--custom-metric-utilization`.'))
        parser.add_argument(
            '--stackdriver-metric-single-instance-assignment',
            metavar='ASSIGNMENT',
            type=float,
            help=('Autoscaler will aim to maintain value of metric divided by '
                  'number of instances at this level. Mutually '
                  'exclusive with '
                  '`-stackdriver-metric-utilization-target-type`, '
                  '`-stackdriver-metric-utilization-target-type`, and '
                  '`--custom-metric-utilization`.'))
def AddAutoscalerArgs(parser,
                      multizonal_enabled=False,
                      queue_scaling_enabled=False):
    """Adds commandline arguments to parser."""
    parser.add_argument(
        'name',
        metavar='NAME',
        completion_resource='compute.instanceGroupManagers',
        help='Managed instance group which autoscaling parameters will be set.'
    )
    parser.add_argument('--cool-down-period',
                        type=arg_parsers.Duration(),
                        help='Number of seconds Autoscaler will wait between '
                        'resizing collection.')
    parser.add_argument('--description', help='Notes about Autoscaler.')
    parser.add_argument('--min-num-replicas',
                        type=arg_parsers.BoundedInt(0, sys.maxint),
                        help='Minimum number of replicas Autoscaler will set.')
    parser.add_argument('--max-num-replicas',
                        type=arg_parsers.BoundedInt(0, sys.maxint),
                        required=True,
                        help='Maximum number of replicas Autoscaler will set.')
    parser.add_argument('--scale-based-on-cpu',
                        action='store_true',
                        help='Use autoscaling based on cpu utilization.')
    parser.add_argument('--scale-based-on-load-balancing',
                        action='store_true',
                        help=('Use autoscaling based on load balancing '
                              'utilization.'))
    parser.add_argument('--target-cpu-utilization',
                        type=arg_parsers.BoundedFloat(0.0, 1.0),
                        help='CPU utilization level Autoscaler will aim to '
                        'maintain (0.0 to 1.0).')
    parser.add_argument(
        '--target-load-balancing-utilization',
        type=arg_parsers.BoundedFloat(0.0, None),
        help='Load balancing utilization level Autoscaler will '
        'aim to maintain (greater than 0.0).')
    custom_metric_utilization = parser.add_argument(
        '--custom-metric-utilization',
        type=arg_parsers.ArgDict(spec={
            'metric': str,
            'utilization-target': float,
            'utilization-target-type': str,
        }, ),
        # pylint:disable=protected-access
        action=arg_parsers.FloatingListValuesCatcher(argparse._AppendAction),
        help=(
            'Adds target value of a Google Cloud Monitoring metric Autoscaler '
            'will aim to maintain.'),
        metavar='PROPERTY=VALUE',
    )
    custom_metric_utilization.detailed_help = """
   Adds a target metric value for the to the Autoscaler.

   *metric*::: Protocol-free URL of a Google Cloud Monitoring metric.

   *utilization-target*::: Value of the metric Autoscaler will aim to maintain
   (greater than 0.0).

   *utilization-target-type*::: How target is expressed. Valid values: {0}.
  """.format(', '.join(_ALLOWED_UTILIZATION_TARGET_TYPES))

    if queue_scaling_enabled:
        cloud_pub_sub_spec = parser.add_argument(
            '--queue-scaling-cloud-pub-sub',
            type=arg_parsers.ArgDict(spec={
                'topic': str,
                'subscription': str,
            }, ),
            help='Scaling based on Cloud Pub/Sub queuing system.',
            metavar='PROPERTY=VALUE',
        )
        cloud_pub_sub_spec.detailed_help = """
     Specifies queue-based scaling based on a Cloud Pub/Sub queuing system.
     Both topic and subscription are required.

     *topic*::: Topic specification. Can be just a name or a partial URL
     (starting with "projects/..."). Topic must belong to the same project as
     Autoscaler.

     *subscription*::: Subscription specification. Can be just a name or a
     partial URL (starting with "projects/..."). Subscription must belong to the
     same project as Autoscaler and must be connected to the specified topic.
    """
        parser.add_argument(
            '--queue-scaling-acceptable-backlog-per-instance',
            type=arg_parsers.BoundedFloat(0.0, None),
            help='Queue-based scaling target: auotscaler will aim '
            'to assure that average number of tasks in the queue '
            'is no greater than this value.',
        )
        parser.add_argument(
            '--queue-scaling-single-worker-throughput',
            type=arg_parsers.BoundedFloat(0.0, None),
            help='Hint the autoscaler for queue-based scaling on '
            'how much throughput a single worker instance is able '
            'to consume.')
    if multizonal_enabled:
        scope_parser = parser.add_mutually_exclusive_group()
        flags.AddRegionFlag(
            scope_parser,
            resource_type='resources',
            operation_type='update',
            explanation=flags.REGION_PROPERTY_EXPLANATION_NO_DEFAULT)
        flags.AddZoneFlag(
            scope_parser,
            resource_type='resources',
            operation_type='update',
            explanation=flags.ZONE_PROPERTY_EXPLANATION_NO_DEFAULT)
    else:
        flags.AddZoneFlag(parser,
                          resource_type='resources',
                          operation_type='update')
示例#20
0
def AddUpdateArgs(parser, include_alpha_logging,
                  include_l7_internal_load_balancing, include_stack_type,
                  include_ipv6_access_type, api_version):
    """Add args to the parser for subnet update.

  Args:
    parser: The argparse parser.
    include_alpha_logging: Include alpha-specific logging args.
    include_l7_internal_load_balancing: Include Internal HTTP(S) LB args.
    include_stack_type: Include stack type args.
    include_ipv6_access_type: Include IPv6 access type args.
    api_version: The api version of the request.
  """
    messages = apis.GetMessagesModule('compute',
                                      compute_api.COMPUTE_GA_API_VERSION)

    updated_field = parser.add_mutually_exclusive_group()

    updated_field.add_argument(
        '--enable-private-ip-google-access',
        action=arg_parsers.StoreTrueFalseAction,
        help=(
            'Enable/disable access to Google Cloud APIs from this subnet for '
            'instances without a public ip address.'))

    updated_field.add_argument('--add-secondary-ranges',
                               type=arg_parsers.ArgDict(min_length=1),
                               action='append',
                               metavar='PROPERTY=VALUE',
                               help="""\
      Adds secondary IP ranges to the subnetwork for use in IP aliasing.

      For example, `--add-secondary-ranges range1=192.168.64.0/24` adds
      a secondary range 192.168.64.0/24 with name range1.

      * `RANGE_NAME` - Name of the secondary range.
      * `RANGE` - `IP range in CIDR format.`
      """)

    updated_field.add_argument('--remove-secondary-ranges',
                               type=arg_parsers.ArgList(min_length=1),
                               action='append',
                               metavar='PROPERTY=VALUE',
                               help="""\
      Removes secondary ranges from the subnetwork.

      For example, `--remove-secondary-ranges range2,range3` removes the
      secondary ranges with names range2 and range3.
      """)

    updated_field.add_argument(
        '--enable-flow-logs',
        action=arg_parsers.StoreTrueFalseAction,
        help=(
            'Enable/disable VPC Flow Logs for this subnet. If the subnet does '
            ' not support VPC Flow Logs, this flag has no effect. For '
            ' more information, see '
            'https://cloud.google.com/vpc/docs/using-flow-logs.'))

    AddLoggingAggregationInterval(parser, messages)
    parser.add_argument('--logging-flow-sampling',
                        type=arg_parsers.BoundedFloat(lower_bound=0.0,
                                                      upper_bound=1.0),
                        help="""\
      Can only be specified if VPC Flow logs for this subnetwork is
      enabled. The value of the field must be in [0, 1]. Set the sampling rate
      of VPC flow logs within the subnetwork where 1.0 means all collected
      logs are reported and 0.0 means no logs are reported. Default is 0.5
      which means half of all collected logs are reported.
      """)
    AddLoggingMetadata(parser, messages)

    parser.add_argument('--logging-filter-expr',
                        help="""\
      Can only be specified if VPC Flow Logs for this subnetwork is enabled.
      Export filter used to define which logs should be generated.
      """)
    parser.add_argument('--logging-metadata-fields',
                        type=arg_parsers.ArgList(),
                        metavar='METADATA_FIELD',
                        default=None,
                        help="""\
      Can only be specified if VPC Flow Logs for this subnetwork is enabled
      and "metadata" is set to CUSTOM_METADATA. The comma-separated list of
      metadata fields that should be added to reported logs.
      """)

    if include_alpha_logging:
        messages = apis.GetMessagesModule(
            'compute', compute_api.COMPUTE_ALPHA_API_VERSION)
        AddLoggingAggregationIntervalDeprecated(parser, messages)
        parser.add_argument('--flow-sampling',
                            type=arg_parsers.BoundedFloat(lower_bound=0.0,
                                                          upper_bound=1.0),
                            help="""\
        Can only be specified if VPC Flow Logs for this subnetwork is enabled.
        The value of the field must be in [0, 1]. Set the sampling rate of
        VPC Flow Logs within the subnetwork where 1.0 means all collected
        logs are reported and 0.0 means no logs are reported. Default is 0.5
        which means half of all collected logs are reported.
        """)
        AddLoggingMetadataDeprecated(parser, messages)

    if include_l7_internal_load_balancing:
        updated_field.add_argument(
            '--role',
            choices={'ACTIVE': 'The ACTIVE subnet that is currently used.'},
            type=lambda x: x.replace('-', '_').upper(),
            help=(
                'The role is set to ACTIVE to update a BACKUP reserved '
                'address range to\nbe the new ACTIVE address range. Note '
                'that the only supported value for\nthis flag is ACTIVE since '
                'setting an address range to BACKUP is not\nsupported. '
                '\n\nThis field is only valid when updating a reserved IP '
                'address range used\nfor the purpose of Internal HTTP(S) Load '
                'Balancer.'))
        parser.add_argument('--drain-timeout',
                            type=arg_parsers.Duration(lower_bound='0s'),
                            default='0s',
                            help="""\
        The time period for draining traffic from Internal HTTP(S) Load Balancer
        proxies that are assigned addresses in the current ACTIVE subnetwork.
        For example, ``1h'', ``60m'' and ``3600s'' each specify a duration of
        1 hour for draining the traffic. Longer times reduce the number of
        proxies that are draining traffic at any one time, and so improve
        the availability of proxies for load balancing. The drain timeout is
        only applicable when the [--role=ACTIVE] flag is being used.
        """)

    if include_stack_type:
        parser.add_argument(
            '--stack-type',
            choices={
                'IPV4_ONLY':
                'New VMs in this subnet will only be assigned IPv4 addresses',
                'IPV4_IPV6':
                'New VMs in this subnet can have both IPv4 and IPv6 addresses'
            },
            type=arg_utils.ChoiceToEnumName,
            help=(
                'The stack type for this subnet to identify whether the IPv6 '
                'feature is enabled or not.'))

    if include_ipv6_access_type:
        parser.add_argument(
            '--ipv6-access-type',
            choices={
                'INTERNAL': 'VMs in this subnet can have internal IPv6.',
                'EXTERNAL': 'VMs in this subnet can have external IPv6.'
            },
            type=arg_utils.ChoiceToEnumName,
            help=(
                'The access type of IPv6 address this subnet holds. It\'s '
                'immutable and can only be specified during creation or the '
                'time the subnet is updated into IPV4_IPV6 dual stack. If the '
                'ipv6 access type is EXTERNAL then this subnet cannot enable '
                'direct path.'))

    messages = apis.GetMessagesModule('compute', api_version)
    GetPrivateIpv6GoogleAccessTypeFlagMapper(messages).choice_arg.AddToParser(
        updated_field)
示例#21
0
def AddAutoscalerArgs(parser, queue_scaling_enabled=False):
    """Adds commandline arguments to parser."""
    parser.add_argument(
        '--cool-down-period',
        type=arg_parsers.Duration(),
        help='Number of seconds Autoscaler will wait between '
        'resizing collection. Note: The Autoscaler waits '
        '10 minutes before scaling down, the value entered here '
        'is in addition to the initial 10 minute period.')
    parser.add_argument('--description', help='Notes about Autoscaler.')
    parser.add_argument('--min-num-replicas',
                        type=arg_parsers.BoundedInt(0, sys.maxint),
                        help='Minimum number of replicas Autoscaler will set.')
    parser.add_argument('--max-num-replicas',
                        type=arg_parsers.BoundedInt(0, sys.maxint),
                        required=True,
                        help='Maximum number of replicas Autoscaler will set.')
    parser.add_argument('--scale-based-on-cpu',
                        action='store_true',
                        help='Autoscaler will be based on CPU utilization.')
    parser.add_argument('--scale-based-on-load-balancing',
                        action='store_true',
                        help=('Use autoscaling based on load balancing '
                              'utilization.'))
    parser.add_argument(
        '--target-cpu-utilization',
        type=arg_parsers.BoundedFloat(0.0, 1.0),
        help='Autoscaler will aim to maintain CPU utilization at '
        'target level (0.0 to 1.0).')
    parser.add_argument(
        '--target-load-balancing-utilization',
        type=arg_parsers.BoundedFloat(0.0, None),
        help='Autoscaler will aim to maintain the load balancing '
        'utilization level (greater than 0.0).')
    parser.add_argument('--custom-metric-utilization',
                        type=arg_parsers.ArgDict(spec={
                            'metric':
                            str,
                            'utilization-target':
                            float,
                            'utilization-target-type':
                            str,
                        }, ),
                        action='append',
                        help="""\
      Adds a target metric value for the to the Autoscaler.

      *metric*::: Protocol-free URL of a Google Cloud Monitoring metric.

      *utilization-target*::: Value of the metric Autoscaler will aim to
      maintain (greater than 0.0).

      *utilization-target-type*::: How target is expressed. Valid values: {0}.
      """.format(', '.join(_ALLOWED_UTILIZATION_TARGET_TYPES)))

    if queue_scaling_enabled:
        parser.add_argument('--queue-scaling-cloud-pub-sub',
                            type=arg_parsers.ArgDict(spec={
                                'topic': str,
                                'subscription': str,
                            }, ),
                            help="""\
        Specifies queue-based scaling based on a Cloud Pub/Sub queuing system.
        Both topic and subscription are required.

        *topic*::: Topic specification. Can be just a name or a partial URL
        (starting with "projects/..."). Topic must belong to the same project as
        Autoscaler.

        *subscription*::: Subscription specification. Can be just a name or a
        partial URL (starting with "projects/..."). Subscription must belong to
        the same project as Autoscaler and must be connected to the specified
        topic.
        """)
        parser.add_argument(
            '--queue-scaling-acceptable-backlog-per-instance',
            type=arg_parsers.BoundedFloat(0.0, None),
            help='Queue-based scaling target: autoscaler will aim '
            'to assure that average number of tasks in the queue '
            'is no greater than this value.',
        )
        parser.add_argument(
            '--queue-scaling-single-worker-throughput',
            type=arg_parsers.BoundedFloat(0.0, None),
            help='Hint the autoscaler for queue-based scaling on '
            'how much throughput a single worker instance is able '
            'to consume.')
示例#22
0
def AddAutoscalerArgs(
    parser,
    autoscaling_file_enabled=False,
    stackdriver_metrics_flags=False,
    scale_in=False,
    predictive=False):
  """Adds commandline arguments to parser."""
  parser.add_argument(
      '--cool-down-period',
      type=arg_parsers.Duration(),
      help=('The time period that the autoscaler should wait before it starts '
            'collecting information from a new instance. This prevents the '
            'autoscaler from collecting information when the instance is '
            'initializing, during which the collected usage would not be '
            'reliable. The default is 60s. See $ gcloud topic datetimes '
            'for information on duration formats.'))
  parser.add_argument('--description', help='Notes about Autoscaler.')
  parser.add_argument('--min-num-replicas',
                      type=arg_parsers.BoundedInt(0, sys.maxsize),
                      help='Minimum number of replicas Autoscaler will set.')
  parser.add_argument('--max-num-replicas',
                      type=arg_parsers.BoundedInt(0, sys.maxsize),
                      required=not autoscaling_file_enabled,
                      help='Maximum number of replicas Autoscaler will set.')
  parser.add_argument('--scale-based-on-cpu',
                      action='store_true',
                      help='Autoscaler will be based on CPU utilization.')
  parser.add_argument('--scale-based-on-load-balancing',
                      action='store_true',
                      help=('Use autoscaling based on load balancing '
                            'utilization.'))
  parser.add_argument('--target-cpu-utilization',
                      type=arg_parsers.BoundedFloat(0.0, 1.0),
                      help='Autoscaler will aim to maintain CPU utilization at '
                      'target level (0.0 to 1.0).')
  parser.add_argument('--target-load-balancing-utilization',
                      type=arg_parsers.BoundedFloat(0.0, None),
                      help='Autoscaler will aim to maintain the load balancing '
                      'utilization level (greater than 0.0).')
  custom_metric_utilization_help = """\
Adds a target metric value for the Autoscaler to use.

*metric*::: Protocol-free URL of a Google Cloud Monitoring metric.

*utilization-target*::: Value of the metric Autoscaler will aim to
  maintain (greater than 0.0).

*utilization-target-type*::: How target is expressed. Valid values: {0}.
""".format(', '.join(_ALLOWED_UTILIZATION_TARGET_TYPES))
  if stackdriver_metrics_flags:
    custom_metric_utilization_help += """
Mutually exclusive with `--update-stackdriver-metric`.
"""
  parser.add_argument(
      '--custom-metric-utilization',
      type=arg_parsers.ArgDict(
          spec={
              'metric': str,
              'utilization-target': float,
              'utilization-target-type': str,
          },
      ),
      action='append',
      help=custom_metric_utilization_help,
  )

  if autoscaling_file_enabled:
    parser.add_argument(
        '--autoscaling-file',
        metavar='PATH',
        help=('Path of the file from which autoscaling configuration will be '
              'loaded. This flag allows you to atomically setup complex '
              'autoscalers.'))
  if stackdriver_metrics_flags:
    parser.add_argument(
        '--remove-stackdriver-metric',
        metavar='METRIC',
        help=('Stackdriver metric to remove from autoscaling configuration. '
              'If the metric is the only input used for autoscaling the '
              'command will fail.'))
    parser.add_argument(
        '--update-stackdriver-metric',
        metavar='METRIC',
        help=('Stackdriver metric to use as an input for autoscaling. '
              'When using this flag you must also specify target value of the '
              'metric by specifying '
              '`--stackdriver-metric-single-instance-assignment` or '
              '`--stackdriver-metric-utilization-target` and '
              '`--stackdriver-metric-utilization-target-type`. '
              'Mutually exclusive with `--custom-metric-utilization`.'))
    parser.add_argument(
        '--stackdriver-metric-filter',
        metavar='FILTER',
        help=('Expression for filtering samples used to autoscale, see '
              'https://cloud.google.com/monitoring/api/v3/filters.'))
    parser.add_argument(
        '--stackdriver-metric-utilization-target',
        metavar='TARGET',
        type=float,
        help=('Value of the metric Autoscaler will aim to maintain. When '
              'specifying this flag you must also provide '
              '`--stackdriver-metric-utilization-target-type`. Mutually '
              'exclusive with '
              '`--stackdriver-metric-single-instance-assignment` and '
              '`--custom-metric-utilization`.'))

    parser.add_argument(
        '--stackdriver-metric-utilization-target-type',
        metavar='TARGET_TYPE',
        choices=_ALLOWED_UTILIZATION_TARGET_TYPES_LOWER,
        help=('Value of the metric Autoscaler will aim to maintain. When '
              'specifying this flag you must also provide '
              '`--stackdriver-metric-utilization-target`. Mutually '
              'exclusive with '
              '`--stackdriver-metric-single-instance-assignment` and '
              '`--custom-metric-utilization`.'))
    parser.add_argument(
        '--stackdriver-metric-single-instance-assignment',
        metavar='ASSIGNMENT',
        type=float,
        help=('Autoscaler will aim to maintain value of metric divided by '
              'number of instances at this level. Mutually '
              'exclusive with '
              '`-stackdriver-metric-utilization-target-type`, '
              '`-stackdriver-metric-utilization-target-type`, and '
              '`--custom-metric-utilization`.'))

  GetModeFlag().AddToParser(parser)

  if scale_in:
    AddScaleInControlFlag(parser)

  if predictive:
    AddPredictiveAutoscaling(parser)
示例#23
0
def _AddArgs(cls, parser, include_alpha=False):
    """Add subnetwork create arguments to parser."""
    cls.SUBNETWORK_ARG = flags.SubnetworkArgument()
    cls.NETWORK_ARG = network_flags.NetworkArgumentForOtherResource(
        'The network to which the subnetwork belongs.')
    cls.SUBNETWORK_ARG.AddArgument(parser, operation_type='create')
    cls.NETWORK_ARG.AddArgument(parser)

    parser.add_argument('--description',
                        help='An optional description of this subnetwork.')

    parser.add_argument(
        '--range',
        required=True,
        help='The IP space allocated to this subnetwork in CIDR format.')

    parser.add_argument(
        '--enable-private-ip-google-access',
        action='store_true',
        default=False,
        help=(
            'Enable/disable access to Google Cloud APIs from this subnet for '
            'instances without a public ip address.'))

    parser.add_argument('--secondary-range',
                        type=arg_parsers.ArgDict(min_length=1),
                        action='append',
                        metavar='PROPERTY=VALUE',
                        help="""\
      Adds a secondary IP range to the subnetwork for use in IP aliasing.

      For example, `--secondary-range range1=192.168.64.0/24` adds
      a secondary range 192.168.64.0/24 with name range1.

      * `RANGE_NAME` - Name of the secondary range.
      * `RANGE` - `IP range in CIDR format.`
      """)

    parser.add_argument(
        '--enable-flow-logs',
        action='store_true',
        default=None,
        help=(
            'Enable/disable VPC flow logging for this subnet. More information '
            'for VPC flow logs can be found at '
            'https://cloud.google.com/vpc/docs/using-flow-logs.'))

    if include_alpha:
        parser.add_argument(
            '--purpose',
            choices={
                'PRIVATE_RFC_1918':
                'Regular user created or automatically created subnet.',
                'INTERNAL_HTTPS_LOAD_BALANCER':
                'Reserved for Internal HTTP(S) Load Balancing.'
            },
            type=lambda x: x.replace('-', '_').upper(),
            help='The purpose of this subnetwork.')

        parser.add_argument(
            '--role',
            choices={
                'ACTIVE': 'The ACTIVE subnet that is currently used.',
                'BACKUP': 'The BACKUP subnet that could be promoted to ACTIVE.'
            },
            type=lambda x: x.replace('-', '_').upper(),
            help=
            ('The role of subnetwork. This field is only used when'
             'purpose=INTERNAL_HTTPS_LOAD_BALANCER. The value can be set to '
             'ACTIVE or BACKUP. An ACTIVE subnetwork is one that is currently '
             'being used for Internal HTTP(S) Load Balancing. A BACKUP '
             'subnetwork is one that is ready to be promoted to ACTIVE or is '
             'currently draining.'))

        aggregation_interval_argument = base.ChoiceArgument(
            '--aggregation-interval',
            choices=[
                'interval-5-sec', 'interval-30-sec', 'interval-1-min',
                'interval-5-min', 'interval-10-min', 'interval-15-min'
            ],
            help_str="""\
        Can only be specified if VPC flow logging for this subnetwork is
        enabled. Toggles the aggregation interval for collecting flow logs.
        Increasing the interval time will reduce the amount of generated flow
        logs for long lasting connections. Default is an interval of 5 seconds
        per connection.
        """)
        aggregation_interval_argument.AddToParser(parser)

        parser.add_argument('--flow-sampling',
                            type=arg_parsers.BoundedFloat(lower_bound=0.0,
                                                          upper_bound=1.0),
                            help="""\
        Can only be specified if VPC flow logging for this subnetwork is
        enabled. The value of the field must be in [0, 1]. Set the sampling rate
        of VPC flow logs within the subnetwork where 1.0 means all collected
        logs are reported and 0.0 means no logs are reported. Default is 0.5
        which means half of all collected logs are reported.
        """)

        metadata_argument = base.ChoiceArgument(
            '--metadata',
            choices=['include-all-metadata', 'exclude-all-metadata'],
            help_str="""\
        Can only be specified if VPC flow logging for this subnetwork is
        enabled. Configures whether metadata fields should be added to the
        reported VPC flow logs. Default is to include all metadata.
        """)
        metadata_argument.AddToParser(parser)
示例#24
0
def AddUpdateArgs(parser, include_alpha=False):
    """Add args to the parser for subnet update.

  Args:
    parser: The argparse parser.
    include_alpha: Include alpha functionality.
  """
    updated_field = parser.add_mutually_exclusive_group()

    updated_field.add_argument(
        '--enable-private-ip-google-access',
        action=arg_parsers.StoreTrueFalseAction,
        help=(
            'Enable/disable access to Google Cloud APIs from this subnet for '
            'instances without a public ip address.'))

    updated_field.add_argument('--add-secondary-ranges',
                               type=arg_parsers.ArgDict(min_length=1),
                               action='append',
                               metavar='PROPERTY=VALUE',
                               help="""\
      Adds secondary IP ranges to the subnetwork for use in IP aliasing.

      For example, `--add-secondary-ranges range1=192.168.64.0/24` adds
      a secondary range 192.168.64.0/24 with name range1.

      * `RANGE_NAME` - Name of the secondary range.
      * `RANGE` - `IP range in CIDR format.`
      """)

    updated_field.add_argument('--remove-secondary-ranges',
                               type=arg_parsers.ArgList(min_length=1),
                               action='append',
                               metavar='PROPERTY=VALUE',
                               help="""\
      Removes secondary ranges from the subnetwork.

      For example, `--remove-secondary-ranges range2,range3` removes the
      secondary ranges with names range2 and range3.
      """)

    updated_field.add_argument(
        '--enable-flow-logs',
        action=arg_parsers.StoreTrueFalseAction,
        help=(
            'Enable/disable VPC flow logging for this subnet. More information '
            'for VPC flow logs can be found at '
            'https://cloud.google.com/vpc/docs/using-flow-logs.'))

    if include_alpha:
        updated_field.add_argument(
            '--role',
            choices={'ACTIVE': 'The ACTIVE subnet that is currently used.'},
            type=lambda x: x.replace('-', '_').upper(),
            help=(
                'The role is set to ACTIVE to update a BACKUP reserved '
                'address range to\nbe the new ACTIVE address range. Note '
                'that the only supported value for\nthis flag is ACTIVE since '
                'setting an address range to BACKUP is not\nsupported. '
                '\n\nThis field is only valid when updating a reserved IP '
                'address range used\nfor the purpose of Internal HTTP(S) Load '
                'Balancer.'))

        parser.add_argument('--drain-timeout',
                            type=arg_parsers.Duration(lower_bound='0s'),
                            default='0s',
                            help="""\
        The drain timeout specifies the upper bound in seconds on the amount of
        time allowed to drain connections from the current ACTIVE subnetwork to
        the current BACKUP subnetwork. The drain timeout is only applicable when
        the [--set-role-active] flag is being used.
        """)

        aggregation_interval_argument = base.ChoiceArgument(
            '--aggregation-interval',
            choices=[
                'interval-5-sec', 'interval-30-sec', 'interval-1-min',
                'interval-5-min', 'interval-10-min', 'interval-15-min'
            ],
            help_str="""\
        Can only be specified if VPC flow logging for this subnetwork is
        enabled. Toggles the aggregation interval for collecting flow logs.
        Increasing the interval time will reduce the amount of generated flow
        logs for long lasting connections. Default is an interval of 5 seconds
        per connection.
        """)
        aggregation_interval_argument.AddToParser(parser)

        parser.add_argument('--flow-sampling',
                            type=arg_parsers.BoundedFloat(lower_bound=0.0,
                                                          upper_bound=1.0),
                            help="""\
        Can only be specified if VPC flow logging for this subnetwork is
        enabled. The value of the field must be in [0, 1]. Set the sampling rate
        of VPC flow logs within the subnetwork where 1.0 means all collected
        logs are reported and 0.0 means no logs are reported. Default is 0.5
        which means half of all collected logs are reported.
        """)

        metadata_argument = base.ChoiceArgument(
            '--metadata',
            choices=['include-all-metadata', 'exclude-all-metadata'],
            help_str="""\
        Can only be specified if VPC flow logging for this subnetwork is
        enabled. Configures whether metadata fields should be added to the
        reported VPC flow logs. Default is to include all metadata.
        """)
        metadata_argument.AddToParser(parser)
示例#25
0
文件: flags.py 项目: iofh/QA-System
def CommonFlags(parser):
  """Add common flags for local developement environments."""
  builder_group = parser.add_mutually_exclusive_group(required=False)
  builder_group.add_argument(
      '--dockerfile',
      default='Dockerfile',
      help='Dockerfile for the service image.')

  builder_group.add_argument(
      '--builder',
      help='Build with a given Cloud Native Computing Foundation Buildpack '
      'builder.')

  parser.add_argument(
      '--service-name', required=False, help='Name of the service.')

  parser.add_argument(
      '--image-name', required=False, help='Name for the built docker image.')

  parser.add_argument(
      '--build-context-directory',
      help='If set, use this as the context directory when building the '
      'container image. Otherwise, the directory of the Dockerfile will be '
      'used.')

  credential_group = parser.add_mutually_exclusive_group(required=False)
  credential_group.add_argument(
      '--service-account',
      help='When connecting to Google Cloud Platform services, use a service '
      'account key.')

  credential_group.add_argument(
      '--application-default-credential',
      action='store_true',
      default=False,
      help='When connecting to Google Cloud Platform services, use the '
      'application default credential.')

  parser.add_argument(
      '--local-port',
      type=int,
      help='Local port to which the service connection is forwarded. If this '
      'flag is not set, then a random port is chosen.')

  parser.add_argument(
      '--cloudsql-instances',
      type=arg_parsers.ArgList(),
      metavar='CLOUDSQL_INSTANCE',
      help='Cloud SQL instance connection strings. Must be in the form '
      '<project>:<region>:<instance>.')

  parser.add_argument(
      '--cpu-limit',
      type=arg_parsers.BoundedFloat(lower_bound=0.0),
      help='Container CPU limit. Limit is expressed as a number of CPUs. '
      'Fractional CPU limits are allowed (e.g. 1.5).')

  parser.add_argument(
      '--memory-limit',
      type=arg_parsers.BinarySize(default_unit='B'),
      help='Container memory limit. Limit is expressed either as an integer '
      'representing the number of bytes or an integer followed by a unit '
      'suffix. Valid unit suffixes are "B", "KB", "MB", "GB", "TB", "KiB", '
      '"MiB", "GiB", "TiB", or "PiB".')

  env_var_group = parser.add_mutually_exclusive_group(required=False)
  env_var_group.add_argument(
      '--env-vars',
      metavar='KEY=VALUE',
      action=arg_parsers.UpdateAction,
      type=arg_parsers.ArgDict(
          key_type=six.text_type, value_type=six.text_type),
      help='List of key-value pairs to set as environment variables.')

  env_var_group.add_argument(
      '--env-vars-file',
      metavar='FILE_PATH',
      type=map_util.ArgDictFile(
          key_type=six.text_type, value_type=six.text_type),
      help='Path to a local YAML file with definitions for all environment '
      'variables.')
示例#26
0
def AddUpdateArgs(parser, include_alpha_logging,
                  include_l7_internal_load_balancing,
                  include_private_ipv6_access_alpha,
                  include_private_ipv6_access_beta):
    """Add args to the parser for subnet update.

  Args:
    parser: The argparse parser.
    include_alpha_logging: Include alpha-specific logging args.
    include_l7_internal_load_balancing: Include Internal HTTP(S) LB args.
    include_private_ipv6_access_alpha: Include alpha Private Ipv6 Access args.
    include_private_ipv6_access_beta: Include beta Private Ipv6 Access args.
  """
    messages = apis.GetMessagesModule('compute',
                                      compute_api.COMPUTE_GA_API_VERSION)

    updated_field = parser.add_mutually_exclusive_group()

    updated_field.add_argument(
        '--enable-private-ip-google-access',
        action=arg_parsers.StoreTrueFalseAction,
        help=(
            'Enable/disable access to Google Cloud APIs from this subnet for '
            'instances without a public ip address.'))

    updated_field.add_argument('--add-secondary-ranges',
                               type=arg_parsers.ArgDict(min_length=1),
                               action='append',
                               metavar='PROPERTY=VALUE',
                               help="""\
      Adds secondary IP ranges to the subnetwork for use in IP aliasing.

      For example, `--add-secondary-ranges range1=192.168.64.0/24` adds
      a secondary range 192.168.64.0/24 with name range1.

      * `RANGE_NAME` - Name of the secondary range.
      * `RANGE` - `IP range in CIDR format.`
      """)

    updated_field.add_argument('--remove-secondary-ranges',
                               type=arg_parsers.ArgList(min_length=1),
                               action='append',
                               metavar='PROPERTY=VALUE',
                               help="""\
      Removes secondary ranges from the subnetwork.

      For example, `--remove-secondary-ranges range2,range3` removes the
      secondary ranges with names range2 and range3.
      """)

    updated_field.add_argument(
        '--enable-flow-logs',
        action=arg_parsers.StoreTrueFalseAction,
        help=('Enable/disable VPC Flow Logs for this subnet. More information '
              'for VPC Flow Logs can be found at '
              'https://cloud.google.com/vpc/docs/using-flow-logs.'))

    AddLoggingAggregationInterval(parser, messages)
    parser.add_argument('--logging-flow-sampling',
                        type=arg_parsers.BoundedFloat(lower_bound=0.0,
                                                      upper_bound=1.0),
                        help="""\
      Can only be specified if VPC Flow logs for this subnetwork is
      enabled. The value of the field must be in [0, 1]. Set the sampling rate
      of VPC flow logs within the subnetwork where 1.0 means all collected
      logs are reported and 0.0 means no logs are reported. Default is 0.5
      which means half of all collected logs are reported.
      """)
    AddLoggingMetadata(parser, messages)

    parser.add_argument('--logging-filter-expr',
                        help="""\
      Can only be specified if VPC Flow Logs for this subnetwork is enabled.
      Export filter used to define which logs should be generated.
      """)
    parser.add_argument('--logging-metadata-fields',
                        type=arg_parsers.ArgList(),
                        metavar='METADATA_FIELD',
                        default=None,
                        help="""\
      Can only be specified if VPC Flow Logs for this subnetwork is enabled
      and "metadata" is set to CUSTOM_METADATA. The comma-separated list of
      metadata fields that should be added to reported logs.
      """)

    if include_alpha_logging:
        messages = apis.GetMessagesModule(
            'compute', compute_api.COMPUTE_ALPHA_API_VERSION)
        AddLoggingAggregationIntervalDeprecated(parser, messages)
        parser.add_argument('--flow-sampling',
                            type=arg_parsers.BoundedFloat(lower_bound=0.0,
                                                          upper_bound=1.0),
                            help="""\
        Can only be specified if VPC Flow Logs for this subnetwork is enabled.
        The value of the field must be in [0, 1]. Set the sampling rate of
        VPC Flow Logs within the subnetwork where 1.0 means all collected
        logs are reported and 0.0 means no logs are reported. Default is 0.5
        which means half of all collected logs are reported.
        """)
        AddLoggingMetadataDeprecated(parser, messages)

    if include_l7_internal_load_balancing:
        updated_field.add_argument(
            '--role',
            choices={'ACTIVE': 'The ACTIVE subnet that is currently used.'},
            type=lambda x: x.replace('-', '_').upper(),
            help=(
                'The role is set to ACTIVE to update a BACKUP reserved '
                'address range to\nbe the new ACTIVE address range. Note '
                'that the only supported value for\nthis flag is ACTIVE since '
                'setting an address range to BACKUP is not\nsupported. '
                '\n\nThis field is only valid when updating a reserved IP '
                'address range used\nfor the purpose of Internal HTTP(S) Load '
                'Balancer.'))
        parser.add_argument('--drain-timeout',
                            type=arg_parsers.Duration(lower_bound='0s'),
                            default='0s',
                            help="""\
        The time period for draining traffic from Internal HTTP(S) Load Balancer
        proxies that are assigned addresses in the current ACTIVE subnetwork.
        For example, ``1h'', ``60m'' and ``3600s'' each specify a duration of
        1 hour for draining the traffic. Longer times reduce the number of
        proxies that are draining traffic at any one time, and so improve
        the availability of proxies for load balancing. The drain timeout is
        only applicable when the [--role=ACTIVE] flag is being used.
        """)

    if include_private_ipv6_access_alpha:
        messages = apis.GetMessagesModule(
            'compute', compute_api.COMPUTE_ALPHA_API_VERSION)
        updated_field.add_argument(
            '--enable-private-ipv6-access',
            action=arg_parsers.StoreTrueFalseAction,
            help=('Enable/disable private IPv6 access for the subnet.'))
        update_private_ipv6_access_field = updated_field.add_argument_group()
        GetPrivateIpv6GoogleAccessTypeFlagMapperAlpha(
            messages).choice_arg.AddToParser(update_private_ipv6_access_field)
        update_private_ipv6_access_field.add_argument(
            '--private-ipv6-google-access-service-accounts',
            default=None,
            metavar='EMAIL',
            type=arg_parsers.ArgList(min_length=0),
            help="""\
        The service accounts can be used to selectively turn on Private IPv6
        Google Access only on the VMs primary service account matching the
        value.

        Setting this will override the existing Private IPv6 Google Access
        service accounts for the subnetwork.
        The following will clear the existing Private IPv6 Google Access service
        accounts:

        $ {command} MY-SUBNET --private-ipv6-google-access-service-accounts ''
        """)
    elif include_private_ipv6_access_beta:
        messages = apis.GetMessagesModule('compute',
                                          compute_api.COMPUTE_BETA_API_VERSION)
        update_private_ipv6_access_field = updated_field.add_argument_group()
        GetPrivateIpv6GoogleAccessTypeFlagMapperBeta(
            messages).choice_arg.AddToParser(update_private_ipv6_access_field)
 def AddCpu(self):
     self._AddFlag(
         '--cpu',
         type=arg_parsers.BoundedFloat(lower_bound=0.0),
         help='Container CPU limit. Limit is expressed as a number of CPUs. '
         'Fractional CPU limits are allowed (e.g. 1.5).')