
                         :   S 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Jr      S*S jr                     S+S jr  S,S jr              S-S jr!          S.S jr"Sr#   S/S jr$    S0S jr%    S1S jr&     S2S jr'S r( S3S jr)S r*   S4S jr+    S5S  jr,S! r- S6S" jr.S# r/   S7S$ jr0   S8S% jr1S& r2S' r3S( r4 S3S) jr5g)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                     / SQnU(       a  UR                  SS/5        U(       a  UR                  / SQ5        U(       a  UR                  S/5        U(       a  [        R                  " U /UQ76 (       d  gg)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)   $   st    . !     >*+

'
'
>~
>
>	    Nc                    / nU(       a  U R                   n/ nU(       a$  [        UUUU R                  =(       d    / UUUUUS9	n[        S,0 SU_SU_SU_S[	        U S/ 5      _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n/ nU(       a  [        XUR                  X#U5      n[        U UUR                  UUUU5      n U
(       GaV  Sn!U(       a  U(       a]  U R                  bP  U R                  c  [        R                  " SS5      e[        R                  " UU R                  UU R                  S9n!O [        R                  " UU R                  US9n!Sn"U(       a   [        R                  " UU R                  US9n"[!        S,0 SU_SU_SU R"                  _SU R$                  _SU R&                  _S U_S!U(       a  U R(                  OS_S"U_S#U	_SU_SU_S	U_SU_SU_S$U _S%U!_S&U R*                  _S'U R,                  _SU_S(U"_S)U_S*U R.                  _6n#U#/U-   nU(       a+  US+   R0                  (       a  UR3                  S+5      n#U#/U-   nUU-   U-   U -   $ )-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). --~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	                    / n	UR                   n
UR                  nU GH?  nUR                  S5      nUR                  SS5      nUS:X  a!  U
R                  R                  R
                  nO U
R                  R                  R                  nUR                  SS5      nUR                  SS5      nSU;   a$  US   S:X  a  [        R                  R                  nO[        R                  R                  n[        R                  " XUXV5      nUR                  S	5      nU(       a  [        R                  " UUU5      nS
U0nO0 n[        R                  " XU5      nUR!                  5       nU[        R                  R                  :X  a	  U(       d  UnU
R                  " SUUUUUU
R                  R"                  R$                  US.UD6nUR                  S5      (       a]  UR                  S5      S:X  a!  U
R                  R&                  R(                  nO U
R                  R&                  R*                  nUUl        U(       a	  U/U	-   n	GM.  U	R/                  U5        GMB     U	$ )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      s+    .$$(**'d88FD &$'JT""66AAd""66@@d88FE"D((=%0K$4=J6&&--e&&++e//	08AH88N+L#99
Xw(#%56ff 2243GIK F((---6Gf)) ""66AA  M xx	+	&	())BBGG	))BBGG	 )m %7nM*m p 
r*   c                    / nU R                   nU R                  nU=(       d    /  GH\  nUR                  S5      nUR                  SS5      nUS:X  a!  UR                  R                  R
                  nO UR                  R                  R                  nUR                  SS5      n[        R                  " UR                  S5      5      nUR                  S/ 5      nUR                  S5      nU(       a:  U(       a2  [        R                  " UUUUU[        U5      S	9n U R                  5       nOS
nUR                  S5      n!UR                  S5      n"UR                  S5      n#UR                  S5      n$S
n%U!(       d  U"(       a.  [        R                  " X5      n&U&R                  UU!U"U#SU$US9u  n%n'S
n(S
n)U(       aK  [         R"                  " X!U%/U5      n(U(       a+  UR%                  USSU0S9n*[         R&                  " UU*U5      n)U(       a  [(        R*                  " UUU)5      n)UR-                  UUR                  S5      U%UUU(S9n+U(       aU  U(       aN  / n,U H?  n-UR.                  R%                  U-SSU0S9n.U,R1                  U.R                  5       5        MA     U,U+l        U	(       a  UR                  S5      n/U(       aU  UR                  S5      bC  UR                  S5      n0U/c  [4        R6                  " SS5      e[        R8                  " U/UUU0S9n1O[        R8                  " U/UUS9n1U1(       a  S
U+l        U1U+l        UR                  S5      n2U2(       a  U2U+l        U(       a  UR                  S5      n3U3(       a  U3U+l         U(       a  UR                  S5      n4U4(       a  U4U+l!        U(       aC  UR                  S 5      n5[        RD                  " UU5US!9n6U6(       a  S
U+l        S
U+l        U6U+l#        UR                  S"S5      n7UR                  S#5      n8U(       a  U8(       a  SU+l$        UR                  S$5      n9U(       a  U9(       a  SU+l%        UR                  S%5      n:U:(       a  U:U+l&        UR                  S&5      n;U;(       a  U;U+l'        UR                  S'5      n<U<(       a/  [        RP                  " UU<XE5      n=U=R                  5       n>U>U+l)        UR                  S(5      n?U?(       a   UR,                  RU                  U?5      U+l+        U(       a  [X        RZ                  " UR                  S)5      5      n@U@(       aZ  UR,                  R]                  5       nAW@R_                  5        VBVCs/ s H  u  nBnCWARa                  UBUCS*9PM     snCnBWAl1        UAU+l2        [        Rf                  " UUU
5      nDUR                  UU7UDU+UUR                  Rh                  Rj                  U)S+9nEUR                  S,5      (       a]  UR                  S,5      S-:X  a!  UR                  Rl                  Rn                  nFO UR                  Rl                  Rp                  nFWFWEl9        U7(       a	  WE/U-   nGMK  UR1                  WE5        GM_     U$ s  snCnBf ).ai	  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
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
\7 *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   6Z	c           
      0   U R                   nU R                  nU(       a0  U(       a(  [        R                  " XXU5      nUR	                  5       nOSnU(       aj  U=(       d    UnUR                  USU	U
S.S9n[        R                  " UR                  UU5      U5      n[        R                  " XU/U5      u  nSU0nSU0nO0 n0 nUnU(       a2  [        R                  " UUUR                  SS5      SS9nU(       a  SU0nUR                  " SUUUS	.UD6n Ub  UU l        Ub  UU l        U(       a  SU l        U(       a  SU l        UU l        OU(       a  SU l        SU l        UU l        UR&                  " SUSUU UR&                  R(                  R*                  UR&                  R,                  R.                  S
.UD6n!U(       aN  US:X  a!  UR&                  R0                  R2                  n"O UR&                  R0                  R4                  n"U"U!l        U!$ )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`   >  sU   2 $$(**'$2293:eMm((*iI( !1 AM "
  H "00H&=>I 	..y09{G	E 45FG&(89KK/&&+T2	G
 ('2k;;  		 &(=% ,.I+$(!&04-'3$$(!'+$.B+,, !)(  44??  44?? 	 ''@@EEi''@@EEi#, 	r*   z
aep-nvdimmc           	          / n[        U S/ 5      =(       d    /  H1  n[        XUR                  S5      X4U5      nUR                  U5        M3     U$ )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     s^     -"4<BB,Y->-B-B6-J-5gGL &	 C
 
r*   c           
         U(       a.  [         R                  " U [        XSU5      nUR                  5       nO[        nUR	                  UR                  R
                  R                  SUR                  R                  R                  UR                  R                  R                  UR                  US9S9nUb  [        R                  " U5      Ul        U$ )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<L18EKM&&(I I&&  44<<%%>>EE  44??<< =  ' , #ooj9L	r*   c                     / n[        U S/ 5      =(       d    /  HR  n[        XUR                  S5      UR                  S5      UR                  S5      UXEU5	      n	UR                  U	5        MT     U$ )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',7H	JI
 i  = 
r*   c	                    U(       a1  U(       a*  [         R                  " U SXuU5      n	U	R                  5       n
OSn
U(       a  UR                  R	                  U5      OSnUR                  UR                  R
                  R                  SUUUR                  R                  R                  UR                  U
S9S9nUb  [        R                  " U5      Ul        U$ )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K18EKM&&(II 
 44Y?  ##  44<<$  44??<< =  $ )  ??:6I	r*   c                 ^   / SQnU(       a  [         R                  " U /UQ76 (       d  / $ U R                  (       a  [        UUU R                  UUUS9$ [        R
                  " UR                  UU R                  U R                  U R                  UUU[        U SS5      [        U SS5      S9
/$ )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JI)!%"44  	55&&)LL;; ~t<t\48	
 r*   c           
        ^  [        U 4S j/ SQ5      nU(       a  [        R                  " T /UQ76 (       d  / $ Sn	Sn
U(       a  [        T SS5      n	[        T SS5      n
[        R
                  " S0 SUR                  _SU_ST R                  _S	T R                  _S
T R                  _ST R                  _SU_SU_SU_ST R                  _ST R                  _ST R                  _ST R                  _S[        T SS5      _S[        T SS5      _S[        T SS5      _S[        T SS5      _S[        T SS5      _SU	_SU
_S[        T SS5      _S[        T SS5      _6/$ )zGet network interfaces.c                    > [        TU 5      $ Nhasattrflagr"   s    r(   <lambda>&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%  r0  r1  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(   GetNetworkInterfacesr6  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           
        ^  [        U 4S j/ SQ5      nU(       a  [        R                  " T /UQ76 (       d  / $ [        R                  " S0 SUR
                  _SU_ST R                  _ST R                  _ST R                  _ST R                  _S	U_S
U_SU_S[        T SS5      _S[        T SS5      _S[        T SS5      _S[        T SS5      _S[        T SS5      _S[        T SS5      _S[        T SS5      _S[        T SS5      _S[        T SS5      _S[        T SS5      _S[        T SS5      _S[        T SS5      _S[        T SS5      _S[        T SS5      _S[        T SS5      _S[        T SS5      _S[        T SS5      _6/$ )z,Get network interfaces in compute Alpha API.c                    > [        TU 5      $ r  r  r   s    r(   r"  +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/  r0  r1  r,   r-   r  r  r  r$  r0   r1   r   r)  Nr  r:  r;  r'  r*  r(  r+  r  r%  r&  r,  r-  r.  r/  r0  r1  rS   )r2  r   r!   r  r  r,   r  r  r  r$  rV   )r"   r3  r5   r0   r1   r   r$   r5  s   `       r(   GetNetworkInterfacesAlphar<    s    ""B E  

'
'
F/E
F
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	                 z   / n	U(       Ga  U GH  n
U
R                  SS5      nSU
;   nU
R                  SS5      nSnSnU(       a$  U
R                  SS5      nU
R                  SS5      nSnU(       a  SU
;   nU	R                  [        R                  " S+0 SU _S	U_S
U
R                  S
S5      _SU
R                  SS5      _SU
R                  SS5      _SU
R                  SS5      _SU_SU_SU_SU_SU_SU
R                  SS5      _SU_SU
R                  SS5      _SU
R                  SS5      _SU
R                  SS5      _SU
R                  SS5      _SU
R                  S S5      _S!U_S"U_S#U_S$U
R                  S%S5      _S&U
R                  S'S5      _S(U
R                  S(S5      _S)U
R                  S*S5      _65        GM     U	$ Ubl  [        R
                  " U5      nU(       d  U	$ U HG  n
U
(       d  M  [        R                  " XR                  R                  5      nU	R                  U5        MI     U	$ ),a@  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/  r0  zexternal-ipv6-addressr1  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_jsonr4  support_enable_vpc_scoped_dnsresultr   r$  r  r  r.  r/  rC  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                 r   [        U SS5      n[        U SS5      nU R                  (       d  U(       d  U(       a   [        UUU R                  Ub  UOUUUUU
US9	$ [        R                  " U 5        U(       d  U	(       a+  U(       a  [        R
                  " U 5        [        XX4XVU5      $ [        U UUUUUUU
S9$ )z6Validates and retrieves the network interface message.network_interface_from_fileN"network_interface_from_json_string)	r,   r-   r  rJ  r0   r1   r   r4  rK  )r4  )rV   r  r  instances_flagsValidatePublicPtrFlagsValidatePublicDnsFlagsr<  r6  )r"   rB   r-   r5   r0   r1   r   r$   support_public_dnssupport_ipv6_assignmentr4  rK  rO  rP  s                 r(   "GetNetworkInterfacesWithValidationrV  :  s     !(.K(,!.'.
0$(8$
 ;()!%"44&2  ;/*K&C  **404	..t4&tV'/G G*K	 	r*   c           	          0 nU HF  nUR                   U;  d  M  [        U UR                   UUUR                  5       S9XER                   '   MH     U$ )z2Creates a mapping of projects to service accounts.)r"   r0   r3  r$   rK   )r0   GetProjectServiceAccountName)r"   instance_refsr3  r$   project_to_sainstance_refs         r(   GetProjectToServiceAccountMapr]  o  sX    -#l=0,D&&%$))+--m(() $ 
r*   c                 2   SnU R                   (       d  U R                  (       d  UR                  R                  SUR                  R                  US94n/ nUR                  U/U5      nU(       da  US   R                  (       dM  / nSR                  U5      n	U(       a  U	SR                  U5      -  n	[        R                  R                  U	5        Uc  U R                   (       a  / OU R                  nU R                  (       a  Sn
OU R                  n
U(       a\  U R                  S5      (       dF  U R                  S5      (       d0  U R                  S	5      (       d  U R                  S
5      (       d  / nU$ [        R                   " UR                  UU
S9nU$ )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`  rb  )ra  r`  r   projectsr   ComputeProjectsGetRequestMakeRequestsdefaultServiceAccountformatr   statusPrintrc  rb  IsSpecifiedr   CreateServiceAccountMessages)r"   r0   r3  r$   rK   r`  requesterrorsrL  scope_warningrb  service_accountss               r(   rX  rX  }  sd    &	 %%..888IKGF  'F3FAY,,MTT
?FF -

'^>>Rt{{F	O**OD,,X66


;
'
'


,
-
-


/
0
0 
	 &BB') 
r*   c                     UR                  S5      (       d,  UR                  S5      (       d  UR                  S5      (       a6  [        R                  " XR                  UR                  UR
                  5      $ g)z1Builds a shielded instance configuration message.shielded_vm_secure_bootshielded_vm_vtpm shielded_vm_integrity_monitoringN)rk  r   #CreateShieldedInstanceConfigMessagerr  rs  rt  )r   r"   s     r(   "BuildShieldedInstanceConfigMessagerv    sj    
011
)**
9::==..0E0E--/ / r*   c                 4    [         R                  " XUUU5      $ )z5Builds a confidential instance configuration message.)r   !CreateConfidentialInstanceMessage)r   r"   !support_confidential_compute_type%support_confidential_compute_type_tdxsupport_snp_svsms        r(   &BuildConfidentialInstanceConfigMessager|    s#     
	9	9'+	
 r*   c                     U(       aN  [         R                  " X5      nUR                  UU R                  U R                  U R
                  SUUUS9u  pU	$ g)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"   r3  rf   r0   rB   r~  r   r   r   rJ   r   s              r(   GetImageUrir    sc      ..vGN!11jj&&((#1-#= 2 ?LI  r*   c                     U R                   (       ab  U R                   S   n[        R                  " XbX4U5      n[        U R                   R	                  SS5      5      n[        UR                  Xx5      $ / $ )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    sv     
 ,,V4%::5J D,,00!<=*>+B+B+;P P	)r*   c                     U R                   (       aJ  U R                   S   n[        U R                   R                  SS5      5      n[        UR                  X#5      $ / $ )Nr   r  r  )r  r  r   r  r   )r"   r-   r  r  s       r(   $GetAcceleratorsForInstancePropertiesr    sY    	''/D,,00!<=*>+B+B+;P P	)r*   c                 &    U R                  XS9nU/$ )aP  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'     --& . L
	r*   c           	         U R                   nU R                  nU R                  n	[        U SS5      n
[        U SS5      n[        R
                  " UUU	UU
US9n[        R                  " XUU5        [        R                  " UXXE5      nU$ )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_5F5=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   rG  googlecloudsdk.callioper   r[   "googlecloudsdk.command_lib.computer   r   ,googlecloudsdk.command_lib.compute.instancesr   rQ  $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corer   r   r)   ru   rT   rU   r`   r  rW   r  rX   r
  r  r6  r<  r  rV  r]  rX  rv  r|  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*   