
                            d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 dd	lm
Z
 dd	lm
Z dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ 	 	 	 	 d*dZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d+dZ	 	 d,dZ 	 	 	 	 	 	 	 	 	 	 	 	 	 d-dZ!	 	 	 	 	 	 	 	 	 	 d.dZ"dZ#	 	 	 d/dZ$	 	 	 	 d0dZ%	 	 	 	 d1dZ&	 	 	 	 	 d2dZ'd Z(	 d3dZ)d Z*	 	 	 d4dZ+	 	 	 	 d5d Z,d! Z-	 d6d"Z.d# Z/	 	 	 d7d$Z0	 	 	 d8d%Z1d& Z2d' Z3d( Z4	 d3d)Z5y)9z8Convenience functions for dealing with instances create.    )absolute_import)division)unicode_literals)
csek_utils)image_utils)instance_utils)	kms_utils)utils)messages)
exceptions)scope)flags)labels_util)log)yamlc                     g d}|r|j                  ddg       |r|j                  g d       |r|j                  dg       |rt        j                  | g| syy)z6Checks if relevant disk arguments have been specified.)	local_ssdboot_disk_typeboot_disk_device_nameboot_disk_auto_deleteboot_disk_interfacediskrequire_csek_key_create)create_diskboot_disk_kms_keyboot_disk_kms_projectboot_disk_kms_locationboot_disk_kms_keyringlocal_nvdimmFT)extendr   IsAnySpecified)argssupport_disksskip_defaultssupport_kmssupport_nvdimmflags_to_checks         <lib/googlecloudsdk/api_lib/compute/instances/create/utils.pyCheckSpecifiedDiskArgsr)   $   sq    . !     >*+

'
'
>~
>	    Nc                 v   g }|r| j                   }g }|r"t        |||| j                  xs g |||||	      }t        d,i d|d|d|dt	        | dg       d|d|d	|d
|d|d|d|d|d|d|d|d|d|d|d|d|}g }|rt        | ||j                  |||      }t        | ||j                  ||||      } |
rEd}!|r|r\| j                  P| j                  t        j                  dd      t        j                  || j                  || j                        }!n"t        j                  || j                  |      }!d}"|r"t        j                  || j                  |      }"t!        d,i d|d|d| j"                  d| j$                  d| j&                  d |d!|r| j(                  ndd"|d#|	d|d|d	|d|d|d$| d%|!d&| j*                  d'| j,                  d|d(|"d)|d*| j.                  }#|#g|z   }|r&|d+   j0                  r|j3                  d+      }#|#g|z   }||z   |z   | z   S )-z,Creates disk messages for a single instance.)		resourcescompute_client	csek_keysdisksprojectlocationr   container_mount_diskuse_disk_type_urir-   r,   r.   create_disksr   r0   r1   r   holder
enable_kmsenable_snapshotsr2   enable_source_snapshot_csekenable_image_cseksupport_replica_zonesr3   support_multi_writerenable_source_instant_snapshots#support_enable_confidential_computesupport_disk_labelssupport_source_snapshot_regionNz--source-snapshot-regionzJCannot set [--source-snapshot-region] without setting [--source-snapshot].)user_projectsnapshotresource_parserregion)r@   rA   rB   r@   instant_snapshotrB   	disk_typedisk_device_namedisk_auto_deletedisk_size_gbr   	image_uriinstance_namekms_argssnapshot_uridisk_provisioned_iopsdisk_provisioned_throughputinstant_snapshot_urisupport_source_instant_snapshotdisk_interfacer    )r2   $CreatePersistentAttachedDiskMessagesr   "CreatePersistentCreateDiskMessagesgetattrCreateLocalNvdimmMessagesr   CreateLocalSsdMessagessource_snapshot_regionsource_snapshotcalliope_exceptionsBadArgumentExceptionr   ResolveSnapshotURIResolveInstantSnapshotURIsource_instant_snapshot$CreateDefaultBootAttachedDiskMessager   r   r   r   boot_disk_provisioned_iops boot_disk_provisioned_throughputr   bootpop)$r"   r0   r1   r   r-   rB   rJ   r5   boot_disk_size_gbrK   create_boot_diskr.   r%   r&   support_source_snapshot_cseksupport_boot_snapshot_urisupport_image_csek#support_match_container_mount_diskssupport_create_disk_snapshots!support_persistent_attached_disksr:   r3   r;   rQ   !support_boot_instant_snapshot_urir=   r>   r?   r2   persistent_diskspersistent_create_diskslocal_nvdimms
local_ssdsboot_snapshot_uriboot_instant_snapshot_uri	boot_disks$                                       r(   CreateDiskMessagesru   H   s   @ (44&,%)))/r!5/		1  ? #  43	
      5 0 #? + 2 *  0!" 'F#$ +N%& .'( &D). --o~66%M &
*  
())5'#88(& 
 +== ))+..	
 +== ))+
 !%("0"J"J77)# 5 %! %% 33	
 33 ' -6D((4  $      !" #$ '%& #=='( %)$I$I)* ,+, 7-. )H/0 //1I4 "{%55 !8!;!@!@'++A.I!{%55	3	3m	Cj	PPr*   c	                    g }	|j                   }
|j                  }|D ]#  }|j                  d      }|j                  dd      }|dk(  r!|
j                  j                  j
                  }n |
j                  j                  j                  }|j                  dd      }|j                  dd      }d|v r#|d   dk(  rt        j                  j                  }nt        j                  j                  }t        j                  | ||||      }|j                  d	      }|rt        j                  |||      }d
|i}ni }t        j                  |||      }|j!                         }|t        j                  j                  k(  r|s|} |
j                  d||||||
j                  j"                  j$                  |d|}|j                  d      r\|j                  d      dk(  r!|
j                  j&                  j(                  }n |
j                  j&                  j*                  }||_        |r|g|	z   }	|	j/                  |       & |	S )zFReturns a list of AttachedDisk messages and the boot disk's reference.namemoderwrc   Fauto-deleter   regionalzforce-attachdiskEncryptionKey)
autoDeleterc   
deviceNamerx   sourcetypeforceAttach	interfaceSCSIrS   )r   apitools_clientgetAttachedDiskModeValueValuesEnum
READ_WRITE	READ_ONLYcompute_scopes	ScopeEnumREGIONZONEr   ParseDiskResourcer   MaybeLookupKeyMessageGetDiskDeviceNameSelfLinkTypeValueValuesEnum
PERSISTENTInterfaceValueValuesEnumr   NVMEr   append)r,   r-   r.   r/   r0   r1   r   r2   r3   disks_messagesr   computer   rw   
mode_valuerx   rc   auto_deletedisk_refforce_attachdisk_key_or_nonekwargsdevice_namer   attached_diskr   s                             r(   rT   rT      s0    .$$(**'d88FD &$'JT""66AAd""66@@d88FE"D((=%0K$4=J6&&--e&&++e//	408%AH88N+L#99
Xw(#%56ff 2243GIK F((---6Gf)H)) ""66AA  M xx	+	&	())BBGG	))BBGG	 )m %7nM*m p 
r*   c                    g }| j                   }| j                  }|xs g D ]  }|j                  d      }|j                  dd      }|dk(  r!|j                  j                  j
                  }n |j                  j                  j                  }|j                  dd      }t        j                  |j                  d            }|j                  dg       }|j                  d      }|r7|r7t        j                  |||||t        |      	      } | j                         }nd
}|j                  d      }!|j                  d      }"|j                  d      }#|j                  d      }$d
}%|!s|"r1t        j                  | |      }&|&j                  ||!|"|#d|$|      \  }%}'d
}(d
})|rHt!        j"                  |||%g|      }(|r-|j%                  |dd|i      }*t!        j&                  ||*|      })|rt)        j*                  |||)      })|j-                  ||j                  d      |%|||(      }+|rQ|rOg },|D ]A  }-|j.                  j%                  |-dd|i      }.|,j1                  |.j                                C |,|+_        |	r|j                  d      }/|rT|j                  d      C|j                  d      }0|/t5        j6                  dd      t        j8                  |/|||0      }1nt        j8                  |/||      }1|1rd
|+_        |1|+_        |j                  d      }2|2r|2|+_        |r|j                  d      }3|3r|3|+_         |r|j                  d      }4|4r|4|+_!        |r@|j                  d       }5t        jD                  ||5|!      }6|6rd
|+_        d
|+_        |6|+_#        |j                  d"d      }7|j                  d#      }8|r	|8rd|+_$        |j                  d$      }9|r	|9rd|+_%        |j                  d%      }:|:r|:|+_&        |j                  d&      };|;r|;|+_'        |j                  d'      }<|<r/t        jP                  ||<||      }=|=j                         }>|>|+_)        |j                  d(      }?|?r |j,                  jU                  |?      |+_+        |rtY        jZ                  |j                  d)            }@|@rZ|j,                  j]                         }A@j_                         D BCcg c]  \  }B}CAja                  |B|C*       c}C}BA_1        |A|+_2        t        jf                  |||
      }D|j                  ||7|D|+||j                  jh                  jj                  |)+      }E|j                  d,      r\|j                  d,      d-k(  r!|j                  jl                  jn                  }Fn |j                  jl                  jp                  }FFE_9        |7rEg|z   }|j1                  E        |S c c}C}Bw ).a	  Returns a list of AttachedDisk messages for newly creating disks.

  Args:
    compute_client: creates resources,
    resources: parser of resources,
    csek_keys: customer suplied encryption keys,
    create_disks: disk objects - contains following properties * name - the name
      of disk, * description - an optional description for the disk, * mode -
      'rw' (R/W), 'ro' (R/O) access mode, * disk-size - the size of the disk, *
      disk-type - the type of the disk (HDD or SSD), * image - the name of the
      image to initialize from, * image-csek-required - the name of the CSK
      protected image, * image-family - the image family name, * image-project -
      the project name that has the image, * auto-delete - whether disks is
      deleted when VM is deleted, * device-name - device name on VM, *
      source-snapshot - the snapshot to initialize from, *
      source-snapshot-csek-required - CSK protected snapshot, *
      source-instant-snapshot - the instant snapshot to initialize from, *
      disk-resource-policy - resource policies applied to disk. *
      enable_source_snapshot_csek - CSK file for snapshot, * enable_image_csek -
      CSK file for image
    project: Project of instance that will own the new disks.
    location: Location of the instance that will own the new disks.
    scope: Location type of the instance that will own the new disks.
    holder: Convenience class to hold lazy initialized client and resources.
    enable_kms: True if KMS keys are supported for the disk.
    enable_snapshots: True if snapshot initialization is supported for the disk.
    container_mount_disk: list of disks to be mounted to container, if any.
    enable_source_snapshot_csek: True if snapshot CSK files are enabled
    enable_image_csek: True if image CSK files are enabled
    support_replica_zones: True if we allow creation of regional disks
    use_disk_type_uri: True to use disk type URI, False if naked type.
    support_multi_writer: True if we allow multiple instances to write to disk.
    support_image_family_scope: True if the zonal image views are supported.
    enable_source_instant_snapshots: True if instant snapshot initialization is
      supported for the disk.
    support_enable_confidential_compute: True to use confidential mode for disk.
    support_disk_labels: True to add disk labels.
    support_source_snapshot_region: True to use source snapshot region.

  Returns:
    list of API messages for attached disks
  rw   rx   ry   rz   Tsizezreplica-zonesr   )replica_zone_cntNimagezimage-familyzimage-projectimage_family_scopeF)r@   r   image_familyimage_projectreturn_image_resourcer   support_image_family_scopecompute.diskszone
collectionparamsdescription)diskNamer   sourceImage
diskSizeGbdiskTypesourceImageEncryptionKeyzcompute.zonesr0   zsource-snapshotzsource-snapshot-regionzFCannot set [source-snapshot-region] without setting [source-snapshot].)rA   r@   rB   rC   )rA   r@   rB   zdisk-resource-policy
image_cseksource_snapshot_csekzsource-instant-snapshotrD   rc   zmulti-writerzconfidential-computezprovisioned-iopszprovisioned-throughputzstorage-poolarchitecturelabels)keyvalue)r}   rc   r~   initializeParamsrx   r   r|   r   r   ):r   r   r   r   r   r   r   r
   	BytesToGbr   ParseDiskTypelenr   r   ImageExpanderExpandImageFlagr   MaybeLookupKeyMessagesByUriParser   r	   MaybeGetKmsKeyFromDictAttachedDiskInitializeParamsr,   r   replicaZonesr[   r\   r]   r   sourceSnapshotresourcePoliciesimageKeyFilesnapshotKeyFiler^   sourceInstantSnapshotmultiWriterenableConfidentialComputeprovisionedIopsprovisionedThroughputParseStoragePoolstoragePoolArchitectureValueValuesEnumr   r   ValidateAndParseLabelsLabelsValueitemsAdditionalPropertyadditionalPropertiesr   r   r   r   r   r   r   r   )Gr-   r,   r.   r4   r0   r1   r   r5   r6   r7   r2   r8   r9   r:   r3   r;   r   r<   r=   r>   r?   r   r   r   r   rw   r   rx   r   rI   replica_zonesrF   disk_type_refimg
img_familyimg_projectr   rJ   image_expander_	image_keydisk_keyr   initialize_paramsnormalized_zonesr   zone_refsnapshot_namesnapshot_regionattached_snapshot_uripoliciesimage_key_filesnapshot_key_fileinstant_snapshot_nameattached_instant_snapshot_urirc   multi_writerenable_confidential_computeprovisioned_iopsprovisioned_throughputstorage_poolstorage_pool_refstorage_pool_uridisk_architecturedict_labelslabels_valuer   r   r   r   r   sG                                                                          r(   rU   rU   /  s=   B .$$(**' b d88FD &$'JT""66AAd""66@@d((=$/K??488F#34LHH_b1M I	&44 /
 "**,	i
((7
C.)J((?+K"67I
j"00Kn#33!# %/%? 4 Ali IH88
YW6i	??_fh5G # I33Ix4;= 11$(Kh ==HH]+!* > , $##))_i5I * K 1 1 34   (8$hh01m
(hh/0<((#;< #88&$  !/ A A" %"	!
 !/ A A" %!

 
(,%+@(xx./H+3(xx-n	)7&"((#9:	,=)&"hh'@A&4&N&N0#'#
 
'(,%+/(2O/88FE"D88N+L&*#"&((+A"B*/J481xx 23*:'!XX&>?0F-88N+L'88
\7H *224&6#0

/
/
K
K $ 66txx7IJk	<<HHJ *//1-
1
U ++5+A1-
)
 $0  2243GIK''*""66AA" ( $K xx	+	&	())BBGG	))BBGG	'k #}~5nK(K !N 
=-
s   *W1c           
         | j                   }| j                  }|r,|r,t        j                  |||	|
|      }|j	                         }nd}|rg|xs |}|j                  |d|	|
d      }t        j                  |j                  ||      |      }t        j                  |||g|      \  }d|i}d|i}ni }i }|}|r/t        j                  |||j                  dd      d      }|rd|i} |j                  d|||d	|} ||| _        ||| _        |rd| _        |rd| _        || _        n|rd| _        d| _        || _         |j&                  d|d|| |j&                  j(                  j*                  |j&                  j,                  j.                  d
|}!|rM|dk(  r!|j&                  j0                  j2                  }"n |j&                  j0                  j4                  }"|"|!_        |!S )z=Returns an AttachedDisk message for creating a new boot disk.Nr   )r0   r   r   r   r|   T)boot_disk_prefix)r   r   r   )r}   rc   r~   r   rx   r   r   rS   )r   r   r   r   r   r   r   MaybeToMessage	LookupKeyr   r	   MaybeGetKmsKeyr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )#r-   r,   rF   rG   rH   rI   r   rJ   rK   r0   r1   r   r.   rL   r6   rM   r3   rN   rO   rP   rQ   rR   r   r   r   effective_boot_disk_namer   r   image_key_or_nonekwargs_init_parmskwargs_diskkms_keyr   boot_attached_diskr   s#                                      r(   r`   r`   >  s^   2 $$(**'$229i3:HeMm((*iI( !1 AM "
  H "00H&=>I 	..y)09{G	E 45FG&(89KK/&&+T2	G
 ('2k;h;;  		 &(=% ,.I+$(!&04-'3$$(!'+$.B+,x,, !)(  44??  44?? 	 ''@@EEi''@@EEi#, 	r*   z
aep-nvdimmc           	          g }t        | dg       xs g D ]2  }t        |||j                  d      |||      }|j                  |       4 |S )z+Create messages representing local NVDIMMs.r   r   )rV   _CreateLocalNvdimmMessager   r   )	r"   r,   r   r1   r   r0   rp   local_nvdimm_diskr   s	            r(   rW   rW     sb     -"4<BB,Y->-B-B6-J-5ugGL &	 C
 
r*   c           	         |r.t        j                  | t        |||      }|j                         }nt        }|j	                  |j                  j
                  j                  d|j                  j                  j                  |j                  j                  j                  |j                  |            }|t        j                  |      |_        |S )z-Create a message representing a local NVDIMM.Tr   )r   r}   r   rx   r   )r   r   NVDIMM_DISK_TYPEr   r   r   SCRATCHr   NVDIMMr   r   r   r
   r   r   )	r,   r   
size_bytesr1   r   r0   r   rF   r   s	            r(   r  r    s     "00<L18(EKM&&(I I&&  44<<%%>>EE  44??<< =  ' , #ooj9L	r*   c                     g }t        | dg       xs g D ]S  }t        |||j                  d      |j                  d      |j                  d      ||||	      }	|j                  |	       U |S )z(Create messages representing local ssds.r   zdevice-namer   r   )rV   _CreateLocalSsdMessager   r   )
r"   r,   r   r1   r   r0   r3   rq   local_ssd_diskr   s
             r(   rX   rX     s     *k26<"<n&y('5'9'9-'H'5'9'9+'F'5'9'9&'A8',g7H	JI
 i  = 
r*   c	           
         |r,|r*t        j                  | d|||      }	|	j                         }
nd}
|r|j                  j	                  |      nd}|j                  |j                  j
                  j                  d|||j                  j                  j                  |j                  |
            }|t        j                  |      |_        |S )z*Create a message representing a local ssd.z	local-ssdNTr  )r   r}   r~   r   rx   r   )r   r   r   r   r   r   r  r   r   r   r
   r   r   )r,   r   r   r   r  r1   r   r0   r3   r   rF   maybe_interface_enumr   s                r(   r
  r
    s     #"00K18(EKM&&(II 
 44Y?  ##  44<<$  44??<< =  $ )  ??:6I	r*   c                 H   g d}|rt        j                  | g| sg S | j                  rt        ||| j                  |||      S t	        j
                  |j                  || j                  | j                  | j                  |||t        | dd      t        | dd      
      gS )z-Gets network interfaces in bulk instance API.)network_interfacenetworknetwork_tiersubnet
no_address
stack_type)r,   r-   network_interface_argr0   r1   r   r  Nr  )
r,   r-   r  r  r  r0   r1   r   r  r  )r   r!   r  CreateNetworkInterfaceMessagesinstances_utilsCreateNetworkInterfaceMessager,   r  r  r  rV   )	r"   rB   r-   r5   r0   r1   r   r$   	bulk_argss	            r(   GetBulkNetworkInterfacesr  (  s    ) >88J	JI)!%"44  	55&&)LL;; ~t<t\48	
 r*   c           
          t         fdg d      }|rt        j                   g| sg S d}	d}
|rt         dd      }	t         dd      }
t	        j
                  di d|j                  d|d j                  d	 j                  d
 j                  d j                  d|d|d|d j                  d j                  d j                  d j                  dt         dd      dt         dd      dt         dd      dt         dd      dt         dd      d|	d|
dt         dd      dt         dd      gS )zGet network interfaces.c                     t        |       S Nhasattrflagr"   s    r(   <lambda>z&GetNetworkInterfaces.<locals>.<lambda>b  s    74&r*   )addressipv6_network_tieripv6_public_ptr_domainr  r  r  no_public_ptrno_public_ptr_domainprivate_network_ip
public_ptrpublic_ptr_domainr  r  ipv6_addressipv6_prefix_lengthinternal_ipv6_addressinternal_ipv6_prefix_lengthexternal_ipv6_addressexternal_ipv6_prefix_lengthNr-  r.  r,   r-   r  r  r  r#  r0   r1   r   r&  r)  r'  r*  r(  r  r%  r  r$  r/  r0  rS   )filterr   r!   rV   r  r  r,   r  r  r  r#  r&  r)  r'  r*  )r"   clientr5   r0   r1   r   r$   !support_internal_ipv6_reservationnetwork_interface_argsr-  r.  s   `          r(   GetNetworkInterfacesr5  V  s    "&0 >88
# I $&#D*A4H")+T#
 33 $$ ,, 	
 __ ,,    ** __  $88 !22 %T+?F t^T:  ")/G!N!" T<6#$ $D*=tD%& !6'( 'B)* !(.Et L+, '.14'-
 r*   c           
          t         fdg d      }|rt        j                   g| sg S t        j                  di d|j
                  d|d j                  d j                  d j                  d j                  d	|d
|d|dt         dd      dt         dd      dt         dd      dt         dd      dt         dd      dt         dd      dt         dd      dt         dd      dt         dd      dt         dd      dt         dd      dt         dd      dt         dd      dt         dd      dt         dd      dt         dd      dt         dd      gS )z,Get network interfaces in compute Alpha API.c                     t        |       S r  r  r   s    r(   r"  z+GetNetworkInterfacesAlpha.<locals>.<lambda>  s    wtT/Br*   )r#  r$  r%  r  r  r  no_public_dnsr&  r'  r(  
public_dnsr)  r*  r  r  r+  r,  r-  r.  r/  r0  r,   r-   r  r  r  r#  r0   r1   r   r(  Nr  r8  r9  r&  r)  r'  r*  r  r$  r%  r+  r,  r-  r.  r/  r0  rS   )r1  r   r!   r  r  r,   r  r  r  r#  rV   )r"   r2  r5   r0   r1   r   r$   r4  s   `       r(   GetNetworkInterfacesAlphar:    s    ""B E  

'
'
F/E
FI33 $$ ,, 	
 __ ,,    %T+?F t^T:  ot< T<6  ot< T<6   't-CTJ!" $D*=tD#$ T<6%& $D*=tD'( ")/G!N)* t^T:+, %T+?F-. !(.Et L/0 '.14'16 !(.Et L78 '.14'9!
 !r*   c	                 4   g }	|r|D ]  }
|
j                  dd      }d|
v }|
j                  dd      }d}d}|r$|
j                  dd      }|
j                  dd      }d}|rd|
v }|	j                  t        j                  d+i d| d	|d
|
j                  d
d      d|
j                  dd      d|
j                  dd      d|
j                  dd      d|d|d|d|d|d|
j                  dd      d|d|
j                  dd      d|
j                  dd      d|
j                  dd      d|
j                  dd      d|
j                  d d      d!|d"|d#|d$|
j                  d%d      d&|
j                  d'd      d(|
j                  d(d      d)|
j                  d*d              |	S |^t	        j
                  |      }|s|	S |D ]@  }
|
st        j                  |
|j                  j                        }|	j                  |       B |	S ),ad  Create network interface messages.

  Args:
    resources: generates resource references.
    compute_client: creates resources.
    network_interface_arg: CLI argument specifying network interfaces.
    project: project of the instance that will own the generated network
      interfaces.
    location: Location of the instance that will own the new network interfaces.
    scope: Location type of the instance that will own the new network
      interfaces.
    network_interface_json: CLI argument value specifying network interfaces in
      a JSON string directly in the command or in a file.
    support_internal_ipv6_reservation: The flag indicates whether internal IPv6
      reservation is supported.
    support_enable_vpc_scoped_dns: The flag indicates whether VPC scoped DNS is
      supported.

  Returns:
    list, items are NetworkInterfaceMessages.
  r#  Nz
no-addressznetwork-tierzinternal-ipv6-addresszinternal-ipv6-prefix-lengthzenable-vpc-scoped-dnsr,   r-   r  r  r(  zprivate-network-ipnic_typeznic-typer  r0   r1   r   alias_ip_ranges_stringaliasesr  r  z
stack-typer$  zipv6-network-tierr%  zipv6-public-ptr-domainqueue_countzqueue-countnetwork_attachmentznetwork-attachmentenable_vpc_scoped_dnsr-  r.  r/  zexternal-ipv6-addressr0  zexternal-ipv6-prefix-lengthvlan
igmp_queryz
igmp-queryrS   )
r   r   r  r  r   loadmessages_utilDictToMessageWithErrorCheckr   NetworkInterface)r,   r-   r  r0   r1   r   network_interface_jsonr3  support_enable_vpc_scoped_dnsresultr   r#  r  r  r-  r.  rA  network_interfacesr  s                      r(   r  r    s   @ &*	i.g9,j]]>48l"$(!	* ).Et L&/mm)4'
# #	& 79 Dmm

7
7  ! +   mmIt4  ]]8T2	 
 "+/CT!J  !}}Z6  $           &/]]9d%C  (  #|T:  !*.A4 H   &/]]*D&! & $--t<' ( "+/CT!J) * %:+ , %:- . +F/ 0 %.MM)4%1 6 +4--/+7 < ==.= > #|T:? "! +| 
- )#9:m'	'CC
^,,==?mm%& ( 
-r*   c                 B   t        | dd      }t        | dd      }| j                  s|s|r"t        ||| j                  ||n|||||
|	      S t        j                  |        |s|	r(|rt        j
                  |        t        | ||||||      S t        | |||||||
      S )z6Validates and retrieves the network interface message.network_interface_from_fileN"network_interface_from_json_string)	r,   r-   r  rH  r0   r1   r   r3  rI  )r3  )rV   r  r  instances_flagsValidatePublicPtrFlagsValidatePublicDnsFlagsr:  r5  )r"   rB   r-   r5   r0   r1   r   r$   support_public_dnssupport_ipv6_assignmentr3  rI  rM  rN  s                 r(   "GetNetworkInterfacesWithValidationrT  :  s     !(.K(,!.'.
0$(8$
 ;()!%"44&2  ;/*K&C  **404	..t4&t^VW'/G G*K	 	r*   c           	          i }|D ]F  }|j                   |vst        | |j                   |||j                               ||j                   <   H |S )z2Creates a mapping of projects to service accounts.)r"   r0   r2  r$   rK   )r0   GetProjectServiceAccountName)r"   instance_refsr2  r$   project_to_sainstance_refs         r(   GetProjectToServiceAccountMapr[  o  sZ    -#l=0,D&&%$))+--mL(() $ 
r*   c                    d}| j                   s| j                  s|j                  j                  d|j                  j                  |      f}g }|j                  |g|      }|sW|d   j                  sHg }dj                  |      }	|r|	dj                  |      z  }	t        j                  j                  |	       || j                   rg n| j                  }| j                  rd}
n| j                  }
|rH| j                  d      s7| j                  d      s&| j                  d	      s| j                  d
      sg }|S t        j                   |j                  ||
      }|S )z5Retrieves service accounts for the specified project.NGet)r0   r   z3There is no default service account for project {}.z" Instance {} will not have scopes.scopes	no_scopesservice_accountno_service_account)r   r^  r`  )r_  r^  r   projectsr   ComputeProjectsGetRequestMakeRequestsdefaultServiceAccountformatr   statusPrintra  r`  IsSpecifiedr   CreateServiceAccountMessages)r"   r0   r2  r$   rK   r^  requesterrorsrJ  scope_warningr`  service_accountss               r(   rV  rV  }  sX    &	 %%..888IKGF  'F3FAY,,MTT
?FF -

'^>>Rt{{F	O**OD,,X6


;
'


,
-


/
0 
	 &BB') 
r*   c                     |j                  d      s"|j                  d      s|j                  d      r6t        j                  | |j                  |j                  |j
                        S y)z1Builds a shielded instance configuration message.shielded_vm_secure_bootshielded_vm_vtpm shielded_vm_integrity_monitoringN)ri  r   #CreateShieldedInstanceConfigMessagerp  rq  rr  )r   r"   s     r(   "BuildShieldedInstanceConfigMessagert    sc    
01
)*
9:==$..0E0E--/ / r*   c                 4    t        j                  | ||||      S )z5Builds a confidential instance configuration message.)r   !CreateConfidentialInstanceMessage)r   r"   !support_confidential_compute_type%support_confidential_compute_type_tdxsupport_snp_svsms        r(   &BuildConfidentialInstanceConfigMessagerz    s%     
	9	9'+	
 r*   c           
          |rRt        j                  ||      }|j                  || j                  | j                  | j
                  d|||      \  }	}
|	S y)z0Retrieves the image uri for the specified image.F)r@   r   r   r   r   confidential_vm_typer   r   N)r   r   r   r   r   r   )r"   r2  rf   r0   rB   r|  r   r   r   rJ   r   s              r(   GetImageUrir}    sg      ..vGN!11jj&&((#1-#= 2 ?LIq  r*   c                     | j                   rd| j                   d   }t        j                  |||||      }t        | j                   j	                  dd            }t        |j                  ||      S g S )z<Returns list of messages with accelerators for the instance.r   count   )acceleratorr   ParseAcceleratorTypeintr   CreateAcceleratorConfigMessagesr   )	r"   r-   rB   r0   r1   r   accelerator_type_nameaccelerator_typeaccelerator_counts	            r(   GetAcceleratorsr    s}     
 ,,V4%::5J D,,00!<=*>+B+B+;=NP P	)r*   c                     | j                   rK| j                   d   }t        | j                   j                  dd            }t        |j                  ||      S g S )Nr   r  r  )r  r  r   r  r   )r"   r-   r  r  s       r(   $GetAcceleratorsForInstancePropertiesr    s\    	''/D,,00!<=*>+B+B+;=NP P	)r*   c                 .    | j                  ||      }|gS )a`  Returns a list of accelerator config messages.

  Args:
    msgs: tracked GCE API messages.
    accelerator_type: reference to the accelerator type.
    accelerator_count: number of accelerators to attach to the VM.

  Returns:
    a list of accelerator config message that specifies the type and number of
    accelerators to attach to an instance.
  )acceleratorTypeacceleratorCount)AcceleratorConfig)msgsr  r  accelerator_configs       r(   r  r    s*     --&9J . L
	r*   c                    | j                   }| j                  }| j                  }	t        | dd      }
t        | dd      }t	        j
                  |||	||
|      }t	        j                  ||||       t	        j                  |||||      }|S )z@Create a machine type URI for given args and instance reference.custom_vm_typeNcustom_extensions)machine_type
custom_cpucustom_memoryextvm_typer|  )r  r  r  rV   r   InterpretMachineTypeCheckCustomCpuRamRatioParseMachineType)r"   r-   rB   r0   r1   r   r|  r  r  r  r  r  machine_type_namemachine_type_uris                 r(   CreateMachineTypeUrir    s     "",*$$-D*D1')40# %99!
/1 ''(9; $44_5F5=uF 
r*   )TFFF)NNNFNFFFFFFFTFTFFFFFF)NT)FFNFFFTFFFFFF)
NNFNTNNNFN)NNN)NNNN)NNNT)NNNNT)F)NFF)FFFFr  )FFF)NNF)6__doc__
__future__r   r   r   googlecloudsdk.api_lib.computer   r   r   r	   r
   (googlecloudsdk.api_lib.compute.instancesr  googlecloudsdk.api_lib.utilr   rE  googlecloudsdk.callioper   r[   "googlecloudsdk.command_lib.computer   r   ,googlecloudsdk.command_lib.compute.instancesr   rO  $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corer   r   r)   ru   rT   rU   r`   r  rW   r  rX   r
  r  r5  r:  r  rT  r[  rV  rt  rz  r}  r  r  r  r  rS   r*   r(   <module>r     s   ? &  ' 5 6 9 4 0 M A E F Q < # $ *.).',*/	!X !&#(-"'&*$)&+(-#(9[QJ ?C;?Fd  %$$)(-#(+Lx  $$)-|@    (,$(&*$ *.'+$(&*B %)!%#'-1. '+$(!%#'-1#L+l ',K\0t  &+"'`X !&+"'2j$ ,0	(V	 ',*/	
$ &*#'+0.0 /4r*   