예제 #1
0
파일: create.py 프로젝트: gyaresu/dotfiles
def _AddSourceInstanceToTemplate(compute_api, args, instance_template,
                                 support_source_instance):
    """Set the source instance for the template."""

    if not support_source_instance or not args.source_instance:
        return
    source_instance_arg = instance_templates_flags.MakeSourceInstanceArg()
    source_instance_ref = source_instance_arg.ResolveAsResource(
        args, compute_api.resources)
    instance_template.sourceInstance = source_instance_ref.SelfLink()
    if args.configure_disk:
        messages = compute_api.client.messages
        instance_template.sourceInstanceParams = messages.SourceInstanceParams(
        )
        for disk in args.configure_disk:
            instantiate_from = disk.get('instantiate-from')
            custom_image = disk.get('custom-image')
            if custom_image and instantiate_from != 'custom-image':
                raise exceptions.InvalidArgumentException(
                    '--configure-disk',
                    'Value for `instaniate-from` must be \'custom-image\' if the key '
                    '`custom-image` is specified.')
            disk_config = messages.DiskInstantiationConfig()
            disk_config.autoDelete = disk.get('auto-delete')
            disk_config.deviceName = disk.get('device-name')
            disk_config.instantiateFrom = (
                messages.DiskInstantiationConfig.
                InstantiateFromValueValuesEnum(
                    instantiate_from.upper().replace('-', '_')))
            disk_config.customImage = custom_image
            instance_template.sourceInstanceParams.diskConfigs.append(
                disk_config)
    # `properties` and `sourceInstance` are a one of.
    instance_template.properties = None
예제 #2
0
def _AddSourceInstanceToTemplate(compute_api, args, instance_template,
                                 support_source_instance):
    """Set the source instance for the template."""

    if not support_source_instance or not args.source_instance:
        return
    source_instance_arg = instance_templates_flags.MakeSourceInstanceArg()
    source_instance_ref = source_instance_arg.ResolveAsResource(
        args, compute_api.resources)
    instance_template.sourceInstance = source_instance_ref.SelfLink()
    if args.configure_disk:
        messages = compute_api.client.messages
        instance_template.sourceInstanceParams = messages.SourceInstanceParams(
        )
        for disk in args.configure_disk:
            disk_config = messages.DiskInstantiationConfig()
            disk_config.autoDelete = disk.get('auto-delete')
            disk_config.deviceName = disk.get('device-name')
            disk_config.instantiateFrom = (
                messages.DiskInstantiationConfig.
                InstantiateFromValueValuesEnum(
                    disk.get('instantiate-from').upper().replace('-', '_')))
            instance_template.sourceInstanceParams.diskConfigs.append(
                disk_config)
    # `properties` and `sourceInstance` are a one of.
    instance_template.properties = None
예제 #3
0
def _AddSourceInstanceToTemplate(compute_api, args, support_source_instance,
                                 instance_template):
    if not support_source_instance or not args.source_instance:
        return
    source_instance_arg = instance_templates_flags.MakeSourceInstanceArg()
    source_instance_ref = source_instance_arg.ResolveAsResource(
        args, compute_api.resources)
    instance_template.sourceInstance = source_instance_ref.SelfLink()
예제 #4
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)
예제 #5
0
파일: create.py 프로젝트: gyaresu/dotfiles
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)
def _CommonArgs(parser,
                release_track,
                support_source_instance,
                support_local_ssd_size=False,
                support_kms=False,
                support_multi_writer=False,
                support_mesh=False,
                support_host_error_timeout_seconds=False,
                support_numa_node_count=False,
                support_visible_core_count=False,
                support_disk_architecture=False,
                support_max_run_duration=False):
  """Adding arguments applicable for creating instance templates."""
  parser.display_info.AddFormat(instance_templates_flags.DEFAULT_LIST_FORMAT)
  metadata_utils.AddMetadataArgs(parser)
  instances_flags.AddDiskArgs(parser, enable_kms=support_kms)
  instances_flags.AddCreateDiskArgs(
      parser,
      enable_kms=support_kms,
      support_boot=True,
      support_multi_writer=support_multi_writer,
      support_disk_architecture=support_disk_architecture)
  if support_local_ssd_size:
    instances_flags.AddLocalSsdArgsWithSize(parser)
  else:
    instances_flags.AddLocalSsdArgs(parser)
  instances_flags.AddCanIpForwardArgs(parser)
  instances_flags.AddAddressArgs(parser, instances=False)
  instances_flags.AddAcceleratorArgs(parser)
  instances_flags.AddMachineTypeArgs(parser)
  deprecate_maintenance_policy = release_track in [base.ReleaseTrack.ALPHA]
  instances_flags.AddMaintenancePolicyArgs(parser, deprecate_maintenance_policy)
  instances_flags.AddNoRestartOnFailureArgs(parser)
  instances_flags.AddPreemptibleVmArgs(parser)
  instances_flags.AddServiceAccountAndScopeArgs(parser, False)
  instances_flags.AddTagsArgs(parser)
  instances_flags.AddCustomMachineTypeArgs(parser)
  instances_flags.AddImageArgs(parser)
  instances_flags.AddNetworkArgs(parser)
  instances_flags.AddShieldedInstanceConfigArgs(parser)
  labels_util.AddCreateLabelsFlags(parser)
  instances_flags.AddNetworkTierArgs(parser, instance=True)
  instances_flags.AddPrivateNetworkIpArgs(parser)
  instances_flags.AddMinNodeCpuArg(parser)
  instances_flags.AddNestedVirtualizationArgs(parser)
  instances_flags.AddThreadsPerCoreArgs(parser)
  instances_flags.AddEnableUefiNetworkingArgs(parser)
  instances_flags.AddResourceManagerTagsArgs(parser)
  if support_numa_node_count:
    instances_flags.AddNumaNodeCountArgs(parser)
  instances_flags.AddStackTypeArgs(parser)
  instances_flags.AddIpv6NetworkTierArgs(parser)
  maintenance_flags.AddResourcePoliciesArgs(parser, 'added to',
                                            'instance-template')
  instances_flags.AddProvisioningModelVmArgs(parser)
  instances_flags.AddInstanceTerminationActionVmArgs(parser)

  if support_max_run_duration:
    instances_flags.AddMaxRunDurationVmArgs(parser)

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

  sole_tenancy_flags.AddNodeAffinityFlagToParser(parser)

  instances_flags.AddLocationHintArg(parser)

  if support_visible_core_count:
    instances_flags.AddVisibleCoreCountArgs(parser)

  instances_flags.AddNetworkPerformanceConfigsArgs(parser)

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

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

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

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

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

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

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

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

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