
    .b                        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lmZ ddlmZ ddlmZ 	 	 	 	 	 	 	 	 	 	 	 	 d"dZ  ejB                  ddd      ejD                   ejF                  ejH                  jJ                         G d dejL                                             Z' ejF                  ejH                  jP                         G d de'             Z) ejF                  ejH                  jT                         G d de)             Z+dddd e'_,        y!)#z8Command for creating VM instances running Docker images.    )absolute_import)division)unicode_literals)base_classes)containers_utils)image_utils)instance_utils)metadata_utils)utils)base)
exceptions)
completers)scope)flags)util)labels_util)logFc                 `   | j                   j                  t        j                         t	        j
                  |        t        j                  | d|       t        j                  | |||       t        j                  |        t        j                  |        t        j                  | dd|	       t        j                  |        t        j                  |        t        j                  | |       t        j                  |        t        j                  |        t        j                   | |       t        j"                  |        t        j$                  | d       t        j&                  |        t        j(                  |        t        j*                  |        t        j,                  |        t        j.                  |        t        j0                  | d       t        j2                  |        t        j4                  | d	       t        j6                  |        t        j8                  | |||       t        j:                  |        t        j<                  |        t        j>                  |        t        j@                  |        tC        jD                  |        t        jF                  | |	       t        jH                  |        t        jJ                  |        t        jL                  |        t        jN                  |        t        jP                  |        |
rt        jR                  | d
       t        jT                  | dd|       tW        jX                  | dd       | j[                  dd       t        j\                  j_                  | d       t        j`                         tb        _2        tb        jd                  j_                  |        | j                   jg                  th        jj                         |rt        jl                  |        t        jn                  |        y)z'Add flags shared by all release tracks.T)container_mount_enabled)r   support_multi_writersupport_disk_labels)	instances
containerssupport_ipv6_only)	deprecate)support_flex_startF)parserfor_containerinstance)	is_createz+Specifies the reservation for the instance.z)The type of reservation for the instance.)
group_textaffinity_text support_specific_then_x_affinityzadded tor    z--descriptionz1Specifies a textual description of the instances.)helpcreate)operation_typeN)8display_info	AddFormatinstances_flagsDEFAULT_LIST_FORMATr
   AddMetadataArgsAddDiskArgsAddCreateDiskArgsAddCanIpForwardArgsAddContainerMountDiskFlagAddAddressArgsAddAcceleratorArgsAddMachineTypeArgsAddMaintenancePolicyArgsAddNoRestartOnFailureArgsAddPreemptibleVmArgsAddProvisioningModelVmArgs"AddInstanceTerminationActionVmArgsAddServiceAccountAndScopeArgsAddTagsArgsAddCustomMachineTypeArgsAddNetworkArgsAddPrivateNetworkIpArgs AddNetworkPerformanceConfigsArgsAddShieldedInstanceConfigArgsAddKonletArgsAddPublicPtrArgsAddImageArgsAddConfidentialComputeArgsAddNestedVirtualizationArgsAddThreadsPerCoreArgsAddIPv6AddressArgsAddIPv6PrefixLengthArgsr   AddCreateLabelsFlagsAddStackTypeArgsAddIpv6NetworkTierArgsAddInternalIPv6AddressArgsAddInternalIPv6PrefixLengthArgsAddMaxRunDurationVmArgsAddDiscardLocalSsdVmArgsAddGracefulShutdownArgsAddReservationAffinityGroupmaintenance_flagsAddResourcePoliciesArgsadd_argumentINSTANCES_ARGAddArgumentMakeSourceInstanceTemplateArgCreateWithContainerSOURCE_INSTANCE_TEMPLATEAddCacheUpdaterr   InstancesCompleterAddSkipGuestOsShutdownArgsAddRequestValidForDurationArgs)r   deprecate_maintenance_policyr   r   !support_confidential_compute_type%support_confidential_compute_type_tdxsupport_snp_svsmr$   r   r   support_graceful_shutdownr   support_skip_guest_os_shutdowns                6lib/surface/compute/instances/create_with_container.py_Argsrd   '   s4     	 C CD  (d,C ##5/-	 %%f-++F3  )	 $$V,$$V,**4 ++F3&&v.,,+ 44V<//>f%**62  ())&1226://4 '""6D9v&,,'+	 --f5''/$$V,))&1""6*""6+<=((0,,V411&9))&1**62++FdC-->?'G	 ++FJ
KO   ++F8+L 335 . ..::6B%%j&C&CD#..v6008    zThe option to deploy a container during VM creation using the container startup agent is deprecated. Use alternative services to run containers on your VMs. Learn more at https://cloud.google.com/compute/docs/containers/migrate-containers.)
is_removedwarningerrorc                       e Zd ZdZdZdZdZdZdZdZ	dZ
dZdZdZdZdZdZdZdZdZed        Zd Zd Zd Zd Zd	 Zd
 Zd Zy)rW   ;Command for creating VM instances running container images.TFc                 ~   t        | ddddddddd
       t        j                  | d       t        j                  | t        j
                  j                         t        j                  | t        j                         t        j                  |        t        j                  |        t        j                  |        y)Register parser args.TF)	r   r   r^   r_   r`   r$   r   r   rb   r   N)rd   r*   AddNetworkTierArgsAddMinCpuPlatformArgsr   ReleaseTrackGAAddPrivateIpv6GoogleAccessArgr   COMPUTE_GA_API_VERSIONAddVisibleCoreCountArgsAddLocalSsdRecoveryTimeoutArgsAddHostErrorTimeoutSecondsArgsr   s    rc   ArgszCreateWithContainer.Args   s     
 $"*..2).!'+ &&v=))&$2C2C2F2FG11,, ++F3226:226:re   c                 |   | j                  |       t        j                  |       t        j                  |       t        j                  |       t        j
                  |       t        j                  |       t        j                  |       t        j                  |       t        j                  |       t        j                  || j                         t        j                  |       t        j                  |       t        j                  |j                  xs g       rt!        j"                  dd      y )Nz--diskz)Boot disk specified for containerized VM.)_ValidateTrackSpecificArgsr*   ValidateAcceleratorArgsValidateNicFlagsValidateNetworkTierArgsValidateKonletArgsValidateDiskCommonFlags"ValidateServiceAccountAndScopeArgsValidatePublicPtrFlags%ValidateNetworkPerformanceConfigsArgsValidateInstanceScheduling_support_max_run_duration ValidateReservationAffinityGroupr	   UseExistingBootDiskdiskr   InvalidArgumentExceptionselfargss     rc   _ValidateArgsz!CreateWithContainer._ValidateArgs   s    ##D)++D1$$T*++D1&&t,++D166t<**4099$?..d,, ++D144T:))$))/r://
?  ;re   c                      y N r   s     rc   ry   z.CreateWithContainer._ValidateTrackSpecificArgs   s    re   c                    |j                  d      s"|j                  d      s|j                  d      rt        j                  ||      }|j                  |d   j                  |j
                  |j                  |j                        \  }}|j                  |      j                  dk7  rt        j                  d       |S t        j                  |      }|S )Nimageimage_familyimage_projectr   )user_projectr   r   r   z	cos-cloudzThis container deployment mechanism requires a Container-Optimized OS image in order to work. Select an image from a cos-cloud project (cos-stable, cos-beta, cos-dev image families).)IsSpecifiedr   ImageExpanderExpandImageFlagprojectr   r   r   Parser   rg   r   ExpandKonletCosImageFlag)r   r   compute_clientresource_parserinstance_refsimage_expander	image_uri_s           rc   GetImageUrizCreateWithContainer.GetImageUri   s    !N+O,"00
/n $33$Q'//

((**	 4 li 
		y	)	1	1[	@'	
  #;;NKire   c           
      <    t        j                  |||||||d      S )NT)!support_internal_ipv6_reservation)create_utilsGetNetworkInterfacesr   r   clientholderr   locationr   skip_defaultss           rc   _GetNetworkInterfacesz)CreateWithContainer._GetNetworkInterfaces  s/     ,,*.	 	re   c	           	          |j                   r&t        j                  |||j                   |||d      S | j                  |||||||      S )NT)	resourcesr   network_interface_argr   r   r   r   )network_interfacer   CreateNetworkInterfaceMessagesr   )	r   r   r   r   r   r   r   r   r   s	            rc   r   z(CreateWithContainer.GetNetworkInterfaces  s_     88 $ 6 6,0  %%ffgx re   c                     g d}t        |d      r|j                  d       |r(|j                  d      st        j                  |g| syy)z8Creates API messages with disks attached to VM instance.)create_disk	local_ssdboot_disk_typeboot_disk_device_nameboot_disk_auto_deleteboot_disk_provisioned_iopslocal_nvdimmr   FT)hasattrappendr   r	   IsAnySpecified)r   r   r   flags_to_checks       rc   CheckDiskMessageArgsz(CreateWithContainer.CheckDiskMessageArgs(  sM    N t^$N+  (--dD^Dre   c                    | j                  |       t        j                  | j                               }|j                  }|j
                  }t        j                  ||j                  |j                  |j                        }t        j                  ||| j                        }t        j                  |      }t        j                  |||d| j                   | j"                  | j$                  | j&                  | j(                  	      }t        j*                  |||      }	t        j,                  ||      }
t        j.                  |      }t        j0                  |||      }| j3                  |||||d   j4                  |d   j6                  t8        j:                  j<                  |      }| j?                  ||||      }tA        jB                  |jD                  |||jF                  jH                        }t        jJ                  ||      }tA        jL                  |jF                  |jN                        }t        jP                  || jR                        }g }|D ]  }tA        jT                  |jF                  ||jW                         |
| jX                  |      }g }| j[                  ||      rt]        j^                  ||jW                         |j4                  |j6                  t8        j:                  j<                  ||||| j`                  | jb                  | jd                  | jf                        }d }t        jh                  ||      rHt]        jj                  ||||j4                  |j6                  t8        j:                  j<                  |      }t]        jl                  ||||j4                  |j6                  t8        j:                  j<                        }|jF                  jI                  ||||jn                  ||||jp                  |jW                         ||	||      }|jr                  =t        jt                  |jF                        jw                  |jr                        |_<        |j{                  d	      rt        j|                  ||      |_?        t]        j                  |jF                  || jR                  | j                  | j                  
      }|r||_C        | j                  xr |j                  d u}|j                  &|j                  | j                  r|j                  |rd|r|j                  nd }t        j                  |jF                  |j                  |j                  | j                  r|j                  nd |      |_K        t        |dd       }|r\g }|D ]N  }t        j                  |||j4                  |j6                        } |j                  | j                                P ||_Q        t]        j                  |jF                  |      }!|!r|!|_S        |j                  d      rt        j                  ||      |_V        |jF                  j                  |||j4                  |j6                        }"t        j                  ||| j                        |"j                  _[        |j                  |j                  j                  d|"f        |j                  |      S )NF)support_min_node_cpu"support_host_error_timeout_secondssupport_max_run_duration"support_local_ssd_recovery_timeoutra   rb   r   )container_mount_disk_enabledcontainer_mount_disk)r   instance_namer   r   r   r   r   boot_disk_size_gbr   create_boot_disksupport_nvdimm#support_match_container_mount_disksr   )r   r   r   r   r   r   confidential_vm_type)r   r   r   r   r   r   )canIpForwarddisksguestAcceleratorsdescriptionlabelsmachineTypemetadataminCpuPlatformnamenetworkInterfacesserviceAccounts
schedulingtagsrequest_valid_for_duration)messagesr   r^   r_   r`   resource_policies)r   zone)r   r   network_performance_configs)r    sourceInstanceTemplater   r   Insert)_r   r   ComputeApiHolderro   r   r   r*   GetValidatedContainerMountDiskr   r   r   r	   GetSourceInstanceTemplaterX   GetSkipDefaultsGetScheduling#_support_host_error_timeout_secondsr   #_support_local_ssd_recovery_timeout_support_graceful_shutdown_support_skip_guest_os_shutdownGetServiceAccountsGetValidatedMetadataGetBootDiskSizeGbGetInstanceRefsr   r   r   compute_scopes	ScopeEnumZONEr   r   GetLabelsMessageWithCosVersionr   r   InstanceGetCanIpForwardCreateTagsMessager   GetConfidentialVmType"_support_confidential_compute_typeCreateKonletMetadataMessageName_container_mount_disk_enabledr   r   CreateDiskMessages_support_create_boot_disk_support_nvdimm$_support_match_container_mount_disks_support_disk_labelsCheckSpecifiedMachineTypeArgsCreateMachineTypeUriGetAcceleratorsr   min_cpu_platformprivate_ipv6_google_access_type(GetPrivateIpv6GoogleAccessTypeFlagMapperGetEnumForChoiceprivateIpv6GoogleAccessIsKnownAndSpecifiedCreateParamsparams&BuildConfidentialInstanceConfigMessage&_support_confidential_compute_type_tdx_support_snp_svsmconfidentialInstanceConfig_support_visible_core_countvisible_core_countenable_nested_virtualizationthreads_per_core_support_numa_node_countnuma_node_count$CreateAdvancedMachineFeaturesMessageadvancedMachineFeaturesgetattrmaintenance_utilParseResourcePolicyWithZoner   SelfLinkresourcePolicies"BuildShieldedInstanceConfigMessageshieldedInstanceConfigr   GetNetworkPerformanceConfignetworkPerformanceConfigComputeInstancesInsertRequestGetReservationAffinity!_support_specific_then_x_affinityr    reservationAffinityapitools_clientr   MakeRequests)#r   r   r   r   r   r   source_instance_templater   r   service_accountsuser_metadatar   r   network_interfacesr   r   can_ip_forwardr   r   requestsinstance_refr   r   machine_type_uriguest_acceleratorsr    confidential_instance_confighas_visible_core_countr  r   parsed_resource_policiespolicyresource_policy_refshielded_instance_configrequests#                                      rc   RunzCreateWithContainer.Run<  s   t**4+<+<+>?F]]N&&O*II))499d6F6F  .GGot<<  #223KLM--"+/+S+S!%!?!?+/+S+S"&"A"A'+'K'K
J &88nm #77nMM&88>"224PM22a  a  %%	   no}I <<((	F $33D-HN--D *??d55 H%!==

!
!





'+'I'I3h e		"	"4	7//&++- ((!&& **//)+/!;;//040Y0Y $ 9 9
  		5	5dM	J'<<)+ ((!&& **//!5
 (77')&&$$((--  ((11%.&&&..  ".* 2 h 
	-	-	9DD''tCCD 	( 
	!	!">	?(55dNK%1%X%X!**,0,S,S040[0[11&" 
&.J+ 
*
* 2%%T1 
 
+
+
7"".++0D0D0P# (>D##4 	 ??''11%%(,(E(E$$4" 	( "$(;TB	#% 'F 0 L L"**$$	!
 #
)
)*=*F*F*H
I ( %=! 
9
9%..T 
 
"*B'			7	866t^L 	) ''EE!9&&  	 F g 
/
/ND$J$J *
 oo))33Xw
Gg &n &&x00re   N)__name__
__module____qualname____doc__r   r   r   r   r   r  r  r   r  r	  r   r  r   r   r   r   staticmethodrw   r   ry   r   r   r   r   r2  r   re   rc   rW   rW      s    * D"&")-&/(,%" $'+$+/((,%&+#"#$(!; ;.*42(R1re   rW   c                   ^    e Zd ZdZdZdZdZdZdZdZ	dZ
dZdZdZdZdZdZdZed        Zd Zy)CreateWithContainerBetarj   TFc                    t        | dddddddddd       t        j                  | d       t        j                  |        t        j                  | t
        j                  j                         t        j                  | t        j                         t        j                  |        t        j                  |        t        j                  |        y)rl   TF)
r   r^   r_   r`   r$   r   ra   r   r   rb   r   N)rd   r*   rm   AddLocalSsdArgsrn   r   ro   BETArq   r   COMPUTE_BETA_API_VERSIONru   rs   rt   rv   s    rc   rw   zCreateWithContainerBeta.Args$  s     
 $*..2)- "&'+ &&v=##F+))&$2C2C2H2HI11.. 226:++F3226:re   c                 .    t        j                  |       y r   )r*   ValidateLocalSsdFlagsr   s     rc   ry   z2CreateWithContainerBeta._ValidateTrackSpecificArgs>  s    ))$/re   N)r3  r4  r5  r6  r   r   r   r   r  r   r  r	  r   r  r   r  r   r   r7  rw   ry   r   re   rc   r9  r9    so    C"&")-&/ $'+$+/((,%"(,%&*#$(!; ;20re   r9  c                   h    e Zd ZdZdZdZdZdZdZdZ	dZ
dZdZdZdZdZdZdZdZed        Zd Zd Zy)CreateWithContainerAlphazAAlpha version of compute instances create-with-container command.Tc                    t        | ddddddddddd       t        j                  | d       t        j                  |        t        j                  |        t        j
                  | t        j                  j                         t        j                  | d       t        j                  | t        j                         t        j                  |        t        j                  |        t        j                  |        t        j                   |        t        j"                  |        t        j$                  |        y )NT)r]   r   r^   r_   r`   r$   r   r   ra   r   rb   r   )rd   r*   rm   AddLocalSsdArgsWithSizeAddLocalNvdimmArgsrn   r   ro   ALPHAAddPublicDnsArgsrq   r   COMPUTE_ALPHA_API_VERSIONru   rt   AddNumaNodeCountArgsrs   AddIPv6AddressAlphaArgsAddIPv6PrefixLengthAlphaArgsrv   s    rc   rw   zCreateWithContainerAlpha.ArgsV  s    	%) $*..2)- "&'+ &&v=++F3&&v.))&$2C2C2I2IJ$$Vd;11// 226:226:((0++F3++F3008re   c                     t        j                  |       t        j                  |       t        j                  |       y r   )r*   r?  ValidatePublicDnsFlagsr   r   s     rc   ry   z3CreateWithContainerAlpha._ValidateTrackSpecificArgsv  s,    ))$/**40**40re   c           	      8    t        j                  |||||||      S r   )r   GetNetworkInterfacesAlphar   s           rc   r   z.CreateWithContainerAlpha._GetNetworkInterfaces{  s&     11ffgx re   N)r3  r4  r5  r6  r   r   r   r   r   r  r  r   r  r	  r   r  r   _support_ipv6_onlyr   r7  rw   ry   r   r   re   rc   rA  rA  B  sz    I"&")-&/(,%! $'+$+/((,%&*#$(!9 9>1
re   rA  zW    Creates Compute Engine virtual machine instances running
    container images.
    a          *{command}* creates Compute Engine virtual
        machines that runs a Docker image. For example:

          $ {command} instance-1 --zone us-central1-a             --container-image=gcr.io/google-containers/busybox

        creates an instance called instance-1, in the us-central1-a zone,
        running the 'busybox' image.

        For more examples, refer to the *EXAMPLES* section below.
        a          To run the gcr.io/google-containers/busybox image on an instance named
        'instance-1' that executes 'echo "Hello world"' as a run command, run:

          $ {command} instance-1             --container-image=gcr.io/google-containers/busybox             --container-command='echo "Hello world"'

        To run the gcr.io/google-containers/busybox image in privileged mode,
        run:

          $ {command} instance-1             --container-image=gcr.io/google-containers/busybox
            --container-privileged
        )briefDESCRIPTIONEXAMPLESN)FFTFFFFFFFTF)-r6  
__future__r   r   r   googlecloudsdk.api_lib.computer   r   r   r	   r
   r   /googlecloudsdk.api_lib.compute.instances.creater   googlecloudsdk.callioper   r   "googlecloudsdk.command_lib.computer   r   r   ,googlecloudsdk.command_lib.compute.instancesr   r*   4googlecloudsdk.command_lib.compute.resource_policiesrQ   r   r  $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corer   rd   	DeprecateDefaultUniverseOnlyReleaseTracksro   rp   CreateCommandrW   r<  r9  rE  rA  detailed_helpr   re   rc   <module>ra     sf   ? &  ' 7 ; 6 9 9 0 Q ( . 9 F Q [ Y < #
 "'!&+*/%*##(e9P 	P	P$ D%%(()k1$,, k1 * %(k1\ D%%**+-01 -0 ,-0` D%%++,=6 = -=B# %  !re   