
    @                        S r SSKJr  SSKJr  SSKJr  SSKrSSKrSSKJr  SSKJ	r	  SSKJ
r
  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ r   SSK!r!\RD                  " S5      r#Sr$S r%SES jr&   SFS jr'S r(S r)S r*S r+                SGS jr,S r- SHS jr.S  r/S! r0S" r1        SIS# jr2S$ r3S% r4S& r5 SJS' jr6S( r7S) r8S* r9S+ r:S, r;S- r<         SKS. jr=S/ r>S0 r?S1 r@S2 rAS3 rBS4 rCS5 rD SLS6 jrESLS7 jrFS8 rGS9 rHS: rIS; rJSMS< jrKS= rLSLS> jrMS? rNS@ rOSA rPSMSB jrQSC rRSDrSg)NzHConvenience functions for dealing with instances and instance templates.    )absolute_import)division)unicode_literalsN)	constants)containers_utils)
csek_utils)metadata_utils)utils)
zone_utils)
exceptions)flags)resource_manager_tags_utils)scope)util)log)	resources)timesz2(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)zDefault device-name for disk name [{0}] will be [{0}] because it is being mounted to a container with [`--container-mount-disk`]c                     [         R                  " SU 5      nU(       a7  UR                  S5      nUR                  S5      nUR                  S5      nX#U4$ g)a  Gets the CPU and memory specs from the custom machine type name.

Args:
  name: the custom machine type name for the 'instance create' call

Returns:
  A three-tuple with the vm family, number of cpu and amount of memory for the
  custom machine type.
  custom_family, the name of the VM family
  custom_cpu, the number of cpu desired for the custom machine type instance
  custom_memory_mib, the amount of ram desired in MiB for the custom machine
    type instance
  None for both variables otherwise
z'([a-zA-Z0-9]+)-custom-([0-9]+)-([0-9]+)         )NNN)researchgroup)namecheck_customcustom_family
custom_cpucustom_memory_mibs        4lib/googlecloudsdk/api_lib/compute/instance_utils.pyGetCpuRamVmFamilyFromCustomNamer!   0   sX     DdK, &&q)M##A&J$**1-&777	    c                 t    U(       a  SR                  X0U5      nOSR                  X5      nU(       a  US-  nU$ )a  Creates a custom machine type name from the desired CPU and memory specs.

Args:
  custom_cpu: the number of cpu desired for the custom machine type
  custom_memory_mib: the amount of ram desired in MiB for the custom machine
    type instance
  ext: extended custom machine type should be used if true
  vm_type: VM instance generation

Returns:
  The custom machine type name for the 'instance create' call
z{0}-custom-{1}-{2}zcustom-{0}-{1}z-ext)format)r   r   extvm_typemachine_types        r    GetNameForCustomr(   H   sB     '..w/@BL $**:ILFL	r"   c                 l   U (       a  U nO'Ub  [         R                  U   nO[         R                  nU(       d  U(       d  U(       am  U(       d  [        R                  " SS5      eU(       d  [        R                  " SS5      eU (       a  [        R
                  " SS5      e[        UUS-  UU5      nUnU$ )a  Interprets the machine type for the instance.

Args:
  machine_type: name of existing machine type, eg. n1-standard
  custom_cpu: number of CPU cores for custom machine type,
  custom_memory: amount of RAM memory in bytes for custom machine type,
  ext: extended custom machine type should be used if true,
  vm_type:  VM instance generation
  confidential_vm_type: If not None, use default machine type based on
      confidential-VM encryption type.

Returns:
  A string representing the URL naming a machine-type.

Raises:
  calliope_exceptions.RequiredArgumentException when only one of the two
    custom machine type flags are used.
  calliope_exceptions.InvalidArgumentException when both the machine type and
    custom machine type flags are used to generate a new instance.
z--custom-cpuz_Both [--custom-cpu] and [--custom-memory] must be set to create a custom machine type instance.z--custom-memoryz--machine-typez\Cannot set both [--machine-type] and [--custom-cpu]/[--custom-memory] for the same instance.i   )r   )DEFAULT_MACHINE_TYPE_FOR_CONFIDENTIAL_VMSDEFAULT_MACHINE_TYPEcalliope_exceptionsRequiredArgumentExceptionInvalidArgumentExceptionr(   )r'   r   custom_memoryr%   r&   confidential_vm_typemachine_type_namecustom_type_strings           r    InterpretMachineTyper3   _   s    6 $'!KK "66 =C99
 :; ; 99
 => > 88
 DE E *%  +	r"   c                     U R                   nU R                  nSU;   aX  UR                  X1US9nUR                  SU4/n/ n[	        U R                  XxS95      n	U(       a  [        R                  " USS9  ggg)a  Checks that the CPU and memory ratio is a supported custom instance type.

Args:
  compute_client: GCE API client,
  project: a project,
  zone: the zone of the instance(s) being created,
  machine_type_name: The machine type of the instance being created.

Returns:
  Nothing. Function acts as a bound checker, and will raise an exception from
    within the function if needed.

Raises:
  utils.RaiseToolException if a custom machine type ratio is out of bounds.
custom)machineTypeprojectzoneGet)requestserrors_to_collectzCould not fetch machine type:)error_messageN)messagesapitools_clientComputeMachineTypesGetRequestmachineTypeslistMakeRequestsr
   RaiseToolException)
compute_clientr7   r8   r1   r=   compute	mt_get_pbmt_get_reqserrors_s
             r    CheckCustomCpuRamRatiorJ      s      $$(**'""66%T 7 CI((%;<KF 	##  	$ 	<	=A 
 ?A  #r"   c           	         Uc  [         R                  nUc  Sn[        R                  " [        5      nU H  nUR                  S5      n[        U5      S:X  a  UnUnOL[        U5      S:X  a  [        R                  " SS5      e[        R                  " SSR                  U5      5      eUS:w  a4  [        R                  U5      (       d  [        R                  " SS	U-   5      e[         R                  R                  Xw/5      nX6   R                  U5        M     U(       d  US:w  a  U R                  U/ S
9/$ / n[!        ["        R$                  " U5      5       H-  u  paUR'                  U R                  U[!        U5      S
95        M/     U$ )zBReturns a list of ServiceAccount messages corresponding to scopes.default=r   r   z--scopeszFlag format --scopes [ACCOUNT=]SCOPE,[[ACCOUNT=]SCOPE, ...] is removed. Use --scopes [SCOPE,...] --service-account ACCOUNT instead.zM[{0}] is an illegal value for [--scopes]. Values must be of the form [SCOPE].z--service-accountz>Invalid format: expected default or user@domain.com, received )emailscopes)r   DEFAULT_SCOPEScollectionsdefaultdictrA   splitlenr,   r.   r$   EMAIL_REGEXmatchSCOPESgetextendServiceAccountsortedsix	iteritemsappend)	r=   rO   service_accountaccounts_to_scopesr   partsaccount	scope_uriress	            r    CreateServiceAccountMessagesre      sx   ^%%FO"..t4eKKE
5zQgi	Uq88
   88
 &-) )
 )#K,=,=o,N,N88

J
    $$Y<I&&y17 : 
Oy0##/"#EFF
#.@ ABogJJx&&WVF^&LM C	*r"   c                    U(       d  gU R                  S5      (       d  U R                  S5      (       d  gUR                  U R                  S5      (       a  U R                  OSU R                  S5      (       a  U R                  S9$ SS9$ )z-Create workloadIdentityConfig message for VM.Nidentityidentity_certificate)rg   identityCertificateEnabled)IsKnownAndSpecifiedWorkloadIdentityConfigrg   rh   )argsr=    support_workload_identity_configs      r    #CreateWorkloadIdentityConfigMessagern      s     
*		!	!
 
$$%;<<		(	(		!	!*	-	- }}		!	!"8	9	9 "&!:!:	 
) 
   
) 
 r"   c                 R    U(       a  U R                   R                  U5      nU$ SnU$ )z*Create on-host-maintenance message for VM.N)
Scheduling OnHostMaintenanceValueValuesEnum)r=   maintenance_policyon_host_maintenances      r    CreateOnHostMaintenanceMessagert      s5    "--NN 
 	r"   c                    [        U U5      nU(       d  U	S:X  a  U R                  SUSS9nOU R                  UUS9nU	(       a   U R                  R                  U	5      Ul        U
(       a   U R                  R	                  U
5      Ul        Ub  U R                  US9Ul        Ub  U R                  US9Ul        UbV  U R                  5       Ul
        SU;   a  US   UR                  l        SU;   a!  U R                  US   S9UR                  l        U(       a  [        R                  " U5      Ul        U(       a  UUl        Ub  [#        U5      Ul        U(       a  UUl        U(       a
  US	-  Ul        U(       a   U R                  R+                  U5      Ul        U(       a  UUl        U(       a  UUl        Ub  U R3                  US
9Ul        Ub  UUl        Ub  U R                  US9Ul        U$ )z!Create scheduling message for VM.SPOTFT)automaticRestartonHostMaintenancepreemptible)rw   rx   secondsenabledmaxDurationi  )discardLocalSsd)rt   rp    ProvisioningModelValueValuesEnumprovisioningModel(InstanceTerminationActionValueValuesEnuminstanceTerminationActionDurationmaxRunDurationlocalSsdRecoveryTimeoutSchedulingGracefulShutdowngracefulShutdownr|   r}   r   FormatDateTimeterminationTimenodeAffinitiesintminNodeCpuslocationHintmaintenanceFreezeDurationHours"MaintenanceIntervalValueValuesEnummaintenanceIntervalhostErrorTimeoutSecondsavailabilityDomainSchedulingOnInstanceStopActiononInstanceStopActionskipGuestOsShutdownpreemptionNoticeDuration)r=   rr   ry   restart_on_failurenode_affinitiesmin_node_cpulocation_hintmaintenance_freeze_durationmaintenance_intervalprovisioning_modelinstance_termination_actionhost_error_timeout_secondsmax_run_durationtermination_timelocal_ssd_recovery_timeoutavailability_domaingraceful_shutdown+discard_local_ssds_at_termination_timestampskip_guest_os_shutdownpreemption_notice_durationrs   
schedulings                         r    CreateSchedulingMessager   
  s2   : 7x7IK&&0$$- % J
 $$+- % /J <<=OP   !DD'	
 ( ! ( 1 1:J 1 KJ+)1):):* *; *J& ""*"E"E"GJ%%,=i,Hj!!)))080A0A#M2 1B 1j!!- !&!5!56F!GJ /J .J+J #t+ - >> 	" "  )CJ&$7J!0<&.&M&MC 'N 'J# '%;J"+*2*;*;* +< +J' 
r"   c                 (    U R                  UUUS9nU$ )z-Create shieldedInstanceConfig message for VM.)enableSecureBoot
enableVtpmenableIntegrityMonitoring)ShieldedInstanceConfig)r=   enable_secure_bootenable_vtpmenable_integrity_monitoringshielded_instance_configs        r    #CreateShieldedInstanceConfigMessager   {  s+    
 &<<) ; = =
 
"!r"   c                 $    U R                  US9nU$ )z7Creates shieldedInstanceIntegrityPolicy message for VM.)updateAutoLearnPolicy)ShieldedInstanceIntegrityPolicy)r=   update_auto_learn_policy"shielded_instance_integrity_policys      r    ,CreateShieldedInstanceIntegrityPolicyMessager     s&     (0'O'O4 (P (6$ 
,+r"   c           	      `   U (       a  U(       d  gSS/nSS/nU R                  SS5      nU R                  SS5      nU(       a2  XB;  a-  [        R                  " SS	U S
SR                  U5       S35      eU(       a3  XS;  a-  [        R                  " SSU S
SR                  U5       S35      egg)at  Validates flags specifying SVSM config.

Args:
  svsm_args: The flags specifying SVSM config.
  support_snp_svsm: Whether SVSM is supported.

Returns:
  Nothing. Function acts as a validator, and will raise an exception from
    within the function if needed.

Raises:
  calliope_exceptions.RequiredArgumentException when the flags are not
    specified or are not valid.
N	EPHEMERAL	NO_CC_TPM
RESTRICTEDUNRESTRICTEDtpmsnp-irqz--svsm-configz#Unexpected confidential TPM type: [z]. Legal values are [z, z].zUnexpected SEV SNP IRQ mode: [)rX   r,   r.   join)	svsm_argssupport_snp_svsmtpm_choicessnp_irq_choicesr   snp_irqs         r    ValidateSvsmConfigr     s      
*
k*+!>2/eT"#MM)T*'S#

6
6
-cU 3IIk"#2	' 
 /

6
6
(	 2IIo&'r	+  0Wr"   c                    [        U S5      (       a  U R                  S5      (       a  U(       d  g[        U R                  U5        U R                  (       a  U R                  R	                  SS5      OSnU R                  (       a  U R                  R	                  SS5      OSnUR
                  R                  U5      nUR
                  R                  U5      nUR                  UUS9$ )z2Create confidentialParavisorConfig message for VM.svsm_configNr   !CONFIDENTIAL_TPM_TYPE_UNSPECIFIEDr   SEV_SNP_IRQ_MODE_UNSPECIFIED)confidentialTpmTypesevSnpIrqMode)hasattrIsSpecifiedr   r   rX   ConfidentialParavisorConfig"ConfidentialTpmTypeValueValuesEnumSevSnpIrqModeValueValuesEnum)rl   r=   r   r   r   confidential_tpm_typesev_snp_irq_modes          r    (CreateConfidentialParavisorConfigMessager     s     $
&
&d.>.>}.M.MT%%'78 
		 5"EF.  
		 9&DE) 
 **MM
  **GG
 
 
	-	-/$ 
. 
 r"   c                    SnSnSn[        US5      (       aA  UR                  S5      (       a+  [        UR                  [        5      (       a  UR                  nU(       a  [        US5      (       a  UR                  S5      (       as  [        UR
                  [        R                  5      (       aJ  U R                  R                  UR
                  5      nU(       d  SU R                  R                  ;   a  SnSn[        XU5      nUb  Ub  U R                  UUS9nU$ Ub  U R                  US9nU$ Ub  [        R                  " SS5      eUb  U R                  US	9nU$ )
z1Create confidentialInstanceConfig message for VM.Nconfidential_computeconfidential_compute_typeTDX)confidentialInstanceTypeconfidentialParavisorConfig)r   z--confidential-compute-typezEConfidential compute type must be specified when using --svsm-config.)enableConfidentialCompute)r   r   
isinstancer   boolr   r\   string_typesConfidentialInstanceConfig'ConfidentialInstanceTypeValueValuesEnumr   r,   r.   )	r=   rl   !support_confidential_compute_type%support_confidential_compute_type_tdxr    confidential_instance_config_msgenable_confidential_computeconfidential_instance_type!confidential_paravisor_config_msgs	            r    !CreateConfidentialInstanceMessager     s   
 &*" $#d*++
-..**D11"&";";'d/00
233//1A1ABB++	0	0**
, 
 2//44	6 %)!#' &N
&'# !,
+
7'/'J'J!;$E (K ($& 
*) "-'/'J'J!; (K ($ 
*) )4

6
6%	 
 #.'/'J'J"= (K ($ 
*)r"   c	                    U R                  5       n	Ub  Xl        Ub  X)l        Ub  X9l        Ub  XIl        Ub  XYl        Ub.  U R                   R                  UR                  5       5      U	l        Ub  Xyl	        Ub  Xl
        U	$ )z7Create AdvancedMachineFeatures message for an Instance.)AdvancedMachineFeaturesenableNestedVirtualizationthreadsPerCorenumaNodeCountvisibleCoreCountenableUefiNetworking(PerformanceMonitoringUnitValueValuesEnumupperperformanceMonitoringUnitenableWatchdogTimer	turboMode)
r=   enable_nested_virtualizationthreads_per_corenuma_node_countvisible_core_countenable_uefi_networkingperformance_monitoring_unitenable_watchdog_timer
turbo_modefeaturess
             r    $CreateAdvancedMachineFeaturesMessager     s     --/(!-*F'!. ,# 2'$:! ,)1)I)I)r)r#))+*H& &#8 #	/r"   c                     U[         R                  R                  :X  a(  U R                  USU[        R
                  " U5      S.S9$ U R                  USUUS.S9$ )aL  Parses disk resources.

Project and zone are ignored if a fully-qualified resource name is given, i.e.
  - https://compute.googleapis.com/compute/v1/projects/my-project
        /zones/us-central1-a/disks/disk-1
  - projects/my-project/zones/us-central1-a/disks/disk-1

If project and zone cannot be parsed, we will use the given project and zone
as fallbacks.

Args:
  resources: resources.Registry, The resource registry
  name: str, name of the disk.
  project: str, project of the disk.
  zone: str, zone of the disk.
  type_: ScopeEnum, type of the disk.

Returns:
  A disk resource.
compute.regionDisksr7   region
collectionparamscompute.disksr7   r8   )compute_scopes	ScopeEnumREGIONParser
   ZoneNameToRegionName)r   r   r7   r8   type_s        r    ParseDiskResourcer  C  ss    * n&&---??(006
    ??"
   r"   c                     U R                  UR                  SS9nU(       a  U$   U R                  UR                  SS9nU(       a  U$  [        R
                  " SR                  UR                  UR                  5      5      e! [        R                  [        R                  4 a     Nf = f! [        R                  [        R                  4 a     Nf = f)a  Parses the source disk resource of an AttachedDisk.

The source of an AttachedDisk is either a partial or fully specified URL
referencing either a regional or zonal disk.

Args:
  resources: resources.Registry, The resource registry
  attached_disk: AttachedDisk

Returns:
  A disk resource.

Raises:
  InvalidResourceException: If the attached disk source cannot be parsed as a
      regional or zonal disk.
r   )r  r  z^Unable to parse disk's source: [{0}] of device name: [{1}], try using `--device-name` instead.)r  sourcecloud_resources WrongResourceCollectionExceptionRequiredFieldOmittedExceptionInvalidResourceExceptionr$   
deviceName)r   attached_diskdisks      r    !ParseDiskResourceFromAttachedDiskr  j  s    "
	??)>  D k 	??=//O?LDk  	00""(&




"
"#	  6633
 	 			 6633
 	 			s"   "B "B/ $B,+B,/$CCc           
         U(       a  [        [        U Vs/ s H  o3R                  SU5      U:H  PM     sn5      (       a  U R                  S5      (       d+  [        R                  " [
        R                  U5      5        U$ U R                  S5      U:w  a5  [        R                  " SSR                  XR                  S5      5      5      eU R                  S5      $ s  snf )z4Helper method to get device-name for a disk message.r   zdevice-namez--container-mount-diskz{Attempting to mount disk named [{}] with device-name [{}]. If being mounted to container, disk name must match device-name.)	filterr   rX   r   warning&_DEFAULT_DEVICE_NAME_CONTAINER_WARNINGr$   r,   r.   )r  r   container_mount_diskds       r    GetDiskDeviceNamer    s    f
2FG2FQUU64 D(2FG 
 88M""	kk8??EFk	-	 D	(88
"J6$/0	  
-	   Hs   C
c                     U[         R                  R                  :X  a  US:w  a  SnX#S.nO6Sn[        U5      nX#S.nO$U[         R                  R                  :X  a  SnX#S.nU R                  UWWS9nU$ )3Parses disk type reference based on location scope.r   zcompute.diskTypesr  zcompute.regionDiskTypesr  r  )r  r	  ZONEGetRegionFromZoner
  r  )	r   	disk_typer7   locationr   replica_zone_cntr  r  disk_type_refs	            r    ParseDiskTyper(    s     n&&+++1&j"5f,j"8,h"7f((///*J 5F//Jv " 7-	r"   c                 d    SR                  U R                  S5      SS 5      R                  5       $ )z1Returns the GCP region that the input zone is in.-N)r   rS   lower)r8   s    r    r#  r#    s)    	$**S/#2&	'	-	-	//r"   c                 2    SnX#S.nU R                  XUS9nU$ )r!  zcompute.storagePoolsr  r  )r  )r   storage_poolr7   r%  r  r  storage_pool_refs          r    ParseStoragePoolr0    s0    %*1&__& %  
r"   c                 &    [        S U  5       5      $ )z=Returns True if the user has specified an existing boot disk.c              3   D   #    U  H  oR                  S S5      v   M     g7f)bootFN)rX   ).0r  s     r    	<genexpr>&UseExistingBootDisk.<locals>.<genexpr>  s     7XXfe$$s    )any)diskss    r    UseExistingBootDiskr9    s    	77	77r"   c                 `    [        U Vs/ s H  o R                  U5      PM     sn5      $ s  snf N)r7  r   )rl   destsdests      r    IsAnySpecifiedr>    s(    	7t$7	887s   +c                     U R                  S5      (       d  g UR                  X[        R                  R                  R
                  S9nUR                  5       $ )Nsource_instance_template)default_scope)r   ResolveAsResourcer   compute_scoper	  GLOBALSelfLink)rl   r   source_instance_template_argrefs       r    GetSourceInstanceTemplaterH    sQ    			4	5	5$66
U%8%8%B%B%I%I 	7 	# 
r"   c                 
    U S L$ r;   )r@  s    r    GetSkipDefaultsrK    s     
"	--r"   c                    SnU(       a!  [         R                  " XR                  U5      nSnU(       a  U R                  nSn[	        U S5      (       a  U R
                  nSn[	        U S5      (       a"  U R                  S5      (       a  U R                  nSn[	        U S5      (       a"  U R                  S5      (       a  U R                  nSn[	        U S5      (       a"  U R                  S5      (       a  U R                  nSn[	        U S5      (       a"  U R                  S5      (       a  U R                  nSnU(       a  [	        U S5      (       a  U R                  nSnU(       a  [	        U S5      (       a  U R                  nSnU(       a3  [	        U S	5      (       a"  U R                  S	5      (       a  U R                  n[        X	5      nSnU(       a  [	        U S
5      (       a  U R                  nSnU(       a  [	        U S5      (       a  U R                   nSnU(       a  U R#                  S5      (       a  U R$                  nSnU R#                  S5      (       a  [	        U S5      (       a  U R&                  nSnU
(       a"  U R#                  S5      (       a  U R(                  nSnU(       a  [	        U S5      (       a  U R*                  nU(       a[  [-        U SSSS5      (       dG  U(       d@  U(       d9  U(       d2  U(       d+  U(       d$  U(       d  U(       d  U(       d  U(       d  U(       d  g[/        S0 SUR                  _SU R0                  _SU R2                  _SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_S
U_S	U_SU_SU_SU_SU_SU_6$ )z>Generate a Scheduling Message or None based on specified args.Nr   r   r   r   r   r   r   r   r   r   r   r   r   r   rr   ry   r=   r   r   r   rJ  )sole_tenancy_util%GetSchedulingNodeAffinityListFromArgsr=   r   r   r   r   r   r   r   r   r   r   r   ExtractGracefulShutdownFromArgsr   r   rj   r   r   r   r   r>  r   rr   ry   )rl   clientskip_defaultssupport_node_affinitysupport_min_node_cpusupport_node_project"support_host_error_timeout_secondssupport_max_run_duration"support_local_ssd_recovery_timeoutsupport_graceful_shutdownsupport_skip_guest_os_shutdown"support_preemption_notice_durationr   r   r   freeze_durationr   r   r   r   r   r   r   r   r   r   r   r   r   s                                r    GetSchedulingr\    s    /'MMoo35O,$$L-T?##&&M/T011d6F6F#7% 7%66O
 "&"2"23I"J"J44d())
+,,00 $d122
455"&"B"B#'G
(-* -*!%!@!@'$0B"C"C,,#'G
(-* -*.2.>.>
&/( /(!%!@!@5
 '$0B"C"C,,04-'
9# # 	88 0 	$223GHH00	344
!: : 22#(@(@) ) "88#'G
(- - "&!@!@ 

'


  !("((	  

00
 ""
 ,	

 &
  
 "
 #2
 0
 ,
 #>
 "<
 (
 (
 "<
  .!
" *#
$ 3^%
& 4'
( "<)
 r"   c                     U R                   (       a  S nOU R                  nU(       a  [        U SSSS5      (       d  / $ [        UR                  U R
                  (       a  / US9$ U R                  US9$ )NrO   	no_scopesr_   no_service_account)r=   rO   r_   )r_  r_   r>  re   r=   r^  rO   )rl   rP  rQ  r_   s       r    GetServiceAccountsr`  ~  sr    	O**ON
Hk#46JL LI	%>>R%
' ''+{{%
' 'r"   c                     [         R                  " UR                  U R                  U R                  S9n[
        R                  " U5        U$ )Nmetadatametadata_from_file)r	   ConstructMetadataMessager=   rc  rd  r   ValidateUserMetadata)rl   rP  user_metadatas      r    GetValidatedMetadatarh    s?     99oo}}002- ''6	r"   c                     U(       a  [        U SS5      (       d  g [        R                  " UR                  U R                  U R
                  S9$ )Nrc  rd  rb  )r>  r	   re  r=   rc  rd  )rl   rP  rQ  s      r    GetMetadatarj    sB    
z+?
@
@22224 4r"   c                     [         R                  " U R                  5      n[         R                  " XR                  5        U$ r;  )r
   	BytesToGbboot_disk_sizeWarnIfDiskSizeIsTooSmallboot_disk_type)rl   boot_disk_size_gbs     r    GetBootDiskSizeGbrq    s2    ood&9&9:  !24G4GH	r"   c                     [         R                  R                  U UR                  [        R
                  " U5      S9n[        R                  " U5      nUR                  U5        U$ )N)scope_lister)	r   INSTANCES_ARGrB  r   compute_flagsGetDefaultScopeListerr   ZoneResourceFetcherWarnForZonalCreation)rl   rP  holderinstance_refszone_resource_fetchers        r    GetInstanceRefsr|    s_    %%77
 66v> 8 @-
 %88@,,];	r"   c                     UR                  XR                  5      n[        R                  R	                  U R
                  SS9n[        R                  " XTUR                  5      nU$ )NF)allow_rsa_encrypted)rB  r   r   CsekKeyStoreFromFile"source_machine_image_csek_key_fileMaybeLookupKeyMessager>   )rl   source_imagerD   ry  machine_image_ref	csek_keysdisk_key_or_nones          r    GetSourceMachineImageKeyr    sc    "44T;K;KL%%..
--5 / J)55N$B$BD	r"   c                 :    U(       + =(       d    [        U SSS5      $ )Nr'   r   r/   )r>  rl   rQ  s     r    CheckSpecifiedMachineTypeArgsr    s"    
 N
~|_
MOr"   c                 N    [        X5      n[        XXG5        [        X'X4U5      nU$ )z@Create a machine type URI for given args and instance reference.)CreateMachineTypeNamerJ   ParseMachineType)	rl   rD   resource_parserr7   r%  r   r0   r1   machine_type_uris	            r    CreateMachineTypeUrir    s4     ,DG (N%o&-@	r"   c           	          U R                   nU R                  nU R                  n[        U SS5      n[        U SS5      n[	        UUUUUUS9nU$ )zACreate a machine type name for given args and instance reference.custom_vm_typeNcustom_extensions)r'   r   r/   r%   r&   r0   )r'   r   r/   getattrr3   )rl   r0   r'   r   r/   r&   r%   r1   s           r    r  r    sh     "",*$$-D*D1')40# +!
/1 
r"   c                     U[         R                  R                  :X  a  SnX#S.nO$U[         R                  R                  :X  a  SnX#S.nU R	                  UWWS9R                  5       nU$ )z/Returns the location-specific machine type uri.zcompute.machineTypesr  zcompute.regionMachineTypesr  r  r  r	  r"  r
  r  rE  )r  r1   r7   r%  r   r  r  r  s           r    r  r    sr     n&&+++'J 3F((///-J 5F$**Jv + ??Gxz 	r"   c                 D   SnU R                  S5      (       a+  U R                  (       a  [        R                  R                  nU(       aU  U R                  S5      (       a?  U R
                  b2  [        [        R                  U R
                  R                  5       5      nU$ )z1Returns the CONFIDENTIAL_VM_TYPES of the machine.Nr   r   )r   r   r   CONFIDENTIAL_VM_TYPESSEVr   r  r   )rl   r   r0   s      r    GetConfidentialVmTyper    s    	,--$2K2K$::>>'


6
7
7

(
(
4"9#B#B#'#A#A#G#G#IK 
r"   c                 V    U(       a  U R                  S5      (       d  g U R                  $ )Ncan_ip_forward)r   r  r  s     r    GetCanIpForwardr    s%    4++,<==			r"   c                 l    U R                   (       a#  UR                  R                  U R                   S9$ g )N)items)tagsr=   Tags)rl   rP  s     r    GetTagsr    s(    	YY??dii00	r"   c                 ^   UR                   R                  R                  nU(       a   UR                   R                  R                  nU R                  (       aO  U" [        [        R                  " U R                  5      5       VVs/ s H  u  pEUR                  XES9PM     snnS9$ gs  snnf )z%Gets labels for the instance message.keyvalueadditionalPropertiesN)	r=   InstanceLabelsValueInstancePropertieslabelsr[   r\   r]   AdditionalProperty)rl   rP  instance_propertieslabels_valuer  r  s         r    	GetLabelsr    s    ))55,??55AAL	[[ t{{!;<.<JC 	''C'=<.   
	.s   B)
c                     U[         R                  R                  :X  a  SnX#S.nO$U[         R                  R                  :X  a  SnX#S.nUR	                  U WWS9R                  5       nU$ )z5Returns accelerator type ref based on location scope.zcompute.acceleratorTypesr  zcompute.regionAcceleratorTypesr  r  r  )accelerator_type_namer  r7   r%  r   r  r  accelerator_types           r    ParseAcceleratorTyper    ss     n&&++++J 3F((///1J 5F$**
6 + CCK8: 	r"   c                     U (       a[  U(       aT  U(       aM  U(       a#  UR                  USXS.S9nUR                  5       $ UR                  USSU 0S9nUR                  5       $ g)z-Returns snapshot URI based on location scope.zcompute.regionSnapshotsr  r  zcompute.snapshotsr7   Nr  rE  )user_projectsnapshotr  r  snapshot_refs        r    ResolveSnapshotURIr  ,  su    h?$**
.)< + l
 ""$$"((&<( ) *L   ""	r"   c                 t    U (       a1  U(       a*  U(       a#  UR                  USSU 0S9nUR                  5       $ g )Nzcompute.instantSnapshotsr7   r  r  )r  instant_snapshotr  instant_snapshot_refs       r    ResolveInstantSnapshotURIr  ?  sB    &?*00-<( 1 
  ((**	r"   c                    U R                  S5      (       a  UR                  R                  R                  nSn/ nSUR                  0nU(       a(  UR                  UR                  UR                  S.5        U R                  S:X  a  UR                  nO>U R                  U;   a"  X`R                     n[        nU R                  /nOUR                  nUR                  R                  UU=(       d    SUS9$ g)z=Returns the message of reservation affinity for the instance.reservation_affinityNspecific)zspecific-then-any-reservationzspecific-then-no-reservationnone)consumeReservationTyper  values)r   r=   ReservationAffinity%ConsumeReservationTypeValueValuesEnumSPECIFIC_RESERVATIONupdateSPECIFIC_THEN_ANY_RESERVATIONSPECIFIC_THEN_NO_RESERVATIONr  NO_RESERVATION_RESERVATION_AFFINITY_KEYreservationANY_RESERVATION)rl   rP   support_specific_then_x_affinity	type_msgsreservation_keyreservation_valuesspecific_affinities_mapreservation_types           r    GetReservationAffinityr  J  s   	,--++	.	.  O 	I22 ($$55 44& 	   F*"11		"	"&=	=01J1JK 2o ,,-"22??../#t! / # #
 
r"   c                    [        U S/ 5      nUR                  R                  5       nU HV  nUR                  SS5      R	                  5       nU(       d  M,  UR                  R                  R                  U5      Ul        MX     U$ )z6Get NetworkPerformanceConfig message for the instance.network_performance_configsztotal-egress-bandwidth-tier )r  r=   NetworkPerformanceConfigrX   r   'TotalEgressBandwidthTierValueValuesEnumtotalEgressBandwidthTier)rl   rP  network_perf_argsnetwork_perf_configsconfig
total_tiers         r    GetNetworkPerformanceConfigr  w  s     d$A2FAAC!f92>DDFJz6<oo6^6^  7G  7G
73 " 
r"   c                    SnU(       a~  [        U S5      (       a$  U R                  S5      (       a  SU R                  0n[        U S5      (       a8  U R                  S5      (       a"  Uc  SU R                  0nU$ U R                  US'   U$ )z%Extracts graceful shutdown from args.Nr   r|   graceful_shutdown_max_durationr}   )r   r   r   r  )rl   rX  r   s      r    rO  rO    s     t())d.>.>/ / %d&<&<=t5664;K;K(< < 
	"*D,O,OP 
 ,0+N+N-(	r"   c                    UR                   R                  5       nU R                  S5      (       a  [        R                  " U R
                  5      nUbj  UR                   R                  R                  nU" [        [        R                  " U5      5       VVs/ s H  u  pVUR                  XVS9PM     snnS9Ul        U R                  S5      (       av  [        U S5      (       a&  U R                  S5      (       a  U R                  S:w  a  [        R                   " SS5      eUR                   R#                  U R$                  S	9Ul        U$ s  snnf )
z)Create a Params message for the instance.resource_manager_tagsr  r  request_valid_for_durationr   
FLEX_STARTz--request_valid_for_durationzS[--request_valid_for_duration] is only supported for FLEX_START provisioning model.rz   )r=   InstanceParamsrj   r   GetResourceManagerTagsr  ResourceManagerTagsValuer[   r\   r]   r  resourceManagerTagsr   r   r   r,   r.   r   r  requestValidForDuration)rl   rP  r  ret_resource_manager_tagsresource_manager_tags_valuer  r  s          r    CreateParamsr    sJ    ??))+&	566#::&&	
 
 !,
//
(
(
A
A " $?
 !'s}}5N'O P	  !Q*# *<< =  !Q	 $f  
:;;D.// 455""l288
(!  &,__%=%=// &> &F" 
-1 s   E
z'compute.googleapis.com/reservation-name)FF)TFN)NNNNNNNNNNNNNNNN)T)NNNNNNNN)r   )	FTFTFFFFFr;  )F)T__doc__
__future__r   r   r   rQ   r   googlecloudsdk.api_lib.computer   r   r   r	   r
   r   googlecloudsdk.callioper   r,   "googlecloudsdk.command_lib.computer   ru  r   r   r  ,googlecloudsdk.command_lib.compute.instances/googlecloudsdk.command_lib.compute.sole_tenancyr   rM  googlecloudsdk.corer   r   r  googlecloudsdk.core.utilr   r\   compilerU   r  r!   r(   r3   rJ   re   rn   rt   r   r   r   r   r   r   r   r  r  r  r(  r#  r0  r9  r>  rH  rK  r\  r`  rh  rj  rq  r|  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rO  r  r  rJ  r"   r    <module>r     s   O &  '  	 4 ; 5 9 0 5 E E J F > U # < * 
jjNO= '
04 "!&.2;|AD*Z(  $ $##04#)nb
" KO,#LD8*z "& $+\$N-`!, FG(0
8
9.  '+"',##(',Nb'4O /3&* 
&*Z*(V F r"   