
    @                     L   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SS.rS rS r\R<                  \R>                  " \R@                  RB                  5       " S S\RD                  5      5       5       r#\R>                  " \R@                  RH                  5       " S S\#5      5       r%\R>                  " \R@                  RL                  5       " S S\#5      5       r'\\#l(        g)zCommand for creating instances.    )absolute_import)division)unicode_literals)base_classes)filter_rewrite)utils)base)
exceptions)scope)flags)util)log)
propertieszD
          Create multiple Compute Engine virtual machines.
        a  
        *{command}* facilitates the creation of multiple Compute Engine
        virtual machines with a single command. They offer a number of advantages
        compared to the single instance creation command. This includes the
        ability to automatically pick a zone in which to create instances based
        on resource availability, the ability to specify that the request be
        atomic or best-effort, and a faster rate of instance creation.
        a  
        To create instances called 'example-instance-1', 'example-instance-2',
        and 'example-instance-3' in the 'us-central1-a' zone, run:

          $ {command} --predefined-names=example-instance-1,example-instance-2,example-instance-3 --zone=us-central1-a
        )briefDESCRIPTIONEXAMPLESc                    / n[         R                  " 5       R                  SU-   S9u  pxUR                  n	/ n
U[        R
                  R                  :X  a  [        R                  " UR                  5      nUR                  U	R                  SXS9/5      n[        U5      S:w  a8  UR                  [        R                  " SR!                  U5      5      5        SU4$ XS   R"                   Vs/ s H  oR%                  U5      R&                  PM     sn-  n
OX/-  n
U R)                  U
 Vs/ s HD  nU R*                  R,                  S	U R*                  R,                  R/                  S	5      " XUS
94PMF     snUSSSS9nX4$ s  snf s  snf )z9Requests operations with group id matching the given one.zoperationGroupId=)
expressionzcompute.regions)
collectionprojectregion   zRegion count is not 1: {}Nr   List)filterr   zoneFT)errors_to_collect
log_resultalways_return_operationno_followup)r   RewriterRewrite	resourcescompute_scopes	ScopeEnumREGIONregion_utilsRegionResourceFetcherclient
GetRegionsCreatelenappendr
   ToolExceptionformatzonesParser   MakeRequestsapitools_clientzoneOperationsGetRequestType)compute_clientr   operation_group_idholderlocationr   r   _operation_filterresource_parserr/   region_fetcherregionsr   operations_responses                  ,lib/surface/compute/instances/bulk/create.py_GetOperationsr@   7   s   
 &//199$'99 : ! $$/
%
n&&---!77FN''(' 	 	
) G
 7|q

"
"#>#E#Eh#O
P $$$	1:;K;KL;K4##D)..;KLLE	ZE&33 	 d ,,;;,,;;JJ'tE 	 *" 4 " 
	//+ M
	s   .$F,AFc                    [        U UR                  UUUU5      u  pgU(       a  [        R                  " USS9  U/ S.nU V	s/ s HA  n	U	R                  S:X  d  M  [        U	R                  5      S:X  d  M0  U	R                  b  M?  U	PMC     n
n	[        U
5      nUR                  R                  U-
  nS nU
 V	s/ s H
  o" U	5      PM     nn	XS'   XS'   XS	'   U$ s  sn	f s  sn	f )
z?Requests operations with group id and parses them as an output.zCould not fetch resource:)error_message)operationGroupId	instancesinsertDONEc                     U R                   U R                  R                  S5      S   U R                  U R                  S.$ )N/)idnamer   selfLink)targetId
targetLinksplitr   )ops    r?   GetInstanceStatus%_GetResult.<locals>.GetInstanceStatus   s8    kk##C(,MM	     createdInstanceCountfailedInstanceCountrD   )r@   r   r   RaiseToolExceptionoperationTypestrstatuserrorr+   bulkInsertInstanceResourcecount)r5   requestr6   r7   r8   r   r>   errorsresultrP   
successfulnum_successfulnum_unsuccessfulrQ   instances_statuss                  r?   
_GetResultrd   h   s   
 !/oo! 	V3NO 2D& $#"			X	% 	 bii.F
" 	 ((	 	#   z?.77==N 7AAj'+jA#1	 "2	(	-1$ Bs   CC5CC7Cc                       \ rS rSrSrSrSrSrSrSr	Sr
SrSrSrSrSrSrSrSrSrSr\S 5       r\S 5       rS rS rS	 rS
 rSrg)r*      0Create Compute Engine virtual machine instances.FTc                    [         R                  " U[        R                  R                  U R
                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                   U R"                  S9  U R%                  U5        [&        R(                  " U5        [&        R*                  " U5        g )N)support_display_devicesupport_numa_node_countsupport_snp_svsmsupport_max_count_per_zonesupport_custom_hostnames support_specific_then_x_affinitysupport_watchdog_timersupport_flex_startsupport_source_snapshot_regionsupport_skip_guest_os_shutdown"support_preemption_notice_duration#support_instance_flexibility_policy support_workload_identity_config)
bulk_flagsAddCommonBulkInsertArgsr	   ReleaseTrackGA_support_display_device_support_numa_node_count_support_snp_svsm_support_max_count_per_zone_support_custom_hostnames!_support_specific_then_x_affinity_support_watchdog_timer_support_flex_start_support_source_snapshot_region_support_skip_guest_os_shutdown#_support_preemption_notice_duration$_support_instance_flexibility_policy!_support_workload_identity_configAddSourceInstanceTemplateinstances_flagsAddLocalSsdRecoveryTimeoutArgsAddHostErrorTimeoutSecondsArgsclsparsers     r?   ArgsCreate.Args   s    &&":: # < <..#&#B#B!$!>!>),)N)N"::22'*'J'J'*'J'J+.+R+R,/,T,T),)N)N" !!&) 226:226:rS   c                 n    [         R                  " 5       U l        U R                  R                  U5        g )N)rv   !MakeBulkSourceInstanceTemplateArgSOURCE_INSTANCE_TEMPLATEAddArgumentr   s     r?   r    Create.AddSourceInstanceTemplate   s.     	446     ,,V4rS   c                     g)Nzcompute.instances )selfs    r?   
CollectionCreate.Collection   s    rS   c                    [         R                  " U R                  U R                  U R                  U R
                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  5      n[         R                   " UUUUUUUU R"                  U5	      n	U[$        R&                  R(                  :X  a4  UR*                  R,                  n
UR.                  R1                  U	UUS9nX4$ U[$        R&                  R2                  :X  a1  UR*                  R4                  n
UR.                  R7                  U	UUS9nW
W4$ )N)r[   r   r   )r[   r   r   )	bulk_utilSupportedFeaturesrz   _support_secure_tagsr{   r|   r}   r~   r   r   _support_graceful_shutdownr   r   r   r   r    CreateBulkInsertInstanceResourcer   r#   r$   ZONEr2   rD   messages!ComputeInstancesBulkInsertRequestr%   regionInstances'ComputeRegionInstancesBulkInsertRequest)r   argsr7   r5   r;   r   r8   r   supported_featuresbulk_instance_resourceinstance_servicerequest_messages               r?   _CreateRequestsCreate._CreateRequests   s    #44$$!!%%((&&..$$'',,,,0011..  'GG%%
 ((---'77AA

!
!
C
C)? D  " ,, 
.**11	1'77GG

!
!
I
I)? J   _,,rS   c           	      n   [         R                  " UU R                  U R                  U R                  S9  [
        R                  " U R                  5       5      nUR                  nUR                  n[        R                  R                  R                  R                  5       nSnSnUR                  S5      (       a'  UR                   n["        R$                  R&                  nO<UR                  S5      (       a&  UR(                  n["        R$                  R*                  nU R-                  XX4XVU5      u  p/ U l        SU l        SU l        UR4                  (       a8  SU l         UR7                  U	5      n
U
R8                  U l        SU
R<                  0$ URC                  USU	4/SSSS	9n
/ U l        U
(       a_  U
S
   R<                  n[E        X9XXg5      nURG                  S5      b/  URG                  S5      b  SRI                  US   US   5      U l        U$ g! [>        R@                   a  nUeSnAff = f)zRuns bulk create command.

Args:
  args: argparse.Namespace, An object that contains the values for the
    arguments specified in the .Args() method.

Returns:
  A resource object dispatched by display.Displayer().
)rl   rm   rt   Nr   r   FTrC   
BulkInsert)r   r   r   r   rT   rU   z%VM instances created: {}, failed: {}.)%rv   ValidateBulkInsertArgsr}   r~   r   r   ComputeApiHolderrx   r(   r"   r   VALUEScorer   	GetOrFailIsSpecifiedr   r#   r$   r   r   r%   r   _errors
_log_async_status_messageasync_r   rL   _operation_selflinkrC   r
   HttpExceptionr1   rd   getr.   )r   r   r7   r5   r;   r   r8   r   instances_servicer]   responserZ   r6   r_   s                 r?   Run
Create.Run  s    %%#'#C#C!%!?!?,0,U,U	 **4+<+<+>?F]]N&&O$$,,668GHEh&&++e			(	#	#h&&--e!%!5!5nw%" DLDOD{{do$//8#+#4#4 "H$=$=>> **
\7	34 $	 + H DL#A;77
#5xf **+
,
8jj./;FMM)*F3H,I 
 m
1 %% s   %/H H4-H//H4c                     AU R                   (       a-  U R                    H  n[        R                  " US   5        M     g U R                  (       a9  [        R                  R                  SR                  U R                  5      5        g U R                   (       a,  U R                    H  n[        R                  " US   5        M     [        R                  R                  SR                  U R                  5      5        g )Nr   z&Bulk instance creation in progress: {}z6Bulk create request finished with status message: [{}])
r   r   rZ   r   rY   Printr.   r   warningr   )r   resources_were_displayedrZ   s      r?   EpilogCreate.EpilogS  s     ||<<%		%(  		jj
2
9
9&& 
\\E
++eAh
 "	jj
B
I
I""rS   )r   r   r   r   N)__name__
__module____qualname____firstlineno____doc__rz   r   r{   r|   r}   r~   r   r   r   r   r   r   r   r   r   r   classmethodr   r   r   r   r   r   __static_attributes__r   rS   r?   r*   r*      s     9!" $#&+#!#$)!$(!(-%).&&+#*; ;2 5 59-vFPrS   r*   c                   h    \ rS rSrSrSrSrSrSrSr	Sr
SrSrSrSrSrSrSrSrSrSr\S 5       rSrg)
CreateBetaii  rg   TFc                 &   [         R                  " U[        R                  R                  4U R
                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                   U R"                  U R$                  U R&                  S.6  U R)                  U5        [*        R,                  " U5        [*        R.                  " U5        g )N)ri   rj   rk   rl   rm   rn   ro   support_graceful_shutdownrp   support_igmp_queryrq   rr   rs   rt   ru   )rv   rw   r	   rx   BETArz   r{   r|   r}   r~   r   r   r   r   _support_igmp_queryr   r   r   r   r   r   r   r   r   r   s     r?   r   CreateBeta.Args~  s    &&  #:: # < <..#&#B#B!$!>!>),)N)N"::"%"@"@2222'*'J'J'*'J'J+.+R+R,/,T,T),)N)N#& !!&) 226:226:rS   r   N)r   r   r   r   r   rz   r   r{   r|   r}   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rS   r?   r   r   i  sw    8 " $"&*#!#$)!$(!(-%).&&+#; ;rS   r   c                   h    \ rS rSrSrSrSrSrSrSr	Sr
SrSrSrSrSrSrSrSrSrSr\S 5       rSrg)CreateAlphai  rg   TFc                    [         R                  " U[        R                  R                  4U R
                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                   U R"                  U R$                  U R&                  S.6  U R)                  U5        [*        R,                  " U5        [*        R.                  " U5        [*        R0                  " 5       R3                  U5        [*        R4                  " U5        g )N)ri   rj   rk   rl   rm   rn   ro   r   r   rp   rq   rr   rs   rt   ru   )rv   rw   r	   rx   ALPHArz   r{   r|   r}   r~   r   r   r   r   r   r   r   r   r   r   r   r   AddSecureTagsArgsr   AddMaintenanceIntervalAddToParserr   r   s     r?   r   CreateAlpha.Args  s   &&  #:: # < <..#&#B#B!$!>!>),)N)N"::22"%"@"@22'*'J'J'*'J'J+.+R+R,/,T,T),)N)N#( !!&) %%f-226:**,88@226:rS   r   N)r   r   r   r   r   rz   r   r{   r|   r}   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rS   r?   r   r     sy    8 !! $"&*# #$(!$(!(,%)-&&*#; ;rS   r   N))r   
__future__r   r   r   googlecloudsdk.api_lib.computer   r   r   &googlecloudsdk.api_lib.compute.regionsr&   googlecloudsdk.callioper	   r
   "googlecloudsdk.command_lib.computer   r#   ,googlecloudsdk.command_lib.compute.instancesr   r   1googlecloudsdk.command_lib.compute.instances.bulkrv   r   r   googlecloudsdk.corer   r   DETAILED_HELPr@   rd   UniverseCompatibleReleaseTracksrx   ry   Commandr*   r   r   r   r   detailed_helpr   rS   r?   <module>r      s   & &  ' 7 9 0 H ( . F Q Q O # **.0b(V D%%(()QT\\ Q * Qh D%%**+-; -; ,-;` D%%++,1;& 1; -1;l % rS   