
    ;O                        S r SSKJr  SSKJr  SSKJr  SSKrSSKJr  SSKJ	r	  SSKJ
r
  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ r   SSK!J"r"  SSK#J$r$  SSK%r%Sr&/ SQr'S r(S r)S r*\RV                  \RX                  " \RZ                  R\                  5       " S S\R^                  5      5       5       r0SSSS .\0l1        \RX                  " \RZ                  Rd                  5       " S! S"\05      5       r3\0Rb                  \3l1        \RX                  " \RZ                  Rh                  5       " S# S$\35      5       r5\0Rb                  \5l1        g)%z,Command for creating managed instance group.    )absolute_import)division)unicode_literalsN)encoding)base_classes)managed_instance_groups_utils)utils)
zone_utils)stateful_policy_utils)ValueOrNone)arg_parsers)base)
exceptions)flags)resource_manager_tags_utils)scope)auto_healing_utils)	arg_utils)
properties6   )instance_redistribution_typetarget_distribution_shapeon_repair_allow_changing_zonec           
      @   U R                  SSS9  U R                  SS[        R                  " S[        R                  SS9SS	9  [
        R                  " U 5        U R                  S
[        R                  " 5       SSS9  [        R                  R                  U 5        g)z
Adds args.z--base-instance-namezBase name to use for the Compute Engine instances that will be created with the managed instance group. If not provided base instance name will be the prefix of instance group name.)helpz--sizeTr   )	unlimitedz3Initial number of instances you want in this group.)requiredtyper   z--target-poolTARGET_POOLz_Specifies any target pools you want the instances of this managed instance group to be part of.)r   metavarr   N)add_argumentr   
BoundedIntsysmaxsizeinstance_groups_flagsAddDescriptionFlagArgListmanaged_flagsINSTANCE_TEMPLATE_ARGAddArgument)parsers    5lib/surface/compute/instance_groups/managed/create.py_AddInstanceGroupManagerArgsr-   7   s    L  N
 	!!!S[[DA@	  B
 **62 4	  6 %%11&9    c                 (    U R                  5       S:H  $ )z/Checks if reference to instance group is zonal.zcompute.instanceGroupManagers)
Collection)refs    r,   _IsZonalGroupr2   M   s    		<	<<r.   c                     Ub  [        U5      (       a  gUR                  R                  R                  R                  nU (       a  U R
                  U:w  a  [        R                  " SS5      eg)ap  Validates and fixed update policy for stateful MIG.

Sets default values in update_policy for stateful IGMs or throws exception
if the wrong value is set explicitly.

Args:
  update_policy: Update policy to be validated
  group_ref: Reference of IGM being validated
  stateful_policy: Stateful policy to check if the group is stateful
  client: The compute API client
Nz--instance-redistribution-typezzStateful regional IGMs need to have instance redistribution type set to 'NONE'. Use '--instance-redistribution-type=NONE'.)r2   messages InstanceGroupManagerUpdatePolicy)InstanceRedistributionTypeValueValuesEnumNONEinstanceRedistributionTyper   RequiredArgumentException)update_policy	group_refstateful_policyclientredistribution_type_nones        r,   #ValidateUpdatePolicyAgainstStatefulr?   R   sk     i 8 8
oo6600  ..2JJ

.
.(	HI I Kr.   c                   x    \ rS rSrSrSrSr\S 5       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g)CreateGAl   .Create Compute Engine managed instance groups.Fc                 j   UR                   R                  [        R                  5        [	        U5        [
        R                  " U5        [        R                  " SS9nUR                  USS9  [        R                  " U5        [        R                  " U5        [        R                  " U5        [        R                  " U5        [        R                  " U5        [        R                  " U5        [        R                   " XR"                  S9  [        R$                  " U5        U R&                  (       a  [        R(                  " U5        [        R*                  " XR-                  5       5        [        R.                  " U5        [        R0                  " U5        [        R2                  " U5        g )NT)
zones_flagcreate)operation_type)support_min_ready_flag)display_info	AddFormatr(   DEFAULT_CREATE_OR_LIST_FORMATr-   r   AddAutohealingArgsr%   GetInstanceGroupManagerArgr*   AddZonesFlagAddMigCreateStatefulFlagsAddMigCreateStatefulIPsFlags$AddMigInstanceRedistributionTypeFlag'AddMigDistributionPolicyTargetShapeFlag%AddMigListManagedInstancesResultsFlagAddMigUpdatePolicyFlags$support_update_policy_min_ready_flagAddMigForceUpdateOnRepairFlagssupport_resource_manager_tagsAddMigResourceManagerTagsFlagsAddMigDefaultActionOnVmFailureReleaseTrack AddInstanceFlexibilityPolicyArgsAddStandbyPolicyFlagsAddWorkloadPolicyFlag)clsr+   igm_args      r,   ArgsCreateGA.Argst   s'   
!!-"M"MN ())&1#>>$OGx8&&v.33F;66v>66v>99&A77?))'O'OQ008
((226:009I9I9KL226:''/''/r.   c                     [         R                  " U5        [         R                  " U5        UR                  (       d"  UR                  (       d  UR
                  (       a  U R                  X#5      Ul        g g N)r%   3ValidateManagedInstanceGroupStatefulDisksProperties1ValidateManagedInstanceGroupStatefulIPsPropertiesstateful_diskstateful_internal_ipstateful_external_ip_CreateStatefulPolicystatefulPolicy)selfinstance_group_managerargsr=   s       r,   _HandleStatefulArgsCreateGA._HandleStatefulArgs   s^    MMKK 	$$$$ 
$
$T
2 + %r.   c                 D   / nUR                   =(       d    /  H3  nUR                  [        R                  " UR                  U5      5        M5     UR                  S S9  [        R                  " UR                  U5      n/ nUR                  =(       d    /  H3  nUR                  [        R                  " UR                  U5      5        M5     UR                  S S9  UR                  R                  R                  US9UR                  l        / nUR                  =(       d    /  H3  nUR                  [        R                  " UR                  U5      5        M5     UR                  S S9  UR                  R                  R                  US9UR                  l        U$ )zCreate stateful policy from disks of args --stateful-disk, and ips of args --stateful-external-ips and --stateful-internal-ips.c                     U R                   $ rc   keyxs    r,   <lambda>0CreateGA._CreateStatefulPolicy.<locals>.<lambda>   s    aeer.   rr   c                     U R                   $ rc   rr   rt   s    r,   rv   rw          QUUr.   additionalPropertiesc                     U R                   $ rc   rr   rt   s    r,   rv   rw      ry   r.   )rf   appendpolicy_utils)MakeStatefulPolicyPreservedStateDiskEntryr4   sortMakeStatefulPolicyrg   /MakeStatefulPolicyPreservedStateInternalIPEntryStatefulPolicyPreservedStateInternalIPsValuepreservedStateinternalIPsrh   /MakeStatefulPolicyPreservedStateExternalIPEntryExternalIPsValueexternalIPs)	rk   rm   r=   stateful_disksstateful_disk_dictr<   stateful_internal_ipsstateful_ip_dictstateful_external_ipss	            r,   ri   CreateGA._CreateStatefulPolicy   s   N#117R7

@
@oo134  8 O,"55O  55;;""

F
Foo/ < ?344EE!6 	F 	
 "".  55;;""

F
Foo/ < ?344EE!6 	F 	
 "". r.   c                    UR                   (       a  UR                  UR                   S   SS[        R                  R                  R
                  R                  0S9n[        R                  " UR                  5       5      nUR                  UR                  U[        R                  R                  R
                  R                  S.SS9$ [        R                  " 5       R                  UU[        R                  R                   ["        R$                  " U5      S9n['        U5      (       a(  [(        R*                  " U5      nUR-                  U/5        U$ )	Nr   compute.zonesproject
collectionparams)regionr   z#compute.regionInstanceGroupManagersr   r   )default_scopescope_lister)zonesParser   VALUEScorer   	GetOrFailr	   ZoneNameToRegionNameNamenamer%   rM   ResolveAsResourcecompute_scope	ScopeEnumZONEr   GetDefaultScopeListerr2   r
   ZoneResourceFetcherWarnForZonalCreation)rk   rm   r=   	resourceszone_refr   r;   zonal_resource_fetchers           r,   _CreateGroupReferenceCreateGA._CreateGroupReference   s#   zz
**Q-$Z..33;;EEF ! Hh ))(--/:f__
))#**//77AA ;  < < 	88:LL'116644V<	 	M <>  Y)==fE119+>r.   c                    UR                  5       nUR                  (       a  / nUR                   Hn  nUR                  USS[        R                  R
                  R                  R                  0S9nUR                  UR                  UR                  5       S95        Mp     XTl        UR                  (       a:  [        R                  " UR                  UR                   R                  5      Ul        [!        U5      $ )Nr   r   r   )zone)DistributionPolicyr   r   r   r   r   r   r   r}   #DistributionPolicyZoneConfigurationSelfLinkr   r   ChoiceToEnumTargetShapeValueValuesEnumtargetShaper   )rk   rm   r   r4   distribution_policypolicy_zonesr   r   s           r,   _CreateDistributionPolicy"CreateGA._CreateDistributionPolicy   s    "557zzl**$??&z0055==GGH # J 	88&&( 9 *	+  #/%%(1(>(>

(
(

%
%
@
@)B% *++r.   c                 z    [        U5      (       a   [        R                  " UR                  5      $ UR                  $ rc   )r2   r	   r   r   r   )rk   r;   s     r,   _GetRegionForGroupCreateGA._GetRegionForGroup   s.    Y''	77r.   c                 R    [        U5      (       a  UR                  $ UR                  $ rc   )r2   instanceGroupManagersregionInstanceGroupManagers)rk   r;   computes      r,   _GetServiceForGroupCreateGA._GetServiceForGroup   s%    Y***000r.   c                    [        U5      (       a@  UR                  Ul        UR                  R                  UUR                  UR                  S9$ UR                  UR                  S[        R                  R                  R                  R                  0SS9nUR                  5       Ul        UR                  R                  UUR                  UR                  S9$ )N)instanceGroupManagerr   r   r   zcompute.regionsr   )r   r   r   )r2   r   r4   )ComputeInstanceGroupManagersInsertRequestr   r   r   r   r   r   r   r   /ComputeRegionInstanceGroupManagersInsertRequest)rk   r;   rl   r=   r   region_links         r,   _CreateResourceRequestCreateGA._CreateResourceRequest   s    Y$-NN!__FF5##~~ G  
 OO


Z..33;;EEF& $ (k '2&:&:&<#__LL5##!! M # #r.   c           	      D   / nU(       as  U R                  U5      nU H\  nUR                  UR                  R                  U[        R
                  R                  R                  R                  US.SS95        M^     U Vs/ s H  owR                  5       PM     sn$ s  snf )N)r   r   zcompute.targetPoolsr   )
r   r}   r   r   r   r   r   r   r   r   )rk   target_poolsr;   holder	pool_refsr   poolpool_refs           r,   #_GetInstanceGroupManagerTargetPools,CreateGA._GetInstanceGroupManagerTargetPools  s    I&&y1f$"")0055==GG$ 1 # 2	3  1::	H	:::s   Bc           	          [         R                  " U5      nUR                  R                  n[	        [
        R                  " U5      5       VVs/ s H  u  pVUR                  R                  XVS9PM      nnnU" UR                  US9S9$ s  snnf )N)rs   valuerz   )resourceManagerTags)	r   GetResourceManagerTagsr4   InstanceGroupManagerParamssortedsix	iteritemsResourceManagerTagsValueAdditionalProperty)rk   r=   resource_manager_tagsresource_manager_tags_mapr   rs   r   additional_propertiess           r,   _CreateParamsCreateGA._CreateParams!  s    #::!	
 
 __77F !/H!IJJJC 	''::s:PJ   ";;!6 < 
 	s   %B
c                    [         R                  " U[        U5        [        R                  " XR
                  5        [        R                  " UR
                  U5      n[        R                  " UR                  XaR                  5      n[        R                  " U5        [        R                  " XAS5      n[        R                  " UR                  U5      n	[        R                  " XR                  5      n
[        R                  " UR                  U5      nUR                  R!                  UR#                  5       UR$                  UR'                  5       UR(                  U R+                  UR,                  X%5      [/        UR0                  5      UU R3                  XR
                  UR                  5      UU	U
US9nUR5                  S5      (       aB  UR                  R                   R7                  UR8                  R;                  5       5      Ul        U R>                  (       a1  UR@                  (       a   U RC                  XAR@                  5      Ul"        U RG                  XU5        [I        URJ                  UURL                  U5        [        RN                  " UR                  URP                  URR                  5      nU(       a  Xl*        URV                  (       a  URV                  Ul,        URZ                  (       a  URZ                  Ul.        UR_                  S5      (       a0  [        R`                  " UR                  URb                  5      Ul2        U$ )z<Create parts of Instance Group Manager shared for the track.N)r   descriptioninstanceTemplatebaseInstanceNametargetPools
targetSizeautoHealingPoliciesdistributionPolicyupdatePolicyinstanceLifecyclePolicyinstanceFlexibilityPolicyresourcePolicieslist_managed_instances_resultstarget_size_policy_mode)3r(   ValidateRegionalMigFlagsUsageREGIONAL_FLAGSr%   %ValidateManagedInstanceGroupScopeArgsr   r   GetHealthCheckUriCreateAutohealingPoliciesr4   initial_delayValidateAutohealingPoliciesPatchUpdatePolicyCreateInstanceLifecyclePolicyCreateInstanceFlexibilityPolicyCreateResourcePoliciesInstanceGroupManagerr   r   r   base_instance_namer   target_poolintsizer   IsSpecified*ListManagedInstancesResultsValueValuesEnumr   upperlistManagedInstancesResultsrW   r   r   r   rn   r?   r   rj   CreateStandbyPolicystandby_policy_initial_delaystandby_policy_modestandbyPolicysuspended_sizetargetSuspendedSizestopped_sizetargetStoppedSizeIsKnownAndSpecifiedCreateTargetSizePolicyr   targetSizePolicy)rk   rm   r;   template_refr=   r   health_checkauto_healing_policiesr:   instance_lifecycle_policyinstance_flexibility_policyresource_policiesrl   standby_policys                 r,   _CreateInstanceGroupManager$CreateGA._CreateInstanceGroupManager2  s    //niP?? 0BB$ L 	&??OO\+=+=	?  "==1CCdM 	&CCOOT	
  	&EE//	
  
 6LL $__AA^^$$%..000<<i
 tyy>199""FOO
 # 9"=*! B & 899
//
.
.5511779; 8
 ))d.H.H&*&8&8
,,'# 	36B ((>(K(K(1(>(M(M(.0
 3FF))  N
 -;*373F3F0151B1B. 9::
'
>
>oot;; - "!r.   c              #      #    U Vs/ s H  n[         R                  " U5      PM     sn H-  nSUS'   [        R                  " UR                  U5        Uv   M/     g s  snf 7f)Nr   r   )r   MessageToDictr   ResolveAutoscalingStatusForMigr=   )rk   r   migsmmigs        r,   _PostProcessOutputCreateGA._PostProcessOutput  sU     3784a&&q)48 c&k $BB
--i 98s   A! A:A!c                    [         R                  " U R                  5       5      nUR                  nU R	                  XUR
                  5      n[        R                  R                  UUR
                  [        R                  R                  R                  S9nU R                  XXSU5      nU R                  XFX2R
                  5      nU R                  XCR                   5      nUR#                  USU4/5      n	U R%                  X)5      $ )zCreates and issues an instanceGroupManagers.Insert request.

Args:
  args: the argparse arguments that this command was invoked with.

Returns:
  List containing one dictionary: resource augmented with 'autoscaled'
  property
)r   Insert)r   ComputeApiHolderrZ   r=   r   r   r(   r)   r   r   r   r   GLOBALr  r   r   apitools_clientMakeRequestsr  )
rk   rm   r   r=   r;   r  rl   requestservicer  s
             r,   RunCreateGA.Run  s     **4+<+<+>?F]]F**49I9IJI 66HH))33:: I L "==v7)))*02B2BDG&&y2H2HIG(G <=>D""600r.    N)__name__
__module____qualname____firstlineno____doc__rU   rW   classmethodr`   rn   ri   r   r   r   r   r   r   r   r  r  r'  __static_attributes__r)  r.   r,   rA   rA   l   sd     7).&"'0 0.4(T2,*1#&; "V"p1r.   rA   z.Create a Compute Engine managed instance groupzI        *{command}* creates a Compute Engine managed instance group.
    a        Running:

              $ {command} example-managed-instance-group --zone=us-central1-a --template=example-global-instance-template --size=1

      will create a managed instance group called 'example-managed-instance-group'
      in the ``us-central1-a'' zone with a global instance template resource
      'example-global-instance-template'.

      To use a regional instance template, specify the full or partial URL of the template.

      Running:

              $ {command} example-managed-instance-group --zone=us-central1-a \
            --template=projects/example-project/regions/us-central1/instanceTemplates/example-regional-instance-template \
            --size=1

      will create a managed instance group called
      'example-managed-instance-group' in the ``us-central1-a'' zone with a
      regional instance template resource 'example-regional-instance-template'.
    )briefDESCRIPTIONEXAMPLESc                   J   ^  \ rS rSrSrSrSr\U 4S j5       rU 4S jr	Sr
U =r$ )
CreateBetai  rC   Tc                    > [         R                  " U5        [         R                  " U5        [         R                  " U5        [        [
        U ]  U5        g rc   )r(   !AddMigActionOnVmFailedHealthCheckAddTargetSizePolicyModeFlagAddOnRepairFlagssuperr5  r`   r^   r+   	__class__s     r,   r`   CreateBeta.Args  s<    33F;--f5""6*	*c'r.   c                 4   > [         [        U ]   XX4U5      nU$ rc   )r:  r5  r  rk   rm   r;   r  r=   r   rl   r<  s          r,   r  &CreateBeta._CreateInstanceGroupManager  s.    ":#'E)D'+'-*/  "!r.   r)  )r*  r+  r,  r-  r.  rU   rW   r/  r`   r  r0  __classcell__r<  s   @r,   r5  r5    s.    6)-&"&( (" "r.   r5  c                   F   ^  \ rS rSrSrSr\U 4S j5       rU 4S jrSr	U =r
$ )CreateAlphai  rC   Tc                 ,   > [         [        U ]  U5        g rc   )r:  rD  r`   r;  s     r,   r`   CreateAlpha.Args  s    	+s (r.   c                 2   > [         [        U ]  XX4U5      nU$ rc   )r:  rD  r  r?  s          r,   r  'CreateAlpha._CreateInstanceGroupManager  s)     #T""&<P  "!r.   r)  )r*  r+  r,  r-  r.  rW   r/  r`   r  r0  rA  rB  s   @r,   rD  rD    s(    6"&) )" "r.   rD  )6r.  
__future__r   r   r   r#   apitools.base.pyr   googlecloudsdk.api_lib.computer   r   r	   r
   6googlecloudsdk.api_lib.compute.instance_groups.managedr   r~   <googlecloudsdk.api_lib.compute.managed_instance_groups_utilsr   googlecloudsdk.callioper   r   r   "googlecloudsdk.command_lib.computer   r   r   r   2googlecloudsdk.command_lib.compute.instance_groupsr%   :googlecloudsdk.command_lib.compute.instance_groups.managedr(   :googlecloudsdk.command_lib.compute.managed_instance_groupsr   $googlecloudsdk.command_lib.util.apisr   googlecloudsdk.corer   r   '_MAX_LEN_FOR_DEDUCED_BASE_INSTANCE_NAMEr   r-   r2   r?   UniverseCompatibleReleaseTracksrZ   GACreateCommandrA   detailed_helpBETAr5  ALPHArD  r)  r.   r,   <module>r]     sU   3 &  ' 
 % 7 H 0 5 h T / ( . 4 J E ] ] Y : * 
 +- ':,=
I4 D%%(()F1t!! F1 * F1T
 > : D%%**+" " ,", $11
  D%%++,"* " -"$ %22 r.   