def Args(parser):
    parser.display_info.AddFormat(instance_templates_flags.DEFAULT_LIST_FORMAT)
    metadata_utils.AddMetadataArgs(parser)
    instances_flags.AddDiskArgs(parser)
    instances_flags.AddCreateDiskArgs(parser)
    instances_flags.AddLocalSsdArgsWithSize(parser)
    instances_flags.AddCanIpForwardArgs(parser)
    instances_flags.AddAddressArgs(
        parser, multiple_network_interface_cards=False, instances=False)
    instances_flags.AddMachineTypeArgs(parser)
    instances_flags.AddMaintenancePolicyArgs(parser, deprecate=True)
    instances_flags.AddNoRestartOnFailureArgs(parser)
    instances_flags.AddPreemptibleVmArgs(parser)
    instances_flags.AddServiceAccountAndScopeArgs(parser, False)
    instances_flags.AddTagsArgs(parser)
    instances_flags.AddCustomMachineTypeArgs(parser)
    instances_flags.AddNetworkArgs(parser)
    instances_flags.AddDockerArgs(parser)
    instances_flags.AddMinCpuPlatformArgs(parser, base.ReleaseTrack.ALPHA)
    instances_flags.AddNetworkTierArgs(parser, instance=True)

    flags.AddRegionFlag(
        parser,
        resource_type='instance template',
        operation_type='create')

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

    CreateFromContainer.InstanceTemplateArg = (
        instance_templates_flags.MakeInstanceTemplateArg())
    CreateFromContainer.InstanceTemplateArg.AddArgument(
        parser, operation_type='create')
    def Args(parser):
        metadata_utils.AddMetadataArgs(parser)
        instances_flags.AddDiskArgs(parser)
        instances_flags.AddCreateDiskArgs(parser)
        instances_flags.AddLocalSsdArgs(parser)
        instances_flags.AddCanIpForwardArgs(parser)
        instances_flags.AddAddressArgs(parser, instances=False)
        instances_flags.AddMachineTypeArgs(parser)
        instances_flags.AddMaintenancePolicyArgs(parser)
        instances_flags.AddNoRestartOnFailureArgs(parser)
        instances_flags.AddPreemptibleVmArgs(parser)
        instances_flags.AddScopeArgs(parser)
        instances_flags.AddTagsArgs(parser)
        instances_flags.AddCustomMachineTypeArgs(parser)
        instances_flags.AddNetworkArgs(parser)
        instances_flags.AddDockerArgs(parser)

        flags.AddRegionFlag(parser,
                            resource_type='instance template',
                            operation_type='create')

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

        instance_templates_flags.INSTANCE_TEMPLATE_ARG.AddArgument(parser)
    def Args(cls, parser):
        compute_holder = cls._GetComputeApiHolder(no_http=True)
        messages = compute_holder.client.messages

        instances_flags.AddCanIpForwardArgs(parser)
        instances_flags.AddMachineTypeArgs(parser)
        instances_flags.AddNoRestartOnFailureArgs(parser)
        instances_flags.AddTagsArgs(parser)
        instances_flags.AddCustomMachineTypeArgs(parser)
        instances_flags.AddNetworkArgs(parser)
        instances_flags.AddPrivateNetworkIpArgs(parser)
        instances_flags.AddDeletionProtectionFlag(parser)
        instances_flags.AddNetworkTierArgs(parser, instance=True)
        instances_flags.AddNoAddressArg(parser)
        labels_util.AddCreateLabelsFlags(parser)
        daisy_utils.AddCommonDaisyArgs(parser, operation='an import')
        daisy_utils.AddExtraCommonDaisyArgs(parser)
        instances_flags.INSTANCES_ARG_FOR_IMPORT.AddArgument(
            parser, operation_type='import')
        daisy_utils.AddOVFSourceUriArg(parser)
        parser.add_argument(
            '--os',
            required=False,
            choices=sorted(cls._OS_CHOICES),
            help='Specifies the OS of the image being imported.')
        daisy_utils.AddByolArg(parser)

        if cls.ReleaseTrack() != base.ReleaseTrack.GA:
            image_utils.AddGuestOsFeaturesArgForImport(parser, messages)

        parser.add_argument(
            '--description',
            help='Specifies a textual description of the VM instances.')
        daisy_utils.AddGuestEnvironmentArg(parser)
        parser.display_info.AddCacheUpdater(completers.InstancesCompleter)
        sole_tenancy_flags.AddNodeAffinityFlagToParser(parser)
        parser.add_argument('--hostname',
                            help="""\
      Specify the hostname of the VM instance to be imported. The specified
      hostname must be RFC1035 compliant. If hostname is not specified, the
      default hostname is [INSTANCE_NAME].c.[PROJECT_ID].internal when using
      the global DNS, and [INSTANCE_NAME].[ZONE].c.[PROJECT_ID].internal
      when using zonal DNS.
      """)
        daisy_utils.AddComputeServiceAccountArg(
            parser, 'instance import',
            daisy_utils.IMPORT_ROLES_FOR_COMPUTE_SERVICE_ACCOUNT)
        instances_flags.AddServiceAccountAndScopeArgs(
            parser,
            False,
            extra_scopes_help=(
                'However, if neither `--scopes` nor `--no-scopes` are '
                'specified and the project has no default service '
                'account, then the VM instance is imported with no '
                'scopes. Note that the level of access that a service '
                'account has is determined by a combination of access '
                'scopes and IAM roles so you must configure both '
                'access scopes and IAM roles for the service account '
                'to work properly.'),
            operation='Import')
def _Args(parser, release_track):
  """Add flags shared by all release tracks."""
  parser.display_info.AddFormat(instance_templates_flags.DEFAULT_LIST_FORMAT)
  metadata_utils.AddMetadataArgs(parser)
  instances_flags.AddDiskArgs(parser)
  instances_flags.AddCreateDiskArgs(parser)
  instances_flags.AddLocalSsdArgsWithSize(parser)
  instances_flags.AddCanIpForwardArgs(parser)
  instances_flags.AddAddressArgs(parser, instances=False)
  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.AddNetworkArgs(parser)
  instances_flags.AddKonletArgs(parser)
  instances_flags.AddImageArgs(parser)
  instances_flags.AddMinCpuPlatformArgs(parser, base.ReleaseTrack.ALPHA)

  flags.AddRegionFlag(
      parser,
      resource_type='instance template',
      operation_type='create')

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

  CreateWithContainer.InstanceTemplateArg = (
      instance_templates_flags.MakeInstanceTemplateArg())
  CreateWithContainer.InstanceTemplateArg.AddArgument(
      parser, operation_type='create')
    def Args(parser):
        """Register parser args."""
        metadata_utils.AddMetadataArgs(parser)
        instances_flags.AddDiskArgs(parser, True)
        instances_flags.AddCreateDiskArgs(parser)
        instances_flags.AddLocalSsdArgsWithSize(parser)
        instances_flags.AddCanIpForwardArgs(parser)
        instances_flags.AddAddressArgs(parser, instances=True)
        instances_flags.AddMachineTypeArgs(parser)
        instances_flags.AddMaintenancePolicyArgs(parser)
        instances_flags.AddNoRestartOnFailureArgs(parser)
        instances_flags.AddPreemptibleVmArgs(parser)
        instances_flags.AddServiceAccountAndScopeArgs(parser, False)
        instances_flags.AddTagsArgs(parser)
        instances_flags.AddCustomMachineTypeArgs(parser)
        instances_flags.AddExtendedMachineTypeArgs(parser)
        instances_flags.AddNetworkArgs(parser)
        instances_flags.AddPrivateNetworkIpArgs(parser)
        instances_flags.AddDockerArgs(parser)
        instances_flags.AddPublicDnsArgs(parser, instance=True)
        instances_flags.AddNetworkTierArgs(parser, instance=True)
        instances_flags.AddMinCpuPlatformArgs(parser)
        labels_util.AddCreateLabelsFlags(parser)

        parser.add_argument(
            '--description',
            help='Specifies a textual description of the instances.')

        instances_flags.INSTANCES_ARG.AddArgument(parser)
  def Args(parser):
    metadata_utils.AddMetadataArgs(parser)
    instances_flags.AddDiskArgs(parser)
    instances_flags.AddCreateDiskArgs(parser)
    instances_flags.AddLocalSsdArgsWithSize(parser)
    instances_flags.AddCanIpForwardArgs(parser)
    instances_flags.AddAddressArgs(parser, instances=False)
    instances_flags.AddMachineTypeArgs(parser)
    instances_flags.AddMaintenancePolicyArgs(parser)
    instances_flags.AddNoRestartOnFailureArgs(parser)
    instances_flags.AddPreemptibleVmArgs(parser)
    instances_flags.AddServiceAccountAndScopeArgs(parser, False)
    instances_flags.AddTagsArgs(parser)
    instances_flags.AddCustomMachineTypeArgs(parser)
    instances_flags.AddExtendedMachineTypeArgs(parser)
    instances_flags.AddNetworkArgs(parser)
    instances_flags.AddDockerArgs(parser)
    instances_flags.AddMinCpuPlatformArgs(parser)

    flags.AddRegionFlag(
        parser,
        resource_type='instance template',
        operation_type='create')

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

    CreateFromContainer.InstanceTemplateArg = (
        instance_templates_flags.MakeInstanceTemplateArg())
    CreateFromContainer.InstanceTemplateArg.AddArgument(parser)
Exemple #7
0
def _CommonArgs(parser, multiple_network_interface_cards, release_track):
    """Common arguments used in Alpha, Beta, and GA."""
    metadata_utils.AddMetadataArgs(parser)
    instances_flags.AddDiskArgs(parser)
    if release_track in [base.ReleaseTrack.ALPHA]:
        instances_flags.AddCreateDiskArgs(parser)
    instances_flags.AddLocalSsdArgs(parser)
    instances_flags.AddCanIpForwardArgs(parser)
    instances_flags.AddAddressArgs(
        parser,
        instances=False,
        multiple_network_interface_cards=multiple_network_interface_cards)
    instances_flags.AddMachineTypeArgs(parser)
    instances_flags.AddMaintenancePolicyArgs(parser)
    instances_flags.AddNoRestartOnFailureArgs(parser)
    instances_flags.AddPreemptibleVmArgs(parser)
    instances_flags.AddScopeArgs(parser)
    instances_flags.AddTagsArgs(parser)
    instances_flags.AddCustomMachineTypeArgs(parser)
    instances_flags.AddImageArgs(parser)
    instances_flags.AddNetworkArgs(parser)

    flags.AddRegionFlag(parser,
                        resource_type='instance template',
                        operation_type='create')

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

    instance_templates_flags.INSTANCE_TEMPLATE_ARG.AddArgument(parser)
Exemple #8
0
def _Args(parser, deprecate_maintenance_policy=False):
  """Add flags shared by all release tracks."""
  parser.display_info.AddFormat(instances_flags.DEFAULT_LIST_FORMAT)
  metadata_utils.AddMetadataArgs(parser)
  instances_flags.AddDiskArgs(parser, True)
  instances_flags.AddCreateDiskArgs(parser)
  instances_flags.AddCanIpForwardArgs(parser)
  instances_flags.AddAddressArgs(parser, instances=True)
  instances_flags.AddMachineTypeArgs(parser)
  instances_flags.AddMaintenancePolicyArgs(
      parser, deprecate=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.AddNetworkArgs(parser)
  instances_flags.AddPrivateNetworkIpArgs(parser)
  instances_flags.AddKonletArgs(parser)
  instances_flags.AddPublicDnsArgs(parser, instance=True)
  instances_flags.AddPublicPtrArgs(parser, instance=True)
  instances_flags.AddImageArgs(parser)
  labels_util.AddCreateLabelsFlags(parser)

  parser.add_argument(
      '--description',
      help='Specifies a textual description of the instances.')

  instances_flags.INSTANCES_ARG.AddArgument(parser, operation_type='create')

  CreateWithContainer.SOURCE_INSTANCE_TEMPLATE = (
      instances_flags.MakeSourceInstanceTemplateArg())
  CreateWithContainer.SOURCE_INSTANCE_TEMPLATE.AddArgument(parser)
  parser.display_info.AddCacheUpdater(completers.InstancesCompleter)
Exemple #9
0
    def Args(parser):
        """Register parser args."""
        parser.display_info.AddFormat(instances_flags.DEFAULT_LIST_FORMAT)
        metadata_utils.AddMetadataArgs(parser)
        instances_flags.AddDiskArgs(parser, True)
        instances_flags.AddCreateDiskArgs(parser)
        instances_flags.AddLocalSsdArgsWithSize(parser)
        instances_flags.AddCanIpForwardArgs(parser)
        instances_flags.AddAddressArgs(parser, instances=True)
        instances_flags.AddMachineTypeArgs(parser)
        instances_flags.AddMaintenancePolicyArgs(parser)
        instances_flags.AddNoRestartOnFailureArgs(parser)
        instances_flags.AddPreemptibleVmArgs(parser)
        instances_flags.AddServiceAccountAndScopeArgs(parser, False)
        instances_flags.AddTagsArgs(parser)
        instances_flags.AddCustomMachineTypeArgs(parser)
        instances_flags.AddNetworkArgs(parser)
        instances_flags.AddPrivateNetworkIpArgs(parser)
        instances_flags.AddDockerArgs(parser)
        instances_flags.AddPublicDnsArgs(parser, instance=True)
        instances_flags.AddNetworkTierArgs(parser, instance=True)
        instances_flags.AddMinCpuPlatformArgs(parser, base.ReleaseTrack.ALPHA)
        labels_util.AddCreateLabelsFlags(parser)

        parser.add_argument(
            '--description',
            help='Specifies a textual description of the instances.')

        instances_flags.INSTANCES_ARG.AddArgument(parser,
                                                  operation_type='create')

        CreateFromContainer.SOURCE_INSTANCE_TEMPLATE = (
            instances_flags.MakeSourceInstanceTemplateArg())
        CreateFromContainer.SOURCE_INSTANCE_TEMPLATE.AddArgument(parser)
Exemple #10
0
def _CommonArgs(parser, multiple_network_interface_cards,
                release_track):
  """Register parser args common to all tracks."""
  metadata_utils.AddMetadataArgs(parser)
  instances_flags.AddDiskArgs(parser)
  if release_track in [base.ReleaseTrack.ALPHA]:
    instances_flags.AddCreateDiskArgs(parser)
  instances_flags.AddLocalSsdArgs(parser)
  instances_flags.AddCanIpForwardArgs(parser)
  instances_flags.AddAddressArgs(
      parser, instances=True,
      multiple_network_interface_cards=multiple_network_interface_cards)
  instances_flags.AddMachineTypeArgs(parser)
  instances_flags.AddMaintenancePolicyArgs(parser)
  instances_flags.AddNoRestartOnFailureArgs(parser)
  instances_flags.AddPreemptibleVmArgs(parser)
  instances_flags.AddScopeArgs(parser)
  instances_flags.AddTagsArgs(parser)
  instances_flags.AddCustomMachineTypeArgs(parser)
  instances_flags.AddNetworkArgs(parser)
  instances_flags.AddPrivateNetworkIpArgs(parser)
  instances_flags.AddImageArgs(parser)

  parser.add_argument(
      '--description',
      help='Specifies a textual description of the instances.')

  instances_flags.INSTANCES_ARG.AddArgument(parser)

  csek_utils.AddCsekKeyArgs(parser)
def _Args(parser,
          release_track,
          container_mount_enabled=False,
          enable_guest_accelerators=False,
          support_multi_writer=True):
    """Add flags shared by all release tracks."""
    parser.display_info.AddFormat(instance_templates_flags.DEFAULT_LIST_FORMAT)
    metadata_utils.AddMetadataArgs(parser)
    instances_flags.AddDiskArgs(
        parser, container_mount_enabled=container_mount_enabled)
    instances_flags.AddCreateDiskArgs(
        parser,
        container_mount_enabled=container_mount_enabled,
        support_multi_writer=support_multi_writer)
    if release_track == base.ReleaseTrack.ALPHA:
        instances_flags.AddLocalSsdArgsWithSize(parser)
    elif release_track == base.ReleaseTrack.BETA:
        instances_flags.AddLocalSsdArgs(parser)
    instances_flags.AddCanIpForwardArgs(parser)
    instances_flags.AddContainerMountDiskFlag(parser)
    instances_flags.AddAddressArgs(parser, instances=False, containers=True)
    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.AddNetworkArgs(parser)
    instances_flags.AddKonletArgs(parser)
    instances_flags.AddImageArgs(parser)
    instances_flags.AddMinCpuPlatformArgs(parser, release_track)
    instances_flags.AddNetworkTierArgs(parser, instance=True)
    instances_flags.AddConfidentialComputeArgs(parser)
    instances_flags.AddShieldedInstanceConfigArgs(parser)
    labels_util.AddCreateLabelsFlags(parser)
    instances_flags.AddPrivateNetworkIpArgs(parser)

    if enable_guest_accelerators:
        instances_flags.AddAcceleratorArgs(parser)

    flags.AddRegionFlag(parser,
                        resource_type='instance template',
                        operation_type='create')

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

    CreateWithContainer.InstanceTemplateArg = (
        instance_templates_flags.MakeInstanceTemplateArg())
    CreateWithContainer.InstanceTemplateArg.AddArgument(
        parser, operation_type='create')

    parser.display_info.AddCacheUpdater(completers.InstanceTemplatesCompleter)
Exemple #12
0
def _CommonArgs(parser,
                enable_regional=False,
                enable_kms=False,
                enable_snapshots=False,
                deprecate_maintenance_policy=False,
                supports_display_device=False):
    """Register parser args common to all tracks."""
    metadata_utils.AddMetadataArgs(parser)
    instances_flags.AddDiskArgs(parser, enable_regional, enable_kms=enable_kms)
    instances_flags.AddCreateDiskArgs(parser,
                                      enable_kms=enable_kms,
                                      enable_snapshots=enable_snapshots)
    instances_flags.AddCanIpForwardArgs(parser)
    instances_flags.AddAddressArgs(parser, instances=True)
    instances_flags.AddAcceleratorArgs(parser)
    instances_flags.AddMachineTypeArgs(parser)
    instances_flags.AddMaintenancePolicyArgs(
        parser, deprecate=deprecate_maintenance_policy)
    instances_flags.AddNoRestartOnFailureArgs(parser)
    instances_flags.AddPreemptibleVmArgs(parser)
    instances_flags.AddServiceAccountAndScopeArgs(
        parser,
        False,
        extra_scopes_help='However, if neither `--scopes` nor `--no-scopes` are '
        'specified and the project has no default service '
        'account, then the instance will be created with no '
        'scopes.')
    instances_flags.AddTagsArgs(parser)
    instances_flags.AddCustomMachineTypeArgs(parser)
    instances_flags.AddNetworkArgs(parser)
    instances_flags.AddPrivateNetworkIpArgs(parser)
    instances_flags.AddHostnameArg(parser)
    instances_flags.AddImageArgs(parser, enable_snapshots=enable_snapshots)
    instances_flags.AddDeletionProtectionFlag(parser)
    instances_flags.AddPublicPtrArgs(parser, instance=True)
    instances_flags.AddNetworkTierArgs(parser, instance=True)
    if supports_display_device:
        instances_flags.AddDisplayDeviceArg(parser)

    sole_tenancy_flags.AddNodeAffinityFlagToParser(parser)

    labels_util.AddCreateLabelsFlags(parser)

    parser.add_argument(
        '--description',
        help='Specifies a textual description of the instances.')

    instances_flags.INSTANCES_ARG_FOR_CREATE.AddArgument(
        parser, operation_type='create')

    csek_utils.AddCsekKeyArgs(parser)

    base.ASYNC_FLAG.AddToParser(parser)
    parser.display_info.AddFormat(
        resource_registry.RESOURCE_REGISTRY['compute.instances'].list_format)
    parser.display_info.AddCacheUpdater(completers.InstancesCompleter)
Exemple #13
0
def _CommonArgs(parser,
                release_track,
                support_public_dns,
                support_public_ptr,
                support_network_tier,
                enable_regional=False,
                support_local_ssd_size=False,
                enable_kms=False):
  """Register parser args common to all tracks."""
  metadata_utils.AddMetadataArgs(parser)
  instances_flags.AddDiskArgs(parser, enable_regional, enable_kms=enable_kms)
  if release_track in [base.ReleaseTrack.ALPHA]:
    instances_flags.AddCreateDiskArgs(parser, enable_kms=enable_kms)
  if support_local_ssd_size:
    instances_flags.AddLocalSsdArgsWithSize(parser)
  else:
    instances_flags.AddLocalSsdArgs(parser)
  instances_flags.AddCanIpForwardArgs(parser)
  instances_flags.AddAddressArgs(
      parser, instances=True,
      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.AddNetworkArgs(parser)
  instances_flags.AddPrivateNetworkIpArgs(parser)
  instances_flags.AddImageArgs(parser)
  instances_flags.AddDeletionProtectionFlag(parser)
  if support_public_dns:
    instances_flags.AddPublicDnsArgs(parser, instance=True)
  if support_public_ptr:
    instances_flags.AddPublicPtrArgs(parser, instance=True)
  if support_network_tier:
    instances_flags.AddNetworkTierArgs(parser, instance=True)

  labels_util.AddCreateLabelsFlags(parser)
  instances_flags.AddMinCpuPlatformArgs(parser, release_track)

  parser.add_argument(
      '--description',
      help='Specifies a textual description of the instances.')

  instances_flags.INSTANCES_ARG_FOR_CREATE.AddArgument(
      parser, operation_type='create')

  csek_utils.AddCsekKeyArgs(parser)

  base.ASYNC_FLAG.AddToParser(parser)
  parser.display_info.AddFormat(
      resource_registry.RESOURCE_REGISTRY['compute.instances'].list_format)
def _CommonArgs(parser,
                multiple_network_interface_cards,
                release_track,
                support_alias_ip_ranges,
                support_public_dns,
                support_network_tier,
                enable_regional=False,
                support_local_ssd_size=False):
    """Register parser args common to all tracks."""
    metadata_utils.AddMetadataArgs(parser)
    instances_flags.AddDiskArgs(parser, enable_regional)
    if release_track in [base.ReleaseTrack.ALPHA]:
        instances_flags.AddCreateDiskArgs(parser)
    if release_track in [base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA]:
        instances_flags.AddExtendedMachineTypeArgs(parser)
    if support_local_ssd_size:
        instances_flags.AddLocalSsdArgsWithSize(parser)
    else:
        instances_flags.AddLocalSsdArgs(parser)
    instances_flags.AddCanIpForwardArgs(parser)
    instances_flags.AddAddressArgs(
        parser,
        instances=True,
        multiple_network_interface_cards=multiple_network_interface_cards,
        support_alias_ip_ranges=support_alias_ip_ranges,
        support_network_tier=support_network_tier)
    instances_flags.AddAcceleratorArgs(parser)
    instances_flags.AddMachineTypeArgs(parser)
    instances_flags.AddMaintenancePolicyArgs(parser)
    instances_flags.AddNoRestartOnFailureArgs(parser)
    instances_flags.AddPreemptibleVmArgs(parser)
    instances_flags.AddServiceAccountAndScopeArgs(parser, False)
    instances_flags.AddTagsArgs(parser)
    instances_flags.AddCustomMachineTypeArgs(parser)
    instances_flags.AddNetworkArgs(parser)
    instances_flags.AddPrivateNetworkIpArgs(parser)
    instances_flags.AddImageArgs(parser)
    if support_public_dns:
        instances_flags.AddPublicDnsArgs(parser, instance=True)
    if support_network_tier:
        instances_flags.AddNetworkTierArgs(parser, instance=True)

    labels_util.AddCreateLabelsFlags(parser)

    parser.add_argument(
        '--description',
        help='Specifies a textual description of the instances.')

    instances_flags.INSTANCES_ARG_FOR_CREATE.AddArgument(
        parser, operation_type='create')

    csek_utils.AddCsekKeyArgs(parser)

    parser.display_info.AddFormat(
        resource_registry.RESOURCE_REGISTRY['compute.instances'].list_format)
Exemple #15
0
def _CommonArgs(parser,
                release_track,
                support_source_instance,
                support_create_disk=False,
                support_network_tier=False,
                support_local_ssd_size=False,
                support_labels=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)
    if support_create_disk:
        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_network_tier:
        instances_flags.AddNetworkTierArgs(parser, instance=True)

    if support_labels:
        labels_util.AddCreateLabelsFlags(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)
Exemple #16
0
    def Args(cls, parser):
        instances_flags.AddCanIpForwardArgs(parser)
        instances_flags.AddMachineTypeArgs(parser)
        instances_flags.AddNoRestartOnFailureArgs(parser)
        instances_flags.AddTagsArgs(parser)
        instances_flags.AddCustomMachineTypeArgs(parser)
        instances_flags.AddNetworkArgs(parser)
        instances_flags.AddPrivateNetworkIpArgs(parser)
        instances_flags.AddDeletionProtectionFlag(parser)
        instances_flags.AddNetworkTierArgs(parser, instance=True)
        labels_util.AddCreateLabelsFlags(parser)
        daisy_utils.AddCommonDaisyArgs(parser, add_log_location=False)
        daisy_utils.AddExtraCommonDaisyArgs(parser)

        instances_flags.INSTANCES_ARG_FOR_IMPORT.AddArgument(
            parser, operation_type='import')

        parser.add_argument(
            '--source-uri',
            required=True,
            help=('Google Cloud Storage path to one of:\n  OVF descriptor\n  '
                  'OVA file\n  Directory with OVF package'))

        parser.add_argument(
            '--os',
            required=False,
            choices=sorted(os_choices.OS_CHOICES_INSTANCE_IMPORT_BETA),
            help='Specifies the OS of the image being imported.')

        parser.add_argument(
            '--description',
            help='Specifies a textual description of the instances.')

        parser.add_argument(
            '--guest-environment',
            action='store_true',
            default=True,
            help='Google Guest Environment will be installed on the instance.')

        parser.display_info.AddCacheUpdater(completers.InstancesCompleter)

        sole_tenancy_flags.AddNodeAffinityFlagToParser(parser)

        parser.add_argument('--hostname',
                            help="""\
      Specify the hostname of the instance to be imported. The specified
      hostname must be RFC1035 compliant. If hostname is not specified, the
      default hostname is [INSTANCE_NAME].c.[PROJECT_ID].internal when using
      the global DNS, and [INSTANCE_NAME].[ZONE].c.[PROJECT_ID].internal
      when using zonal DNS.
      """)
Exemple #17
0
def _CommonArgs(parser,
                multiple_network_interface_cards,
                release_track,
                support_alias_ip_ranges,
                support_network_tier,
                support_local_ssd_size=False):
  """Common arguments used in Alpha, Beta, and GA."""
  parser.display_info.AddFormat(instance_templates_flags.DEFAULT_LIST_FORMAT)
  metadata_utils.AddMetadataArgs(parser)
  instances_flags.AddDiskArgs(parser)
  if release_track in [base.ReleaseTrack.ALPHA]:
    instances_flags.AddCreateDiskArgs(parser)
    instances_flags.AddExtendedMachineTypeArgs(parser)
  if release_track in [base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA]:
    instances_flags.AddAcceleratorArgs(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,
      multiple_network_interface_cards=multiple_network_interface_cards,
      support_alias_ip_ranges=support_alias_ip_ranges,
      support_network_tier=support_network_tier)
  instances_flags.AddMachineTypeArgs(parser)
  instances_flags.AddMaintenancePolicyArgs(parser)
  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_network_tier:
    instances_flags.AddNetworkTierArgs(parser, instance=True)

  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)
def _Args(parser,
          deprecate_maintenance_policy=False,
          container_mount_enabled=False,
          support_multi_writer=True):
  """Add flags shared by all release tracks."""
  parser.display_info.AddFormat(instances_flags.DEFAULT_LIST_FORMAT)
  metadata_utils.AddMetadataArgs(parser)
  instances_flags.AddDiskArgs(
      parser, True, container_mount_enabled=container_mount_enabled)
  instances_flags.AddCreateDiskArgs(
      parser,
      container_mount_enabled=container_mount_enabled,
      support_multi_writer=support_multi_writer)
  instances_flags.AddCanIpForwardArgs(parser)
  instances_flags.AddContainerMountDiskFlag(parser)
  instances_flags.AddAddressArgs(parser, instances=True, containers=True)
  instances_flags.AddAcceleratorArgs(parser)
  instances_flags.AddMachineTypeArgs(parser)
  instances_flags.AddMaintenancePolicyArgs(
      parser, deprecate=deprecate_maintenance_policy)
  instances_flags.AddNoRestartOnFailureArgs(parser)
  instances_flags.AddPreemptibleVmArgs(parser)
  instances_flags.AddProvisioningModelVmArgs(parser)
  instances_flags.AddInstanceTerminationActionVmArgs(parser)
  instances_flags.AddServiceAccountAndScopeArgs(parser, False)
  instances_flags.AddTagsArgs(parser)
  instances_flags.AddCustomMachineTypeArgs(parser)
  instances_flags.AddNetworkArgs(parser)
  instances_flags.AddPrivateNetworkIpArgs(parser)
  instances_flags.AddNetworkPerformanceConfigsArgs(parser)
  instances_flags.AddShieldedInstanceConfigArgs(
      parser=parser, for_container=True)
  instances_flags.AddKonletArgs(parser)
  instances_flags.AddPublicPtrArgs(parser, instance=True)
  instances_flags.AddImageArgs(parser)
  instances_flags.AddConfidentialComputeArgs(parser)
  instances_flags.AddNestedVirtualizationArgs(parser)
  instances_flags.AddThreadsPerCoreArgs(parser)
  labels_util.AddCreateLabelsFlags(parser)

  parser.add_argument(
      '--description', help='Specifies a textual description of the instances.')

  instances_flags.INSTANCES_ARG.AddArgument(parser, operation_type='create')

  CreateWithContainer.SOURCE_INSTANCE_TEMPLATE = (
      instances_flags.MakeSourceInstanceTemplateArg())
  CreateWithContainer.SOURCE_INSTANCE_TEMPLATE.AddArgument(parser)
  parser.display_info.AddCacheUpdater(completers.InstancesCompleter)
Exemple #19
0
def _CommonArgs(parser,
                multiple_network_interface_cards,
                release_track,
                support_alias_ip_ranges,
                support_public_dns,
                support_network_tier,
                enable_regional=False):
    """Register parser args common to all tracks."""
    metadata_utils.AddMetadataArgs(parser)
    instances_flags.AddDiskArgs(parser, enable_regional)
    if release_track in [base.ReleaseTrack.ALPHA]:
        instances_flags.AddCreateDiskArgs(parser)
        instances_flags.AddExtendedMachineTypeArgs(parser)
    if release_track in [base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA]:
        instances_flags.AddAcceleratorArgs(parser)
    instances_flags.AddLocalSsdArgs(parser)
    instances_flags.AddCanIpForwardArgs(parser)
    instances_flags.AddAddressArgs(
        parser,
        instances=True,
        multiple_network_interface_cards=multiple_network_interface_cards,
        support_alias_ip_ranges=support_alias_ip_ranges,
        support_network_tier=support_network_tier)
    instances_flags.AddMachineTypeArgs(parser)
    instances_flags.AddMaintenancePolicyArgs(parser)
    instances_flags.AddNoRestartOnFailureArgs(parser)
    instances_flags.AddPreemptibleVmArgs(parser)
    instances_flags.AddServiceAccountAndScopeArgs(parser, False)
    instances_flags.AddTagsArgs(parser)
    instances_flags.AddCustomMachineTypeArgs(parser)
    instances_flags.AddNetworkArgs(parser)
    instances_flags.AddPrivateNetworkIpArgs(parser)
    instances_flags.AddImageArgs(parser)
    if support_public_dns:
        instances_flags.AddPublicDnsArgs(parser, instance=True)
    if support_network_tier:
        instances_flags.AddNetworkTierArgs(parser, instance=True)

    parser.add_argument(
        '--description',
        help='Specifies a textual description of the instances.')

    instances_flags.INSTANCES_ARG.AddArgument(parser)

    csek_utils.AddCsekKeyArgs(parser)
    def Args(cls, parser):
        instances_flags.AddCanIpForwardArgs(parser)
        instances_flags.AddMachineTypeArgs(parser)
        instances_flags.AddNoRestartOnFailureArgs(parser)
        instances_flags.AddTagsArgs(parser)
        instances_flags.AddCustomMachineTypeArgs(parser)
        instances_flags.AddNetworkArgs(parser)
        instances_flags.AddPrivateNetworkIpArgs(parser)
        instances_flags.AddDeletionProtectionFlag(parser)
        instances_flags.AddNetworkTierArgs(parser, instance=True)
        labels_util.AddCreateLabelsFlags(parser)
        daisy_utils.AddCommonDaisyArgs(parser, add_log_location=False)

        instances_flags.INSTANCES_ARG_FOR_IMPORT.AddArgument(
            parser, operation_type='import')

        parser.add_argument(
            '--source-uri',
            required=True,
            help=('Google Cloud Storage path to one of:\n  OVF descriptor\n  '
                  'OVA file\n  Directory with OVF package'))

        parser.add_argument(
            '--os',
            required=True,
            choices=sorted(os_choices.OS_CHOICES_INSTANCE_IMPORT_ALPHA),
            help='Specifies the OS of the image being imported.')

        parser.add_argument(
            '--description',
            help='Specifies a textual description of the instances.')

        parser.add_argument(
            '--guest-environment',
            action='store_true',
            default=True,
            help='Google Guest Environment will be installed on the instance.')

        parser.display_info.AddCacheUpdater(completers.InstancesCompleter)

        sole_tenancy_flags.AddNodeAffinityFlagToParser(parser)
Exemple #21
0
    def Args(cls, parser):
        instances_flags.AddCanIpForwardArgs(parser)
        instances_flags.AddMachineTypeArgs(parser)
        instances_flags.AddNoRestartOnFailureArgs(parser)
        instances_flags.AddTagsArgs(parser)
        instances_flags.AddCustomMachineTypeArgs(parser)
        instances_flags.AddNetworkArgs(parser)
        instances_flags.AddPrivateNetworkIpArgs(parser)
        instances_flags.AddDeletionProtectionFlag(parser)
        instances_flags.AddNetworkTierArgs(parser, instance=True)
        instances_flags.AddNoAddressArg(parser)
        labels_util.AddCreateLabelsFlags(parser)
        daisy_utils.AddCommonDaisyArgs(parser)
        daisy_utils.AddExtraCommonDaisyArgs(parser)

        instances_flags.INSTANCES_ARG_FOR_IMPORT.AddArgument(
            parser, operation_type='import')

        daisy_utils.AddOVFSourceUriArg(parser)

        parser.add_argument(
            '--os',
            required=False,
            choices=sorted(cls._OS_CHOICES),
            help='Specifies the OS of the image being imported.')

        parser.add_argument(
            '--description',
            help='Specifies a textual description of the instances.')
        daisy_utils.AddGuestEnvironmentArg(parser)
        parser.display_info.AddCacheUpdater(completers.InstancesCompleter)
        sole_tenancy_flags.AddNodeAffinityFlagToParser(parser)

        parser.add_argument('--hostname',
                            help="""\
      Specify the hostname of the instance to be imported. The specified
      hostname must be RFC1035 compliant. If hostname is not specified, the
      default hostname is [INSTANCE_NAME].c.[PROJECT_ID].internal when using
      the global DNS, and [INSTANCE_NAME].[ZONE].c.[PROJECT_ID].internal
      when using zonal DNS.
      """)
Exemple #22
0
def _CommonArgs(parser,
                multiple_network_interface_cards,
                release_track,
                support_alias_ip_ranges,
                support_local_ssd_size=False):
    """Common arguments used in Alpha, Beta, and GA."""
    metadata_utils.AddMetadataArgs(parser)
    instances_flags.AddDiskArgs(parser)
    if release_track in [base.ReleaseTrack.ALPHA]:
        instances_flags.AddCreateDiskArgs(parser)
        instances_flags.AddExtendedMachineTypeArgs(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,
        multiple_network_interface_cards=multiple_network_interface_cards,
        support_alias_ip_ranges=support_alias_ip_ranges)
    instances_flags.AddMachineTypeArgs(parser)
    instances_flags.AddMaintenancePolicyArgs(parser)
    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)

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

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

    instance_templates_flags.INSTANCE_TEMPLATE_ARG.AddArgument(parser)
Exemple #23
0
    def Args(parser):
        """Register parser args."""
        metadata_utils.AddMetadataArgs(parser)
        instances_flags.AddDiskArgs(parser)
        instances_flags.AddLocalSsdArgs(parser)
        instances_flags.AddCanIpForwardArgs(parser)
        instances_flags.AddAddressArgs(parser, instances=True)
        instances_flags.AddMachineTypeArgs(parser)
        instances_flags.AddMaintenancePolicyArgs(parser)
        instances_flags.AddNoRestartOnFailureArgs(parser)
        instances_flags.AddPreemptibleVmArgs(parser)
        instances_flags.AddScopeArgs(parser)
        instances_flags.AddTagsArgs(parser)
        instances_flags.AddCustomMachineTypeArgs(parser)
        instances_flags.AddNetworkArgs(parser)
        instances_flags.AddPrivateNetworkIpArgs(parser)
        instances_flags.AddDockerArgs(parser)
        parser.add_argument(
            '--description',
            help='Specifies a textual description of the instances.')

        instances_flags.INSTANCES_ARG.AddArgument(parser)
def ArgsForClusterRef(parser,
                      beta=False,
                      include_deprecated=True,
                      include_ttl_config=False,
                      include_gke_platform_args=False):
    """Register flags for creating a dataproc cluster.

  Args:
    parser: The argparse.ArgParser to configure with dataproc cluster arguments.
    beta: whether or not this is a beta command (may affect flag visibility)
    include_deprecated: whether deprecated flags should be included
    include_ttl_config: whether to include Scheduled Delete(TTL) args
    include_gke_platform_args: whether to include GKE-based cluster args
  """
    labels_util.AddCreateLabelsFlags(parser)
    # 30m is backend timeout + 5m for safety buffer.
    flags.AddTimeoutFlag(parser, default='35m')
    flags.AddZoneFlag(parser, short_flags=include_deprecated)
    flags.AddComponentFlag(parser)

    platform_group = parser.add_argument_group(mutex=True)
    gce_platform_group = platform_group.add_argument_group(help="""\
    Compute Engine options for Dataproc clusters.
    """)

    instances_flags.AddTagsArgs(gce_platform_group)
    gce_platform_group.add_argument(
        '--metadata',
        type=arg_parsers.ArgDict(min_length=1),
        action='append',
        default=None,
        help=('Metadata to be made available to the guest operating system '
              'running on the instances'),
        metavar='KEY=VALUE')

    # Either allow creating a single node cluster (--single-node), or specifying
    # the number of workers in the multi-node cluster (--num-workers and
    # --num-secondary-workers)
    node_group = parser.add_argument_group(mutex=True)  # Mutually exclusive
    node_group.add_argument('--single-node',
                            action='store_true',
                            help="""\
      Create a single node cluster.

      A single node cluster has all master and worker components.
      It cannot have any separate worker nodes. If this flag is not
      specified, a cluster with separate workers is created.
      """)
    # Not mutually exclusive
    worker_group = node_group.add_argument_group(
        help='Multi-node cluster flags')
    worker_group.add_argument(
        '--num-workers',
        type=int,
        help='The number of worker nodes in the cluster. Defaults to '
        'server-specified.')
    worker_group.add_argument(
        '--secondary-worker-type',
        hidden=True,
        metavar='TYPE',
        choices=['preemptible', 'non-preemptible', 'unspecified'],
        default='unspecified',
        help='The type of the secondary worker group.')
    num_secondary_workers = worker_group.add_argument_group(mutex=True)
    num_secondary_workers.add_argument(
        '--num-preemptible-workers',
        action=actions.DeprecationAction(
            '--num-preemptible-workers',
            warn=('The `--num-preemptible-workers` flag is deprecated. '
                  'Use the `--num-secondary-workers` flag instead.')),
        type=int,
        hidden=True,
        help='The number of preemptible worker nodes in the cluster.')
    num_secondary_workers.add_argument(
        '--num-secondary-workers',
        type=int,
        help='The number of secondary worker nodes in the cluster.')

    parser.add_argument(
        '--master-machine-type',
        help='The type of machine to use for the master. Defaults to '
        'server-specified.')
    parser.add_argument(
        '--worker-machine-type',
        help='The type of machine to use for workers. Defaults to '
        'server-specified.')
    image_parser = parser.add_mutually_exclusive_group()
    # TODO(b/73291743): Add external doc link to --image
    image_parser.add_argument(
        '--image',
        metavar='IMAGE',
        help='The full custom image URI or the custom image name that '
        'will be used to create a cluster.')
    image_parser.add_argument(
        '--image-version',
        metavar='VERSION',
        help='The image version to use for the cluster. Defaults to the '
        'latest version.')
    parser.add_argument('--bucket',
                        help="""\
      The Google Cloud Storage bucket to use by default to stage job
      dependencies, miscellaneous config files, and job driver console output
      when using this cluster.
      """)

    netparser = gce_platform_group.add_argument_group(mutex=True)
    netparser.add_argument('--network',
                           help="""\
      The Compute Engine network that the VM instances of the cluster will be
      part of. This is mutually exclusive with --subnet. If neither is
      specified, this defaults to the "default" network.
      """)
    netparser.add_argument('--subnet',
                           help="""\
      Specifies the subnet that the cluster will be part of. This is mutally
      exclusive with --network.
      """)
    parser.add_argument(
        '--num-worker-local-ssds',
        type=int,
        help='The number of local SSDs to attach to each worker in a cluster.')
    parser.add_argument(
        '--num-master-local-ssds',
        type=int,
        help='The number of local SSDs to attach to the master in a cluster.')
    secondary_worker_local_ssds = parser.add_argument_group(mutex=True)
    secondary_worker_local_ssds.add_argument(
        '--num-preemptible-worker-local-ssds',
        type=int,
        hidden=True,
        action=actions.DeprecationAction(
            '--num-preemptible-worker-local-ssds',
            warn=(
                'The `--num-preemptible-worker-local-ssds` flag is deprecated. '
                'Use the `--num-secondary-worker-local-ssds` flag instead.')),
        help="""\
      The number of local SSDs to attach to each secondary worker in
      a cluster.
      """)
    secondary_worker_local_ssds.add_argument(
        '--num-secondary-worker-local-ssds',
        type=int,
        help="""\
      The number of local SSDs to attach to each preemptible worker in
      a cluster.
      """)
    parser.add_argument(
        '--initialization-actions',
        type=arg_parsers.ArgList(min_length=1),
        metavar='CLOUD_STORAGE_URI',
        help=('A list of Google Cloud Storage URIs of '
              'executables to run on each node in the cluster.'))
    parser.add_argument(
        '--initialization-action-timeout',
        type=arg_parsers.Duration(),
        metavar='TIMEOUT',
        default='10m',
        help=('The maximum duration of each initialization action. See '
              '$ gcloud topic datetimes for information on duration formats.'))
    parser.add_argument(
        '--num-masters',
        type=arg_parsers.CustomFunctionValidator(
            lambda n: int(n) in [1, 3],
            'Number of masters must be 1 (Standard) or 3 (High Availability)',
            parser=arg_parsers.BoundedInt(1, 3)),
        help="""\
      The number of master nodes in the cluster.

      Number of Masters | Cluster Mode
      --- | ---
      1 | Standard
      3 | High Availability
      """)
    parser.add_argument('--properties',
                        type=arg_parsers.ArgDict(),
                        action=arg_parsers.UpdateAction,
                        default={},
                        metavar='PREFIX:PROPERTY=VALUE',
                        help="""\
Specifies configuration properties for installed packages, such as Hadoop
and Spark.

Properties are mapped to configuration files by specifying a prefix, such as
"core:io.serializations". The following are supported prefixes and their
mappings:

Prefix | File | Purpose of file
--- | --- | ---
capacity-scheduler | capacity-scheduler.xml | Hadoop YARN Capacity Scheduler configuration
core | core-site.xml | Hadoop general configuration
distcp | distcp-default.xml | Hadoop Distributed Copy configuration
hadoop-env | hadoop-env.sh | Hadoop specific environment variables
hdfs | hdfs-site.xml | Hadoop HDFS configuration
hive | hive-site.xml | Hive configuration
mapred | mapred-site.xml | Hadoop MapReduce configuration
mapred-env | mapred-env.sh | Hadoop MapReduce specific environment variables
pig | pig.properties | Pig configuration
spark | spark-defaults.conf | Spark configuration
spark-env | spark-env.sh | Spark specific environment variables
yarn | yarn-site.xml | Hadoop YARN configuration
yarn-env | yarn-env.sh | Hadoop YARN specific environment variables

See https://cloud.google.com/dataproc/docs/concepts/configuring-clusters/cluster-properties
for more information.

""")
    gce_platform_group.add_argument(
        '--service-account',
        help='The Google Cloud IAM service account to be authenticated as.')
    gce_platform_group.add_argument('--scopes',
                                    type=arg_parsers.ArgList(min_length=1),
                                    metavar='SCOPE',
                                    help="""\
Specifies scopes for the node instances. Multiple SCOPEs can be specified,
separated by commas.
Examples:

  $ {{command}} example-cluster --scopes https://www.googleapis.com/auth/bigtable.admin

  $ {{command}} example-cluster --scopes sqlservice,bigquery

The following *minimum scopes* are necessary for the cluster to function
properly and are always added, even if not explicitly specified:

  {minimum_scopes}

If the `--scopes` flag is not specified, the following *default scopes*
are also included:

  {additional_scopes}

If you want to enable all scopes use the 'cloud-platform' scope.

{scopes_help}
""".format(minimum_scopes='\n  '.join(constants.MINIMUM_SCOPE_URIS),
           additional_scopes='\n  '.join(
               constants.ADDITIONAL_DEFAULT_SCOPE_URIS),
           scopes_help=compute_helpers.SCOPES_HELP))

    if include_deprecated:
        _AddDiskArgsDeprecated(parser)
    else:
        _AddDiskArgs(parser)

    # --no-address is an exception to the no negative-flag style guildline to be
    # consistent with gcloud compute instances create --no-address
    parser.add_argument('--no-address',
                        action='store_true',
                        help="""\
      If provided, the instances in the cluster will not be assigned external
      IP addresses.

      If omitted the instances in the cluster will each be assigned an
      ephemeral external IP address.

      Note: Dataproc VMs need access to the Dataproc API. This can be achieved
      without external IP addresses using Private Google Access
      (https://cloud.google.com/compute/docs/private-google-access).
      """)

    boot_disk_type_detailed_help = """\
      The type of the boot disk. The value must be ``pd-standard'' or
      ``pd-ssd''.
      """
    parser.add_argument('--master-boot-disk-type',
                        help=boot_disk_type_detailed_help)
    parser.add_argument('--worker-boot-disk-type',
                        help=boot_disk_type_detailed_help)
    secondary_worker_boot_disk_type = parser.add_argument_group(mutex=True)
    secondary_worker_boot_disk_type.add_argument(
        '--preemptible-worker-boot-disk-type',
        help=boot_disk_type_detailed_help,
        hidden=True,
        action=actions.DeprecationAction(
            '--preemptible-worker-boot-disk-type',
            warn=(
                'The `--preemptible-worker-boot-disk-type` flag is deprecated. '
                'Use the `--secondary-worker-boot-disk-type` flag instead.')))
    secondary_worker_boot_disk_type.add_argument(
        '--secondary-worker-boot-disk-type', help=boot_disk_type_detailed_help)

    autoscaling_group = parser.add_argument_group()
    flags.AddAutoscalingPolicyResourceArgForCluster(
        autoscaling_group, api_version=('v1beta2' if beta else 'v1'))

    if include_ttl_config:
        parser.add_argument('--max-idle',
                            type=arg_parsers.Duration(),
                            help="""\
          The duration before cluster is auto-deleted after last job completes,
          such as "2h" or "1d".
          See $ gcloud topic datetimes for information on duration formats.
          """)

        auto_delete_group = parser.add_mutually_exclusive_group()
        auto_delete_group.add_argument('--max-age',
                                       type=arg_parsers.Duration(),
                                       help="""\
          The lifespan of the cluster before it is auto-deleted, such as
          "2h" or "1d".
          See $ gcloud topic datetimes for information on duration formats.
          """)

        auto_delete_group.add_argument('--expiration-time',
                                       type=arg_parsers.Datetime.Parse,
                                       help="""\
          The time when cluster will be auto-deleted, such as
          "2017-08-29T18:52:51.142Z." See $ gcloud topic datetimes for
          information on time formats.
          """)

    AddKerberosGroup(parser)

    flags.AddMinCpuPlatformArgs(parser)

    _AddAcceleratorArgs(parser)

    AddReservationAffinityGroup(
        gce_platform_group,
        group_text='Specifies the reservation for the instance.',
        affinity_text='The type of reservation for the instance.')
    if include_gke_platform_args:
        gke_based_cluster_group = platform_group.add_argument_group(
            hidden=True,
            help="""\
          Options for creating a GKE-based Dataproc cluster. Specifying any of these
          will indicate that this cluster is intended to be a GKE-based cluster.
          These options are mutually exclusive with GCE-based options.
          """)
        gke_based_cluster_group.add_argument('--gke-cluster',
                                             hidden=True,
                                             help="""\
            Required for GKE-based clusters. Specify the name of the GKE cluster to
            deploy this GKE-based Dataproc cluster to. This should be the short name
            and not the full path name.
            """)
        gke_based_cluster_group.add_argument('--gke-cluster-namespace',
                                             hidden=True,
                                             help="""\
            Optional. Specify the name of the namespace to deploy Dataproc system
            components into. This namespace does not need to already exist.
            """)
Exemple #25
0
def ArgsForClusterRef(parser, beta=False):
    """Register flags for creating a dataproc cluster.

  Args:
    parser: The argparse.ArgParser to configure with dataproc cluster arguments.
    beta: whether or not this is a beta command (may affect flag visibility)
  """
    labels_util.AddCreateLabelsFlags(parser)
    instances_flags.AddTagsArgs(parser)
    # 30m is backend timeout + 5m for safety buffer.
    flags.AddTimeoutFlag(parser, default='35m')
    flags.AddZoneFlag(parser)

    parser.add_argument(
        '--metadata',
        type=arg_parsers.ArgDict(min_length=1),
        action='append',
        default=None,
        help=('Metadata to be made available to the guest operating system '
              'running on the instances'),
        metavar='KEY=VALUE')

    # Either allow creating a single node cluster (--single-node), or specifying
    # the number of workers in the multi-node cluster (--num-workers and
    # --num-preemptible-workers)
    node_group = parser.add_argument_group(mutex=True)  # Mutually exclusive
    node_group.add_argument('--single-node',
                            action='store_true',
                            help="""\
      Create a single node cluster.

      A single node cluster has all master and worker components.
      It cannot have any separate worker nodes. If this flag is not
      specified, a cluster with separate workers is created.
      """)
    # Not mutually exclusive
    worker_group = node_group.add_argument_group(
        help='Multi-node cluster flags')
    worker_group.add_argument(
        '--num-workers',
        type=int,
        help='The number of worker nodes in the cluster. Defaults to '
        'server-specified.')
    worker_group.add_argument(
        '--num-preemptible-workers',
        type=int,
        help='The number of preemptible worker nodes in the cluster.')

    parser.add_argument(
        '--master-machine-type',
        help='The type of machine to use for the master. Defaults to '
        'server-specified.')
    parser.add_argument(
        '--worker-machine-type',
        help='The type of machine to use for workers. Defaults to '
        'server-specified.')
    image_parser = parser.add_mutually_exclusive_group()
    # TODO(b/73291743): Add external doc link to --image
    image_parser.add_argument(
        '--image',
        metavar='IMAGE',
        help='The full custom image URI or the custom image name that '
        'will be used to create a cluster.')
    image_parser.add_argument(
        '--image-version',
        metavar='VERSION',
        help='The image version to use for the cluster. Defaults to the '
        'latest version.')
    parser.add_argument(
        '--bucket',
        help='The Google Cloud Storage bucket to use with the Google Cloud '
        'Storage connector. A bucket is auto created when this parameter is '
        'not specified.')

    netparser = parser.add_mutually_exclusive_group()
    netparser.add_argument('--network',
                           help="""\
      The Compute Engine network that the VM instances of the cluster will be
      part of. This is mutually exclusive with --subnet. If neither is
      specified, this defaults to the "default" network.
      """)
    netparser.add_argument('--subnet',
                           help="""\
      Specifies the subnet that the cluster will be part of. This is mutally
      exclusive with --network.
      """)
    parser.add_argument(
        '--num-worker-local-ssds',
        type=int,
        help='The number of local SSDs to attach to each worker in a cluster.')
    parser.add_argument(
        '--num-master-local-ssds',
        type=int,
        help='The number of local SSDs to attach to the master in a cluster.')
    parser.add_argument(
        '--initialization-actions',
        type=arg_parsers.ArgList(min_length=1),
        metavar='CLOUD_STORAGE_URI',
        help=('A list of Google Cloud Storage URIs of '
              'executables to run on each node in the cluster.'))
    parser.add_argument(
        '--initialization-action-timeout',
        type=arg_parsers.Duration(),
        metavar='TIMEOUT',
        default='10m',
        help=('The maximum duration of each initialization action. See '
              '$ gcloud topic datetimes for information on duration formats.'))
    parser.add_argument(
        '--num-masters',
        type=arg_parsers.CustomFunctionValidator(
            lambda n: int(n) in [1, 3],
            'Number of masters must be 1 (Standard) or 3 (High Availability)',
            parser=arg_parsers.BoundedInt(1, 3)),
        help="""\
      The number of master nodes in the cluster.

      [format="csv",options="header"]
      |========
      Number of Masters,Cluster Mode
      1,Standard
      3,High Availability
      |========
      """)
    parser.add_argument('--properties',
                        type=arg_parsers.ArgDict(),
                        metavar='PREFIX:PROPERTY=VALUE',
                        default={},
                        help="""\
Specifies configuration properties for installed packages, such as Hadoop
and Spark.

Properties are mapped to configuration files by specifying a prefix, such as
"core:io.serializations". The following are supported prefixes and their
mappings:

[format="csv",options="header"]
|========
Prefix,File,Purpose of file
capacity-scheduler,capacity-scheduler.xml,Hadoop YARN Capacity Scheduler configuration
core,core-site.xml,Hadoop general configuration
distcp,distcp-default.xml,Hadoop Distributed Copy configuration
hadoop-env,hadoop-env.sh,Hadoop specific environment variables
hdfs,hdfs-site.xml,Hadoop HDFS configuration
hive,hive-site.xml,Hive configuration
mapred,mapred-site.xml,Hadoop MapReduce configuration
mapred-env,mapred-env.sh,Hadoop MapReduce specific environment variables
pig,pig.properties,Pig configuration
spark,spark-defaults.conf,Spark configuration
spark-env,spark-env.sh,Spark specific environment variables
yarn,yarn-site.xml,Hadoop YARN configuration
yarn-env,yarn-env.sh,Hadoop YARN specific environment variables
|========

See https://cloud.google.com/dataproc/docs/concepts/configuring-clusters/cluster-properties
for more information.

""")
    parser.add_argument(
        '--service-account',
        help='The Google Cloud IAM service account to be authenticated as.')
    parser.add_argument('--scopes',
                        type=arg_parsers.ArgList(min_length=1),
                        metavar='SCOPE',
                        help="""\
Specifies scopes for the node instances. Multiple SCOPEs can be specified,
separated by commas.
Examples:

  $ {{command}} example-cluster --scopes https://www.googleapis.com/auth/bigtable.admin

  $ {{command}} example-cluster --scopes sqlservice,bigquery

The following *minimum scopes* are necessary for the cluster to function
properly and are always added, even if not explicitly specified:

[format="csv"]
|========
{minimum_scopes}
|========

If the `--scopes` flag is not specified, the following *default scopes*
are also included:

[format="csv"]
|========
{additional_scopes}
|========

If you want to enable all scopes use the 'cloud-platform' scope.

SCOPE can be either the full URI of the scope or an alias.
Available aliases are:

[format="csv",options="header"]
|========
Alias,URI
{aliases}
|========

{scope_deprecation_msg}
""".format(minimum_scopes='\n'.join(constants.MINIMUM_SCOPE_URIS),
           additional_scopes='\n'.join(
               constants.ADDITIONAL_DEFAULT_SCOPE_URIS),
           aliases=compute_helpers.SCOPE_ALIASES_FOR_HELP,
           scope_deprecation_msg=compute_constants.DEPRECATED_SCOPES_MESSAGES))

    master_boot_disk_size = parser.add_mutually_exclusive_group()
    worker_boot_disk_size = parser.add_mutually_exclusive_group()

    # Deprecated, to be removed at a future date.
    master_boot_disk_size.add_argument(
        '--master-boot-disk-size-gb',
        action=actions.DeprecationAction(
            '--master-boot-disk-size-gb',
            warn=(
                'The `--master-boot-disk-size-gb` flag is deprecated. '
                'Use `--master-boot-disk-size` flag with "GB" after value.')),
        type=int,
        hidden=True,
        help='Use `--master-boot-disk-size` flag with "GB" after value.')
    worker_boot_disk_size.add_argument(
        '--worker-boot-disk-size-gb',
        action=actions.DeprecationAction(
            '--worker-boot-disk-size-gb',
            warn=(
                'The `--worker-boot-disk-size-gb` flag is deprecated. '
                'Use `--worker-boot-disk-size` flag with "GB" after value.')),
        type=int,
        hidden=True,
        help='Use `--worker-boot-disk-size` flag with "GB" after value.')

    boot_disk_size_detailed_help = """\
      The size of the boot disk. The value must be a
      whole number followed by a size unit of ``KB'' for kilobyte, ``MB''
      for megabyte, ``GB'' for gigabyte, or ``TB'' for terabyte. For example,
      ``10GB'' will produce a 10 gigabyte disk. The minimum size a boot disk
      can have is 10 GB. Disk size must be a multiple of 1 GB.
      """
    master_boot_disk_size.add_argument(
        '--master-boot-disk-size',
        type=arg_parsers.BinarySize(lower_bound='10GB'),
        help=boot_disk_size_detailed_help)
    worker_boot_disk_size.add_argument(
        '--worker-boot-disk-size',
        type=arg_parsers.BinarySize(lower_bound='10GB'),
        help=boot_disk_size_detailed_help)
    parser.add_argument('--preemptible-worker-boot-disk-size',
                        type=arg_parsers.BinarySize(lower_bound='10GB'),
                        help=boot_disk_size_detailed_help)

    # Args that are visible only in Beta track
    parser.add_argument('--no-address',
                        action='store_true',
                        help="""\
      If provided, the instances in the cluster will not be assigned external
      IP addresses.

      Note: Dataproc VMs need access to the Dataproc API. This can be achieved
      without external IP addresses using Private Google Access
      (https://cloud.google.com/compute/docs/private-google-access).
      """,
                        hidden=not beta)

    boot_disk_type_detailed_help = """\
      The type of the boot disk. The value must be ``pd-standard'' or
      ``pd-ssd''.
      """
    parser.add_argument('--master-boot-disk-type',
                        help=boot_disk_type_detailed_help)
    parser.add_argument('--worker-boot-disk-type',
                        help=boot_disk_type_detailed_help)
    parser.add_argument('--preemptible-worker-boot-disk-type',
                        help=boot_disk_type_detailed_help)
Exemple #26
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)
Exemple #27
0
def _CommonArgs(parser):
    """Register flags common to all tracks."""
    instances_flags.AddTagsArgs(parser)
    base.ASYNC_FLAG.AddToParser(parser)
    labels_util.AddCreateLabelsFlags(parser)
    parser.add_argument(
        '--metadata',
        type=arg_parsers.ArgDict(min_length=1),
        action='append',
        default=None,
        help=('Metadata to be made available to the guest operating system '
              'running on the instances'),
        metavar='KEY=VALUE')
    parser.add_argument('name', help='The name of this cluster.')
    parser.add_argument(
        '--num-workers',
        type=int,
        help='The number of worker nodes in the cluster. Defaults to '
        'server-specified.')
    parser.add_argument(
        '--num-preemptible-workers',
        type=int,
        help='The number of preemptible worker nodes in the cluster.')
    parser.add_argument(
        '--main-machine-type',
        help='The type of machine to use for the main. Defaults to '
        'server-specified.')
    parser.add_argument(
        '--worker-machine-type',
        help='The type of machine to use for workers. Defaults to '
        'server-specified.')
    parser.add_argument('--image', hidden=True)
    parser.add_argument(
        '--image-version',
        metavar='VERSION',
        help='The image version to use for the cluster. Defaults to the '
        'latest version.')
    parser.add_argument(
        '--bucket',
        help='The Google Cloud Storage bucket to use with the Google Cloud '
        'Storage connector. A bucket is auto created when this parameter is '
        'not specified.')

    netparser = parser.add_mutually_exclusive_group()
    netparser.add_argument('--network',
                           help="""\
      The Compute Engine network that the VM instances of the cluster will be
      part of. This is mutually exclusive with --subnet. If neither is
      specified, this defaults to the "default" network.
      """)
    netparser.add_argument('--subnet',
                           help="""\
      Specifies the subnet that the cluster will be part of. This is mutally
      exclusive with --network.
      """)
    parser.add_argument(
        '--zone',
        '-z',
        help='The compute zone (e.g. us-central1-a) for the cluster.',
        action=actions.StoreProperty(properties.VALUES.compute.zone))
    parser.add_argument(
        '--num-worker-local-ssds',
        type=int,
        help='The number of local SSDs to attach to each worker in a cluster.')
    parser.add_argument(
        '--num-main-local-ssds',
        type=int,
        help='The number of local SSDs to attach to the main in a cluster.')
    parser.add_argument(
        '--initialization-actions',
        type=arg_parsers.ArgList(min_length=1),
        metavar='CLOUD_STORAGE_URI',
        help=('A list of Google Cloud Storage URIs of '
              'executables to run on each node in the cluster.'))
    parser.add_argument(
        '--initialization-action-timeout',
        type=arg_parsers.Duration(),
        metavar='TIMEOUT',
        default='10m',
        help='The maximum duration of each initialization action.')
    parser.add_argument('--properties',
                        type=arg_parsers.ArgDict(),
                        metavar='PREFIX:PROPERTY=VALUE',
                        default={},
                        help="""\
Specifies configuration properties for installed packages, such as Hadoop
and Spark.

Properties are mapped to configuration files by specifying a prefix, such as
"core:io.serializations". The following are supported prefixes and their
mappings:

[format="csv",options="header"]
|========
Prefix,Target Configuration File
core,core-site.xml
hdfs,hdfs-site.xml
mapred,mapred-site.xml
yarn,yarn-site.xml
hive,hive-site.xml
pig,pig.properties
spark,spark-defaults.conf
|========

""")
    parser.add_argument(
        '--service-account',
        help='The Google Cloud IAM service account to be authenticated as.')
    parser.add_argument('--scopes',
                        type=arg_parsers.ArgList(min_length=1),
                        metavar='SCOPE',
                        help="""\
Specifies scopes for the node instances. The project's default service account
is used. Multiple SCOPEs can specified, separated by commas.
Examples:

  $ {{command}} example-cluster --scopes https://www.googleapis.com/auth/bigtable.admin

  $ {{command}} example-cluster --scopes sqlservice,bigquery

The following scopes necessary for the cluster to function properly are always
added, even if not explicitly specified:

[format="csv"]
|========
{minimum_scopes}
|========

If this flag is not specified the following default scopes are also included:

[format="csv"]
|========
{additional_scopes}
|========

If you want to enable all scopes use the 'cloud-platform' scope.

SCOPE can be either the full URI of the scope or an alias.
Available aliases are:

[format="csv",options="header"]
|========
Alias,URI
{aliases}
|========
""".format(minimum_scopes='\n'.join(constants.MINIMUM_SCOPE_URIS),
           additional_scopes='\n'.join(
               constants.ADDITIONAL_DEFAULT_SCOPE_URIS),
           aliases=compute_helpers.SCOPE_ALIASES_FOR_HELP))

    main_boot_disk = parser.add_mutually_exclusive_group()
    worker_boot_disk = parser.add_mutually_exclusive_group()

    # Deprecated, to be removed at a future date.
    main_boot_disk.add_argument('--main-boot-disk-size-gb',
                                type=int,
                                hidden=True)
    worker_boot_disk.add_argument('--worker-boot-disk-size-gb',
                                  type=int,
                                  hidden=True)

    boot_disk_size_detailed_help = """\
      The size of the boot disk. The value must be a
      whole number followed by a size unit of ``KB'' for kilobyte, ``MB''
      for megabyte, ``GB'' for gigabyte, or ``TB'' for terabyte. For example,
      ``10GB'' will produce a 10 gigabyte disk. The minimum size a boot disk
      can have is 10 GB. Disk size must be a multiple of 1 GB.
      """
    main_boot_disk.add_argument(
        '--main-boot-disk-size',
        type=arg_parsers.BinarySize(lower_bound='10GB'),
        help=boot_disk_size_detailed_help)
    worker_boot_disk.add_argument(
        '--worker-boot-disk-size',
        type=arg_parsers.BinarySize(lower_bound='10GB'),
        help=boot_disk_size_detailed_help)

    parser.add_argument('--preemptible-worker-boot-disk-size',
                        type=arg_parsers.BinarySize(lower_bound='10GB'),
                        help="""\
      The size of the boot disk. The value must be a
      whole number followed by a size unit of ``KB'' for kilobyte, ``MB''
      for megabyte, ``GB'' for gigabyte, or ``TB'' for terabyte. For example,
      ``10GB'' will produce a 10 gigabyte disk. The minimum size a boot disk
      can have is 10 GB. Disk size must be a multiple of 1 GB.
      """)
Exemple #28
0
def _CommonArgs(parser,
                enable_regional=False,
                enable_kms=False,
                deprecate_maintenance_policy=False,
                enable_resource_policy=False,
                supports_min_node_cpus=False,
                supports_location_hint=False,
                snapshot_csek=False,
                image_csek=False):
  """Register parser args common to all tracks."""
  metadata_utils.AddMetadataArgs(parser)
  instances_flags.AddDiskArgs(parser, enable_regional, enable_kms=enable_kms)
  instances_flags.AddCreateDiskArgs(parser, enable_kms=enable_kms,
                                    enable_snapshots=True,
                                    resource_policy=enable_resource_policy,
                                    source_snapshot_csek=snapshot_csek,
                                    image_csek=image_csek)
  instances_flags.AddCanIpForwardArgs(parser)
  instances_flags.AddAddressArgs(parser, instances=True)
  instances_flags.AddAcceleratorArgs(parser)
  instances_flags.AddMachineTypeArgs(parser)
  instances_flags.AddMaintenancePolicyArgs(
      parser, deprecate=deprecate_maintenance_policy)
  instances_flags.AddNoRestartOnFailureArgs(parser)
  instances_flags.AddPreemptibleVmArgs(parser)
  instances_flags.AddServiceAccountAndScopeArgs(
      parser, False,
      extra_scopes_help='However, if neither `--scopes` nor `--no-scopes` are '
                        'specified and the project has no default service '
                        'account, then the instance will be created with no '
                        'scopes. Note that the level of access that a service '
                        'account has is determined by a combination of access '
                        'scopes and IAM roles so you must configure both '
                        'access scopes and IAM roles for the service account '
                        'to work properly.')
  instances_flags.AddTagsArgs(parser)
  instances_flags.AddCustomMachineTypeArgs(parser)
  instances_flags.AddNetworkArgs(parser)
  instances_flags.AddPrivateNetworkIpArgs(parser)
  instances_flags.AddHostnameArg(parser)
  instances_flags.AddImageArgs(parser, enable_snapshots=True)
  instances_flags.AddDeletionProtectionFlag(parser)
  instances_flags.AddPublicPtrArgs(parser, instance=True)
  instances_flags.AddNetworkTierArgs(parser, instance=True)
  instances_flags.AddShieldedInstanceConfigArgs(parser)
  instances_flags.AddDisplayDeviceArg(parser)

  instances_flags.AddReservationAffinityGroup(
      parser,
      group_text='Specifies the reservation for the instance.',
      affinity_text='The type of reservation for the instance.')

  sole_tenancy_flags.AddNodeAffinityFlagToParser(parser)

  if supports_min_node_cpus:
    sole_tenancy_flags.AddMinNodeCpusArg(parser)

  if supports_location_hint:
    instances_flags.AddLocationHintArg(parser)

  labels_util.AddCreateLabelsFlags(parser)

  parser.add_argument(
      '--description',
      help='Specifies a textual description of the instances.')

  instances_flags.INSTANCES_ARG_FOR_CREATE.AddArgument(
      parser, operation_type='create')

  csek_utils.AddCsekKeyArgs(parser)

  base.ASYNC_FLAG.AddToParser(parser)
  parser.display_info.AddFormat(
      resource_registry.RESOURCE_REGISTRY['compute.instances'].list_format)
  parser.display_info.AddCacheUpdater(completers.InstancesCompleter)
def _CommonArgs(
        parser,
        # TODO(b/80138906): Release track should not be passed around.
        release_track,
        support_public_dns,
        support_network_tier,
        enable_regional=False,
        support_local_ssd_size=False,
        enable_kms=False,
        support_sole_tenancy=False,
        supports_resource_policies=False):
    """Register parser args common to all tracks."""
    metadata_utils.AddMetadataArgs(parser)
    instances_flags.AddDiskArgs(parser, enable_regional, enable_kms=enable_kms)
    instances_flags.AddCreateDiskArgs(parser, enable_kms=enable_kms)
    if support_local_ssd_size:
        instances_flags.AddLocalSsdArgsWithSize(parser)
    else:
        instances_flags.AddLocalSsdArgs(parser)
    instances_flags.AddCanIpForwardArgs(parser)
    instances_flags.AddAddressArgs(parser,
                                   instances=True,
                                   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,
        extra_scopes_help='However, if neither `--scopes` nor `--no-scopes` are '
        'specified and the project has no default service '
        'account, then the instance will be created with no '
        'scopes.')
    instances_flags.AddTagsArgs(parser)
    instances_flags.AddCustomMachineTypeArgs(parser)
    instances_flags.AddNetworkArgs(parser)
    instances_flags.AddPrivateNetworkIpArgs(parser)
    instances_flags.AddImageArgs(parser)
    instances_flags.AddDeletionProtectionFlag(parser)
    instances_flags.AddPublicPtrArgs(parser, instance=True)
    if support_public_dns:
        instances_flags.AddPublicDnsArgs(parser, instance=True)
    if support_network_tier:
        instances_flags.AddNetworkTierArgs(parser, instance=True)
    if support_sole_tenancy:
        sole_tenancy_flags.AddNodeAffinityFlagToParser(parser)
    if supports_resource_policies:
        maintenance_flags.AddResourcePoliciesArgs(parser, 'added to',
                                                  'instance')

    labels_util.AddCreateLabelsFlags(parser)
    instances_flags.AddMinCpuPlatformArgs(parser, release_track)

    parser.add_argument(
        '--description',
        help='Specifies a textual description of the instances.')

    instances_flags.INSTANCES_ARG_FOR_CREATE.AddArgument(
        parser, operation_type='create')

    csek_utils.AddCsekKeyArgs(parser)

    base.ASYNC_FLAG.AddToParser(parser)
    parser.display_info.AddFormat(
        resource_registry.RESOURCE_REGISTRY['compute.instances'].list_format)
    parser.display_info.AddCacheUpdater(completers.InstancesCompleter)
Exemple #30
0
def ArgsForClusterRef(parser, beta=False, include_deprecated=True):     \
    # pylint: disable=unused-argument
    """Register flags for creating a dataproc cluster.

  Args:
    parser: The argparse.ArgParser to configure with dataproc cluster arguments.
    beta: whether or not this is a beta command (may affect flag visibility)
    include_deprecated: whether deprecated flags should be included
  """
    labels_util.AddCreateLabelsFlags(parser)
    instances_flags.AddTagsArgs(parser)
    # 30m is backend timeout + 5m for safety buffer.
    flags.AddTimeoutFlag(parser, default='35m')
    flags.AddZoneFlag(parser, short_flags=include_deprecated)

    parser.add_argument(
        '--metadata',
        type=arg_parsers.ArgDict(min_length=1),
        action='append',
        default=None,
        help=('Metadata to be made available to the guest operating system '
              'running on the instances'),
        metavar='KEY=VALUE')

    # Either allow creating a single node cluster (--single-node), or specifying
    # the number of workers in the multi-node cluster (--num-workers and
    # --num-preemptible-workers)
    node_group = parser.add_argument_group(mutex=True)  # Mutually exclusive
    node_group.add_argument('--single-node',
                            action='store_true',
                            help="""\
      Create a single node cluster.

      A single node cluster has all master and worker components.
      It cannot have any separate worker nodes. If this flag is not
      specified, a cluster with separate workers is created.
      """)
    # Not mutually exclusive
    worker_group = node_group.add_argument_group(
        help='Multi-node cluster flags')
    worker_group.add_argument(
        '--num-workers',
        type=int,
        help='The number of worker nodes in the cluster. Defaults to '
        'server-specified.')
    worker_group.add_argument(
        '--num-preemptible-workers',
        type=int,
        help='The number of preemptible worker nodes in the cluster.')

    parser.add_argument(
        '--master-machine-type',
        help='The type of machine to use for the master. Defaults to '
        'server-specified.')
    parser.add_argument(
        '--worker-machine-type',
        help='The type of machine to use for workers. Defaults to '
        'server-specified.')
    image_parser = parser.add_mutually_exclusive_group()
    # TODO(b/73291743): Add external doc link to --image
    image_parser.add_argument(
        '--image',
        metavar='IMAGE',
        help='The full custom image URI or the custom image name that '
        'will be used to create a cluster.')
    image_parser.add_argument(
        '--image-version',
        metavar='VERSION',
        help='The image version to use for the cluster. Defaults to the '
        'latest version.')
    parser.add_argument(
        '--bucket',
        help='The Google Cloud Storage bucket to use with the Google Cloud '
        'Storage connector. A bucket is auto created when this parameter is '
        'not specified.')

    netparser = parser.add_mutually_exclusive_group()
    netparser.add_argument('--network',
                           help="""\
      The Compute Engine network that the VM instances of the cluster will be
      part of. This is mutually exclusive with --subnet. If neither is
      specified, this defaults to the "default" network.
      """)
    netparser.add_argument('--subnet',
                           help="""\
      Specifies the subnet that the cluster will be part of. This is mutally
      exclusive with --network.
      """)
    parser.add_argument(
        '--num-worker-local-ssds',
        type=int,
        help='The number of local SSDs to attach to each worker in a cluster.')
    parser.add_argument(
        '--num-master-local-ssds',
        type=int,
        help='The number of local SSDs to attach to the master in a cluster.')
    parser.add_argument(
        '--initialization-actions',
        type=arg_parsers.ArgList(min_length=1),
        metavar='CLOUD_STORAGE_URI',
        help=('A list of Google Cloud Storage URIs of '
              'executables to run on each node in the cluster.'))
    parser.add_argument(
        '--initialization-action-timeout',
        type=arg_parsers.Duration(),
        metavar='TIMEOUT',
        default='10m',
        help=('The maximum duration of each initialization action. See '
              '$ gcloud topic datetimes for information on duration formats.'))
    parser.add_argument(
        '--num-masters',
        type=arg_parsers.CustomFunctionValidator(
            lambda n: int(n) in [1, 3],
            'Number of masters must be 1 (Standard) or 3 (High Availability)',
            parser=arg_parsers.BoundedInt(1, 3)),
        help="""\
      The number of master nodes in the cluster.

      Number of Masters | Cluster Mode
      --- | ---
      1 | Standard
      3 | High Availability
      """)
    parser.add_argument('--properties',
                        type=arg_parsers.ArgDict(),
                        metavar='PREFIX:PROPERTY=VALUE',
                        default={},
                        help="""\
Specifies configuration properties for installed packages, such as Hadoop
and Spark.

Properties are mapped to configuration files by specifying a prefix, such as
"core:io.serializations". The following are supported prefixes and their
mappings:

Prefix | File | Purpose of file
--- | --- | ---
capacity-scheduler | capacity-scheduler.xml | Hadoop YARN Capacity Scheduler configuration
core | core-site.xml | Hadoop general configuration
distcp | distcp-default.xml | Hadoop Distributed Copy configuration
hadoop-env | hadoop-env.sh | Hadoop specific environment variables
hdfs | hdfs-site.xml | Hadoop HDFS configuration
hive | hive-site.xml | Hive configuration
mapred | mapred-site.xml | Hadoop MapReduce configuration
mapred-env | mapred-env.sh | Hadoop MapReduce specific environment variables
pig | pig.properties | Pig configuration
spark | spark-defaults.conf | Spark configuration
spark-env | spark-env.sh | Spark specific environment variables
yarn | yarn-site.xml | Hadoop YARN configuration
yarn-env | yarn-env.sh | Hadoop YARN specific environment variables

See https://cloud.google.com/dataproc/docs/concepts/configuring-clusters/cluster-properties
for more information.

""")
    parser.add_argument(
        '--service-account',
        help='The Google Cloud IAM service account to be authenticated as.')
    parser.add_argument('--scopes',
                        type=arg_parsers.ArgList(min_length=1),
                        metavar='SCOPE',
                        help="""\
Specifies scopes for the node instances. Multiple SCOPEs can be specified,
separated by commas.
Examples:

  $ {{command}} example-cluster --scopes https://www.googleapis.com/auth/bigtable.admin

  $ {{command}} example-cluster --scopes sqlservice,bigquery

The following *minimum scopes* are necessary for the cluster to function
properly and are always added, even if not explicitly specified:

  {minimum_scopes}

If the `--scopes` flag is not specified, the following *default scopes*
are also included:

  {additional_scopes}

If you want to enable all scopes use the 'cloud-platform' scope.

{scopes_help}
""".format(minimum_scopes='\n  '.join(constants.MINIMUM_SCOPE_URIS),
           additional_scopes='\n  '.join(
               constants.ADDITIONAL_DEFAULT_SCOPE_URIS),
           scopes_help=compute_helpers.SCOPES_HELP))

    if include_deprecated:
        _AddDiskArgsDeprecated(parser)
    else:
        _AddDiskArgs(parser)

    # --no-address is an exception to the no negative-flag style guildline to be
    # consistent with gcloud compute instances create --no-address
    parser.add_argument('--no-address',
                        action='store_true',
                        help="""\
      If provided, the instances in the cluster will not be assigned external
      IP addresses.

      If omitted the instances in the cluster will each be assigned an
      ephemeral external IP address.

      Note: Dataproc VMs need access to the Dataproc API. This can be achieved
      without external IP addresses using Private Google Access
      (https://cloud.google.com/compute/docs/private-google-access).
      """)

    boot_disk_type_detailed_help = """\
      The type of the boot disk. The value must be ``pd-standard'' or
      ``pd-ssd''.
      """
    parser.add_argument('--master-boot-disk-type',
                        help=boot_disk_type_detailed_help)
    parser.add_argument('--worker-boot-disk-type',
                        help=boot_disk_type_detailed_help)
    parser.add_argument('--preemptible-worker-boot-disk-type',
                        help=boot_disk_type_detailed_help)