Exemplo n.º 1
0
 def Args(parser):
   parser.add_argument(
       '--host-port',
       required=False,
       type=lambda arg: arg_parsers.HostPort.Parse(arg, ipv6_enabled=True),
       help='The host:port to which the emulator should be bound. The default '
       'value is localhost:9010. Note that this port serves gRPC requests. To '
       'override the default port serving REST requests, use --rest-port. If '
       'using Docker to run the emulator, the host must be specified as an '
       'ipaddress.')
   parser.add_argument(
       '--rest-port',
       required=False,
       type=arg_parsers.BoundedInt(1, 65535),
       help='The port at which REST requests are served. gcloud uses REST to '
       'communicate with the emulator. The default value is 9020.')
   parser.add_argument(
       '--use-docker',
       required=False,
       type=arg_parsers.ArgBoolean(),
       help='Use the cloud spanner emulator docker image even if the platform '
       'has a native binary available in the sdk. Currently we only provide a '
       'native binary for Linux. For other systems, you must install docker '
       'for your platform before starting the emulator.')
   parser.add_argument(
       '--enable-fault-injection',
       required=False,
       type=arg_parsers.ArgBoolean(),
       help='If true, the emulator will randomly inject faults into '
       'transactions. This facilitates application abort-retry testing.',
       default=False)
Exemplo n.º 2
0
def GetUseChiefInTfConfig():
  """Build use-chief-in-tf-config flag."""
  return base.Argument(
      '--use-chief-in-tf-config',
      required=False,
      type=arg_parsers.ArgBoolean(),
      help=('Use "chief" role in the cluster instead of "master". This is '
            'required for TensorFlow 2.0 and newer versions. Unlike "master" '
            'node, "chief" node does not run evaluation.'))
Exemplo n.º 3
0
def AddPoolsArg(parser):
    parser.add_argument('--pools',
                        type=arg_parsers.ArgDict(
                            required_keys=[
                                'name',
                                'roles',
                            ],
                            spec={
                                'name': str,
                                'roles': str,
                                'machineType': str,
                                'preemptible': arg_parsers.ArgBoolean(),
                                'localSsdCount': int,
                                'accelerators': str,
                                'minCpuPlatform': str,
                                'locations': str,
                                'min': int,
                                'max': int,
                            },
                        ),
                        action='append',
                        default=[],
                        metavar='KEY=VALUE[;VALUE]',
                        help="""
        Each `--pools` flag represents a single GKE node pool associated with
        the virtual cluster. It is comprised of a CSV in the form
        `KEY=VALUE[;VALUE]`, where certain keys may have multiple values.

        The following KEYs must be specified:

        KEY | Type | Example | Description
        --- |  --- | --- | ---
        name | string | `my-node-pool` | Name of the node pool.
        roles | repeated string | `default;spark-driver` | Roles that this node pool should perform. Valid values are `default`, `controller`, `spark-driver`, `spark-executor`.

        The following KEYs may be specified.

        KEY | Type | Example | Description
        --- | --- | --- | ---
        machineType | string | `n1-standard-8` | Compute Engine machine type to use.
        preemptible | boolean | `false` | If true, then this node pool uses preemptible VMs. This cannot be true on the node pool with the `controllers` role (or `default` role if `controllers` role is not specified).
        localSsdCount | int | `2` | The number of local SSDs to attach to each node.
        accelerator | repeated string | `nvidia-tesla-a100=1` | Accelerators to attach to each node. In the format NAME=COUNT.
        minCpuPlatform | string | `Intel Skylake` | Minimum CPU platform for each node.
        locations | repeated string | `us-west1-a;us-west1-c` | Zones within the location of the GKE cluster. All `--pools` flags for a single Dataproc cluster must have identical locations.
        min | int | `0` | Minimum number of nodes per zone that this node pool can scale down to.
        max | int | `10` | Maximum number of nodes per zone that this node pool can scale up to.
        """)
Exemplo n.º 4
0
def _CommonArgs(parser,
                release_track,
                support_source_instance,
                support_network_tier=False,
                support_local_ssd_size=False,
                support_shielded_vms=False,
                support_sole_tenancy=False):
    """Adding arguments applicable for creating instance templates."""
    parser.display_info.AddFormat(instance_templates_flags.DEFAULT_LIST_FORMAT)
    metadata_utils.AddMetadataArgs(parser)
    instances_flags.AddDiskArgs(parser)
    instances_flags.AddCreateDiskArgs(parser)
    if support_local_ssd_size:
        instances_flags.AddLocalSsdArgsWithSize(parser)
    else:
        instances_flags.AddLocalSsdArgs(parser)
    instances_flags.AddCanIpForwardArgs(parser)
    instances_flags.AddAddressArgs(parser,
                                   instances=False,
                                   support_network_tier=support_network_tier)
    instances_flags.AddAcceleratorArgs(parser)
    instances_flags.AddMachineTypeArgs(parser)
    deprecate_maintenance_policy = release_track in [base.ReleaseTrack.ALPHA]
    instances_flags.AddMaintenancePolicyArgs(parser,
                                             deprecate_maintenance_policy)
    instances_flags.AddNoRestartOnFailureArgs(parser)
    instances_flags.AddPreemptibleVmArgs(parser)
    instances_flags.AddServiceAccountAndScopeArgs(parser, False)
    instances_flags.AddTagsArgs(parser)
    instances_flags.AddCustomMachineTypeArgs(parser)
    instances_flags.AddImageArgs(parser)
    instances_flags.AddNetworkArgs(parser)
    if support_shielded_vms:
        instances_flags.AddShieldedVMConfigArgs(parser)
    labels_util.AddCreateLabelsFlags(parser)
    if support_network_tier:
        instances_flags.AddNetworkTierArgs(parser, instance=True)
    if support_sole_tenancy:
        sole_tenancy_flags.AddNodeAffinityFlagToParser(parser)

    flags.AddRegionFlag(parser,
                        resource_type='subnetwork',
                        operation_type='attach')

    parser.add_argument(
        '--description',
        help='Specifies a textual description for the instance template.')

    Create.InstanceTemplateArg = (
        instance_templates_flags.MakeInstanceTemplateArg())
    Create.InstanceTemplateArg.AddArgument(parser, operation_type='create')
    if support_source_instance:
        instance_templates_flags.MakeSourceInstanceArg().AddArgument(parser)
        parser.add_argument(
            '--configure-disk',
            type=arg_parsers.ArgDict(spec={
                'auto-delete': arg_parsers.ArgBoolean(),
                'device-name': str,
                'instantiate-from': str,
                'custom-image': str,
            }, ),
            metavar='PROPERTY=VALUE',
            action='append',
            help="""\
        This option has effect only when used with `--source-instance`. It
        allows you to override how the source-instance's disks are defined in
        the template.

        *auto-delete*::: If `true`, this persistent disk will be automatically
        deleted when the instance is deleted. However, if the disk is later
        detached from the instance, this option won't apply. If not provided,
        the setting is copied from the source instance. Allowed values of the
        flag are: `false`, `no`, `true`, and `yes`.

        *device-name*::: Name of the device.

        *instantiate-from*::: Specifies whether to include the disk and which
        image to use. Valid values are: {}

        *custom-image*::: The custom image to use if custom-image is specified
        for instantiate-from.
        """.format(', '.join(_INSTANTIATE_FROM_VALUES)),
        )

    parser.display_info.AddCacheUpdater(completers.InstanceTemplatesCompleter)
Exemplo n.º 5
0
def AddMutationArgs(parser, required=True):
    """Adds arguments for mutating commands.

  Args:
    parser: A given parser.
    required: bool, default is True.
  """
    parser.add_argument(
        '--description',
        metavar='DESCRIPTION',
        type=str,
        help='Description of the policy.',
    )
    parser.add_argument(
        '--agent-rules',
        metavar=('type=TYPE,version=VERSION,package-state=PACKAGE-STATE,'
                 'enable-autoupgrade=ENABLE-AUTOUPGRADE'),
        action='store',
        required=required,
        type=arg_parsers.ArgList(
            custom_delim_char=';',
            min_length=1,
            element_type=arg_parsers.ArgDict(spec={
                'type':
                ArgEnum('type',
                        list(agent_policy.OpsAgentPolicy.AgentRule.Type)),
                'version':
                str,
                'package-state':
                ArgEnum(
                    'package-state',
                    list(agent_policy.OpsAgentPolicy.AgentRule.PackageState)),
                'enable-autoupgrade':
                arg_parsers.ArgBoolean(),
            },
                                             required_keys=['type']),
        ),
        help="""\
      A non-empty list of agent rules to be enforced by the policy.

      This flag must be quoted. Items in the list are separated by ";". Each
      item in the list is a <key, value> map that represents a logging or
      metrics agent. The allowed values of the key are as follows.

      *type*::: Type of agent to manage.

      *Required*. Allowed values: ``logging'', ``metrics'' and ``ops-agent''.
      Use ``logging'' for the Logging Agent
      (https://cloud.google.com/logging/docs/agent). Use ``metrics'' for the
      Monitoring Agent (https://cloud.google.com/monitoring/agent). Use
      ``ops-agent'' for the Ops Agent
      (https://cloud.google.com/stackdriver/docs/solutions/ops-agent). The Ops
      Agent has both a logging module and a metrics module already. So other
      types of agents are not allowed when there is an agent with type
      ``ops-agent''. See
      https://cloud.google.com/stackdriver/docs/solutions/ops-agent#which_agent
      for which agent to use.

      *version*::: Version of the agent to install.

      Optional. Default to ``version=current-major''. The allowed values and
      formats are as follows.

      *version=latest*::::

      With this setting, the latest version of the agent is installed at the
      time when the policy is applied to an instance.

      If multiple instances are created at different times but they all fall
      into the instance filter rules of an existing policy, they may end up with
      different versions of the agent, depending on what the latest version of
      the agent is at the policy application time (in this case the instance
      creation time). One way to avoid this is to set
      ``enable-autoupgrade=true''. This guarantees that the installed agents on
      all instances that are managed by this policy are always up to date and
      conform to the same version.

      While this ``version=latest'' setting makes it easier to keep the agent
      version up to date, this setting does come with a potential risk. When a
      new major version is released, the policy may install the latest version
      of the agent from that new major release, which may introduce breaking
      changes. For production environments, consider using the
      ```version=MAJOR_VERSION.*.*``` setting below for safer agent deployments.

      ```version=MAJOR_VERSION.*.*```::::

      With this setting, the latest version of agent from a specific major
      version is installed at the time when the policy is applied to an
      instance.

      If multiple instances are created at different times but they all fall
      into the instance filter rules of an existing policy, they may end up with
      different versions of the agent, depending on what the latest version of
      the agent is at the policy application time (in this case the instance
      creation time). One way to avoid this is to set
      ``enable-autoupgrade=true''. This guarantees that the installed agents on
      all instances that are managed by this policy are always up to date within
      that major version and conform to the same version.

      When a new major release is out, this setting ensures that only the latest
      version from the specified major version is installed, which avoids
      accidentally introducing breaking changes. This is recommended for
      production environments to ensure safer agent deployments.

      *version=current-major*::::

      With this setting, the version field is automatically set to
      ```version=MAJOR_VERSION.*.*```, where ``MAJOR_VERSION'' is the current
      latest major version released. Refer to the
      ```version=MAJOR_VERSION.*.*``` section for the expected behavior.

      *version=MAJOR_VERSION.MINOR_VERSION.PATCH_VERSION*::::

      With this setting, the specified exact version of agent is installed at
      the time when the policy is applied to an instance. ``enable-autoupgrade''
      must be false for this setting.

      This setting is not recommended since it prevents the policy from
      installing new versions of the agent that include bug fixes and other
      improvements.

      One limitation of this setting is that if the agent gets manually
      uninstalled from the instances after the policy gets applied, the policy
      can only ensure that the agent is re-installed. It is not able to restore
      the expected exact version of the agent.

      ```version=5.5.2-BUILD_NUMBER```::::

      Allowed for the metrics agent (``type=metrics'') only.

      With this setting, the specified exact build number of the deprecated
      5.5.2 metrics agent is installed at the time when the policy is applied
      to an instance. enable-autoupgrade must be false for this setting.

      This setting is deprecated and will be decommissioned along with the 5.5.2
      metrics agent on Apr 28, 2021
      (https://cloud.google.com/stackdriver/docs/deprecations/mon-agent).
      It is not recommended since it prevents the policy from installing new
      versions of the agent that include bug fixes and other improvements.

      One limitation of this setting is that if the agent gets manually
      uninstalled from the instances after the policy gets applied, the policy
      can only ensure that the agent is re-installed. It is not able to restore
      the expected exact version of the agent.

      *package-state*::: Desired package state of the agent.

      Optional. Default to ``package-state=installed''. The allowed values are
      as follows.

      *package-state=installed*::::

      With this setting, the policy will ensure the agent package is installed
      on the instances and the agent service is running.

      *package-state=removed*::::

      With this setting, the policy will ensure the agent package is removed
      from the instances, which stops the service from running.

      *enable-autoupgrade*::: Whether to enable autoupgrade of the agent.

      Optional. Default to ``enable-autoupgrade=true''. Allowed values: ``true''
      or ``false''. This has to be ``false'' if the agent version is set to a
      specific patch version in the format of
      ``version=MAJOR_VERSION.MINOR_VERSION.PATCH_VERSION''.
      """)
    parser.add_argument(
        '--os-types',
        metavar='short-name=SHORT-NAME,version=VERSION',
        action='store',
        required=required,
        type=arg_parsers.ArgList(
            custom_delim_char=';',
            min_length=1,
            element_type=arg_parsers.ArgDict(
                spec={
                    'short-name':
                    ArgEnum(
                        'short-name',
                        list(agent_policy.OpsAgentPolicy.Assignment.OsType.
                             OsShortName)),
                    'version':
                    str,
                },
                required_keys=['short-name', 'version']),
        ),
        help="""\
      A non-empty list of OS types to filter instances that the policy applies
      to.

      For Alpha, exactly one OS type needs to be specified. The support for
      multiple OS types will be added later for more flexibility. Each OS type
      contains the following fields.

      *short-name*::: Short name of the OS.

      *Required*. Allowed values: ``centos'', ``debian'', ``rhel'', ``sles'',
      ``sles_sap'', ``ubuntu''. This is typically the ``ID'' value in the
      ``/etc/os-release'' file in the OS.

      To inspect the exact OS short name of an instance, run:

        $ gcloud beta compute instances os-inventory describe INSTANCE_NAME

      *version*::: Version of the OS.

      *Required*. This is typically the ``VERSION_ID'' value in the
      ``/etc/os-release'' file in the OS.

      To inspect the exact OS version of an instance, run:

        $ gcloud beta compute instances os-inventory describe INSTANCE_NAME

      Sample values:

        OS Short Name      OS Version
        centos             8
        centos             7
        debian             10
        debian             9
        rhel               8.*
        rhel               7.*
        sles               12.*
        sles               15.*
        sles_sap           12.*
        sles_sap           15.*
        ubuntu             16.04
        ubuntu             18.04
        ubuntu             19.10
        ubuntu             20.04

      ```*``` can be used to match a prefix of the version:
      ```<VERSION_PREFIX>*``` matches any version that starts with
      ``<VERSION_PREFIX>''.
      """,
    )
def _CommonArgs(parser,
                release_track,
                support_source_instance,
                support_local_ssd_size=False,
                support_kms=False,
                support_multi_writer=False,
                support_mesh=False,
                support_host_error_timeout_seconds=False,
                support_numa_node_count=False,
                support_visible_core_count=False,
                support_disk_architecture=False,
                support_max_run_duration=False):
  """Adding arguments applicable for creating instance templates."""
  parser.display_info.AddFormat(instance_templates_flags.DEFAULT_LIST_FORMAT)
  metadata_utils.AddMetadataArgs(parser)
  instances_flags.AddDiskArgs(parser, enable_kms=support_kms)
  instances_flags.AddCreateDiskArgs(
      parser,
      enable_kms=support_kms,
      support_boot=True,
      support_multi_writer=support_multi_writer,
      support_disk_architecture=support_disk_architecture)
  if support_local_ssd_size:
    instances_flags.AddLocalSsdArgsWithSize(parser)
  else:
    instances_flags.AddLocalSsdArgs(parser)
  instances_flags.AddCanIpForwardArgs(parser)
  instances_flags.AddAddressArgs(parser, instances=False)
  instances_flags.AddAcceleratorArgs(parser)
  instances_flags.AddMachineTypeArgs(parser)
  deprecate_maintenance_policy = release_track in [base.ReleaseTrack.ALPHA]
  instances_flags.AddMaintenancePolicyArgs(parser, deprecate_maintenance_policy)
  instances_flags.AddNoRestartOnFailureArgs(parser)
  instances_flags.AddPreemptibleVmArgs(parser)
  instances_flags.AddServiceAccountAndScopeArgs(parser, False)
  instances_flags.AddTagsArgs(parser)
  instances_flags.AddCustomMachineTypeArgs(parser)
  instances_flags.AddImageArgs(parser)
  instances_flags.AddNetworkArgs(parser)
  instances_flags.AddShieldedInstanceConfigArgs(parser)
  labels_util.AddCreateLabelsFlags(parser)
  instances_flags.AddNetworkTierArgs(parser, instance=True)
  instances_flags.AddPrivateNetworkIpArgs(parser)
  instances_flags.AddMinNodeCpuArg(parser)
  instances_flags.AddNestedVirtualizationArgs(parser)
  instances_flags.AddThreadsPerCoreArgs(parser)
  instances_flags.AddEnableUefiNetworkingArgs(parser)
  instances_flags.AddResourceManagerTagsArgs(parser)
  if support_numa_node_count:
    instances_flags.AddNumaNodeCountArgs(parser)
  instances_flags.AddStackTypeArgs(parser)
  instances_flags.AddIpv6NetworkTierArgs(parser)
  maintenance_flags.AddResourcePoliciesArgs(parser, 'added to',
                                            'instance-template')
  instances_flags.AddProvisioningModelVmArgs(parser)
  instances_flags.AddInstanceTerminationActionVmArgs(parser)

  if support_max_run_duration:
    instances_flags.AddMaxRunDurationVmArgs(parser)

  instance_templates_flags.AddServiceProxyConfigArgs(
      parser, release_track=release_track)
  if support_mesh:
    instance_templates_flags.AddMeshArgs(parser)

  sole_tenancy_flags.AddNodeAffinityFlagToParser(parser)

  instances_flags.AddLocationHintArg(parser)

  if support_visible_core_count:
    instances_flags.AddVisibleCoreCountArgs(parser)

  instances_flags.AddNetworkPerformanceConfigsArgs(parser)

  flags.AddRegionFlag(
      parser, resource_type='subnetwork', operation_type='attach')

  parser.add_argument(
      '--description',
      help='Specifies a textual description for the instance template.')

  Create.InstanceTemplateArg = (
      instance_templates_flags.MakeInstanceTemplateArg())
  Create.InstanceTemplateArg.AddArgument(parser, operation_type='create')
  if support_source_instance:
    instance_templates_flags.MakeSourceInstanceArg().AddArgument(parser)
    parser.add_argument(
        '--configure-disk',
        type=arg_parsers.ArgDict(
            spec={
                'auto-delete': arg_parsers.ArgBoolean(),
                'device-name': str,
                'instantiate-from': str,
                'custom-image': str,
            },),
        metavar='PROPERTY=VALUE',
        action='append',
        help="""\
        This option has effect only when used with `--source-instance`. It
        allows you to override how the source-instance's disks are defined in
        the template.

        *auto-delete*::: If `true`, this persistent disk will be automatically
        deleted when the instance is deleted. However, if the disk is later
        detached from the instance, this option won't apply. If not provided,
        the setting is copied from the source instance. Allowed values of the
        flag are: `false`, `no`, `true`, and `yes`.

        *device-name*::: Name of the device.

        *instantiate-from*::: Specifies whether to include the disk and which
        image to use. Valid values are: {}

        *custom-image*::: The custom image to use if custom-image is specified
        for instantiate-from.
        """.format(', '.join(_INSTANTIATE_FROM_VALUES)),
    )

  instances_flags.AddReservationAffinityGroup(
      parser,
      group_text="""\
Specifies the reservation for instances created from this template.
""",
      affinity_text="""\
The type of reservation for instances created from this template.
""")

  parser.display_info.AddCacheUpdater(completers.InstanceTemplatesCompleter)
  if support_host_error_timeout_seconds:
    instances_flags.AddHostErrorTimeoutSecondsArgs(parser)