
    M                        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r/ SQr\R:                  \R<                  " \R>                  R@                  5       " S S\RB                  5      5       5       r"SSS.\"l#        \R<                  " \R>                  RH                  5       " S S\"5      5       r%\"RF                  \%l#        \R<                  " \R>                  RL                  5       " S S\%5      5       r'\%RF                  \'l#        g)z,Command for updating managed instance group.    )absolute_import)division)unicode_literalsN)base_classes)managed_instance_groups_utils)utils)stateful_policy_utils)base)flags)scope)auto_healing_utils)	arg_utils)instance_redistribution_typetarget_distribution_shapeon_repair_allow_changing_zonec                       \ rS rSrSrSrSr\S 5       r  SS jr	S r
S rS	 rS
 r  SS jr SS jr SS jrS rS rS rS rS rS rS rSrg)UpdateGA.   /Update a Compute Engine managed instance group.Fc                    [         R                  R                  USS9  UR                  5       nUR	                  SSS SS9  UR                  5       n[        R                  " U5        [         R                  " U5        [         R                  " U5        [         R                  " USS9  [        R                  " U5        [        R                  " U5        [        R                  " U5        [        R                  " XR                   S	9  [        R"                  " U5        [        R$                  " XR'                  5       5        [        R(                  " U5        [        R*                  " USS
9  [        R,                  " U5        [        R.                  " U5        U R0                  (       a  [        R2                  " U5        g g )Nupdate)operation_typez--clear-autohealing
store_truezU        Clears all autohealing policy fields for the managed instance group.
        )actiondefaulthelpT)
for_update)support_min_ready_flag)	is_update)instance_groups_flags%MULTISCOPE_INSTANCE_GROUP_MANAGER_ARGAddArgumentadd_mutually_exclusive_groupadd_argument	add_groupr   AddAutohealingArgsAddMigUpdateStatefulFlagsAddMigUpdateStatefulFlagsIPsAddDescriptionFlagmanaged_flags$AddMigInstanceRedistributionTypeFlag'AddMigDistributionPolicyTargetShapeFlag%AddMigListManagedInstancesResultsFlagAddMigUpdatePolicyFlags$support_update_policy_min_ready_flagAddMigForceUpdateOnRepairFlagsAddMigDefaultActionOnVmFailureReleaseTrackAddMigSizeFlag AddInstanceFlexibilityPolicyArgsAddStandbyPolicyFlagsAddWorkloadPolicyFlagssupport_multi_mig_flagAddMultiMigFlags)clsparserautohealing_groupautohealing_params_groups       5lib/surface/compute/instance_groups/managed/update.pyArgsUpdateGA.Args6   s]   ??KKx L  ;;=""	 #   1::<))*BC33F;66v>,,VE66v>99&A77?))'O'O 008009I9I9KL  (226TJ''/((0
!!$$V, "    Nc                    0 nU(       a  [         R                  " U5        OrU(       aM  UR                  (       a<  UR                  R                  (       a!  UR                  R                  R                  nO/ nU Vs0 s H  owR
                  U_M     nnU=(       d    /  HY  nUR                  S5      n	[        R                  " UR                  U5      n
X;   a  [        R                  " XY   U
5        MU  XU	'   M[     U=(       d    /  H  n	[        R                  " X5      XY'   M     [        [        R                  " U5       VVs/ s H  u  pUPM	     snnS S9nU$ s  snf s  snnf )Nzdevice-namec                     U R                   $ Nkeyxs    r=   <lambda><UpdateGA._GetUpdatedStatefulPolicyForDisks.<locals>.<lambda>       aeer@   rD   )r   (RegisterCustomStatefulDisksPatchEncoderspreservedStatedisksadditionalPropertiesrE   getpolicy_utils)MakeStatefulPolicyPreservedStateDiskEntrymessagesPatchStatefulPolicyDisk*MakeDiskDeviceNullEntryForDisablingInPatchsortedsix	iteritems)selfclientcurrent_stateful_policyupdate_disksremove_device_namespatched_disks_mapcurrent_disks
disk_entryupdate_diskdevice_nameupdated_preserved_state_disk_stateful_diskstateful_diskss                 r=   !_GetUpdatedStatefulPolicyForDisks*UpdateGA._GetUpdatedStatefulPolicyForDisksZ   sg    #LL
 "%44%44:: $2288MM 	  8E7D..*
$}  
 $)r)OOM2k

@
@oo{ # 
	),,*,H	
 *F+& *  +0b0

A
A $ 1  %(MM2C$D	
$D  $D	
 N G:	
s   ;EE 
c                 x   UR                   nUR                  nU R                  XXE5      n[        R                  " UR
                  U5      nU R                  XR                  UR                  5      nU R                  XR                  UR                  5      n	[        R                  " UR
                  USUU	5      $ )z:Create an updated stateful policy based on specified args.N)rd   remove_stateful_disksrf   rP   MakeStatefulPolicyrR   (_GetPatchForStatefulPolicyForInternalIPsstateful_internal_ipremove_stateful_internal_ips(_GetPatchForStatefulPolicyForExternalIPsstateful_external_ipremove_stateful_external_ipsUpdateStatefulPolicy)
rX   rY   rZ   argsr[   r\   re   stateful_policystateful_internal_ipsstateful_external_ipss
             r=   _GetUpdatedStatefulPolicy"UpdateGA._GetUpdatedStatefulPolicy   s    %%L44;;N #55O !II))4+L+L !II))4+L+L ,, r@   c                    UR                  S5      =(       dq    UR                  S5      =(       dY    UR                  S5      =(       dA    UR                  S5      =(       d)    UR                  S5      =(       d    UR                  S5      $ )Nrd   ri   rl   rm   ro   rp   IsSpecifiedrX   rr   s     r=   _StatefulArgsSetUpdateGA._StatefulArgsSet   s    ) 	<34	<23	< :;	< 23		<
 :;r@   c                     UR                  S5      =(       d)    UR                  S5      =(       d    UR                  S5      $ )Nrd   rl   ro   ry   r{   s     r=   _StatefulnessIntroduced UpdateGA._StatefulnessIntroduced   s=    ) 	423	423r@   c                 \    [         R                  " X5        [         R                  " X5        g rC   )r    "ValidateUpdateStatefulPolicyParams)ValidateUpdateStatefulPolicyParamsWithIPs)rX   rr   rs   s      r=   _ValidateStatefulPolicyParams&UpdateGA._ValidateStatefulPolicyParams   s&    << CCr@   c                 p   U(       a  [         R                  " U5        0 nU=(       d    /  H/  nUR                  S[        R                  5      nU" U5      n	XU'   M1     U=(       d    /  H  nU" U5      n	XU'   M     [        [        R                  " U5       V
Vs/ s H  u  pUPM	     snn
S S9nU$ s  snn
f )Nzinterface-namec                     U R                   $ rC   rD   rF   s    r=   rH   FUpdateGA._GetStatefulPolicyPatchForStatefulIPsCommon.<locals>.<lambda>   rJ   r@   rD   )r   &RegisterCustomStatefulIpsPatchEncodersrO   r    "STATEFUL_IP_DEFAULT_INTERFACE_NAMErU   rV   rW   )rX   rY   update_ip_to_ip_entry_lambdaupdate_ip_to_none_lambda
update_ipsremove_interface_namespatched_ips_map	update_ipinterface_nameupdated_preserved_state_iprE   stateful_ipstateful_ipss                r=   +_GetStatefulPolicyPatchForStatefulIPsCommon4UpdateGA._GetStatefulPolicyPatchForStatefulIPsCommon   s     #JJ
 O  %2%	 }}


B
Bn $@	#J (Bn% & 16B6#;N#K (Bn% 7 -0]]?-KL-K)-KLL  	Ms   B2
c                     U R                  U[        R                  " [        R                  UR
                  5      [        R                  " [        R                  U5      UU5      $ rC   )r   	functoolspartialrP   MakeInternalIPEntryrR   *MakeInternalIPNullEntryForDisablingInPatch)rX   rY   update_internal_ipsr   s       r=   rk   1UpdateGA._GetPatchForStatefulPolicyForInternalIPs   sU     ;;,::FOOLCCV	
 	 r@   c                     U R                  U[        R                  " [        R                  UR
                  5      [        R                  " [        R                  U5      UU5      $ rC   )r   r   r   rP   MakeExternalIPEntryrR   *MakeExternalIPNullEntryForDisablingInPatch)rX   rY   update_external_ipsr   s       r=   rn   1UpdateGA._GetPatchForStatefulPolicyForExternalIPs   sU     ;;,::FOOLCCV	
 	 r@   c                     U R                  U5      (       a  [        R                  " X45        U R                  X#R                  5        U R                  XCR                  U5      Ul        U$ )z:Patch the stateful policy specified in args, to igm_patch.)r   r   ValidateIgmReadyForStatefulnessr   statefulPolicyrv   )rX   	igm_patchrr   igm_resourcerY   holders         r=   _PatchStatefulPolicyUpdateGA._PatchStatefulPolicy  sb     ##D))#CC
 	&&t-H-HI#==++T I r@   c                     [         R                  " UR                  U5      n[         R                  " UR                  UR
                  UU5      n[         R                  " U5        U$ rC   )r   GetHealthCheckUri	resourcesModifyAutohealingPoliciesautoHealingPoliciesrR   ValidateAutohealingPolicies)rX   r   rY   rr   r   health_checkauto_healing_policiess          r=    _GetValidatedAutohealingPolicies)UpdateGA._GetValidatedAutohealingPolicies  se     1BB$L 	&??,,OO		
  "== ! r@   c                     UR                   nUc  UR                  R                  5       n[        R                  " UUR                  R                  R
                  5      Ul        XQl         g rC   )distributionPolicyrR   DistributionPolicyr   ChoiceToEnumTargetShapeValueValuesEnumtargetShape)rX   patch_instance_group_managerr   r   rY   distribution_policys         r=   _PatchTargetDistributionShape&UpdateGA._PatchTargetDistributionShape.  s\     '99""OO>>@&/&<&<!**EE'# 7J3r@   c                    UR                  5       S:X  aU  UR                  R                  nUR                  R	                  UR                  5       UUR                  UR                  S9nOTUR                  R                  nUR                  R                  UR                  5       UUR                  UR                  S9nUR                  USU4/5      $ )Ncompute.instanceGroupManagers)instanceGroupManagerinstanceGroupManagerResourceprojectzone)r   r   r   regionPatch)
Collectionapitools_clientinstanceGroupManagersrR   (ComputeInstanceGroupManagersPatchRequestNamer   r   regionInstanceGroupManagers.ComputeRegionInstanceGroupManagersPatchRequestr   MakeRequests)rX   rY   igm_refigm_updated_resourceservicerequests         r=   _MakePatchRequestUpdateGA._MakePatchRequest>  s    >>&&<<gHH&||~';//||	 I g &&BBgNN&||~';//	 O g '7 ;<==r@   c                     UR                  5       S:X  a   [        R                  " UR                  5      $ UR                  $ )Nr   )r   r   ZoneNameToRegionNamer   r   )rX   r   s     r=   _GetRegionForGroupUpdateGA._GetRegionForGroupQ  s3    >>''55^^r@   c                 P   [         R                  " U[        U5        UR                  R	                  5       n/ nU R                  XTX5      nUb  Xl        [        R                  " XAUR                  5      n	U	b  Xl	        U R                  U5      (       a  U R                  XaX4U5      nUR                  (       a  U R                  UUR                  UU5        UR                  S5      (       a  UR                  Ul        UR                  S5      (       aB  UR                  R                  R!                  UR"                  R%                  5       5      Ul        [        R(                  " UR                  U5      Ul        [        R,                  " XR                  U5      Ul        UR                  S5      (       a  UR0                  Ul        [        R4                  " UR                  UR6                  UR8                  5      n
U
(       a  Xl        UR<                  (       a  UR<                  Ul        UR@                  (       a  UR@                  Ul!        [        RD                  " UR                  U5      nXl#        URI                  S5      (       ak  URJ                  (       aW  U RM                  U5      nURN                  RQ                  URJ                  XRR                  S.SS9nURU                  5       Ul+        Xg4$ URI                  S	5      (       a  SUl+        URY                  S
5        Xg4$ )zCreate IGM resource patch.Ndescriptionlist_managed_instances_resultssize	multi_mig)r   r   zcompute.regionMultiMigs)params
collectionclear_multi_migmultiMig)-r*   ValidateRegionalMigFlagsUsageREGIONAL_FLAGSrR   InstanceGroupManagerr   r   r   PatchUpdatePolicyupdatePolicyr|   r   r   r   rz   r   *ListManagedInstancesResultsValueValuesEnumr   upperlistManagedInstancesResultsCreateInstanceLifecyclePolicyinstanceLifecyclePolicyCreateInstanceFlexibilityPolicyinstanceFlexibilityPolicyr   
targetSizeCreateStandbyPolicystandby_policy_initial_delaystandby_policy_modestandbyPolicysuspended_sizetargetSuspendedSizestopped_sizetargetStoppedSizeCreateResourcePoliciesresourcePoliciesIsKnownAndSpecifiedr   r   r   Parser   SelfLinkr   append)rX   rr   r   r   rY   r   r   include_fieldsr   update_policystandby_policyresource_policiesmulti_mig_regionmulti_mig_refs                 r=    _CreateInstanceGroupManagerPatch)UpdateGA._CreateInstanceGroupManagerPatchW  s    //ngN#)??#G#G#I N AA (9N61CCl//M  2?/T""%)%>%>
&lF&" %%
((
&

(
(

	 &&151A1A".899
//
.
.
Y
Y++11305 #>
 	&CCOOT	
 !8 	&EE//<	
 !:
 04		"-2FF))  N
 3A09=9L9L"67;7H7H"45LL 5F1,,	227;((..NN.??K0 / 

 1>0F0F0H$-
 (77	 
	!	!"3	4	4.2"+J''77r@   c                 l   [         R                  " U R                  5       5      nUR                  n[        R
                  R                  UUR                  [        R                  R                  [        R                  " U5      S9nUR                  5       S;  a(  [        SR                  UR                  5       5      5      e[         R"                  " XC5      nU R%                  XXSU5      u  pgUR&                  R)                  U5         U R+                  X4U5      sS S S 5        $ ! , (       d  f       g = f)N)default_scopescope_lister)r   z#compute.regionInstanceGroupManagerszUnknown reference type {0})r   ComputeApiHolderr2   rY   r    r!   ResolveAsResourcer   compute_scope	ScopeEnumZONEr   GetDefaultScopeListerr   
ValueErrorformatr   GetInstanceGroupManagerOrThrowr  r   IncludeFieldsr   )rX   rr   r   rY   r   r   r   r   s           r=   RunUpdateGA.Run  s   **4+<+<+>?F]]FCCUU#--22008 	V E   $  
&
-
-g.@.@.B
C  1OOL
 	--<	
 1  
			-	-n	=##
7 
>	=	=s   	D%%
D3 )NN)__name__
__module____qualname____firstlineno____doc__r/   r7   classmethodr>   rf   rv   r|   r   r   r   rk   rn   r   r   r   r   r   r  r  __static_attributes__r  r@   r=   r   r   .   s     9).&  -  -N =~8 !!H FJ FJ!&J >&P8d!r@   r   r   am        Update a Compute Engine managed instance group.

      *{command}* allows you to specify or modify the description and group
      policies for an existing managed instance group, including the group's
      update policy and optional autohealing and stateful policies

      The group's update policy defines how an updated VM configuration is
      applied to existing VMs in the group. For more information, see
      [Applying new configurations]
      (https://cloud.google.com/compute/docs/instance-groups/updating-migs)
      to VMs in a MIG.

      A stateful policy defines which resources should be preserved across the
      group. When instances in the group are recreated, stateful resources are
      preserved. This command allows you to update stateful resources,
      specifically to add or remove stateful disks.

      When updating the autohealing policy, you can specify the health check,
      initial delay, or both. If either field is unspecified, its value won't
      be modified. If `--health-check` is specified, the health check monitors
      the health of your application. Whenever the health check signal for an
      instance becomes `UNHEALTHY`, the autohealer recreates the instance.

      If no health check exists, instance autohealing is triggered only by
      instance status: if an instance is not `RUNNING`, the group recreates it.
      )briefDESCRIPTIONc                   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$ )
UpdateBetai  r   Tc                    > [         R                  " U5        [         R                  " U5        [        [        U ]  U5        g rC   )r*   !AddMigActionOnVmFailedHealthCheckAddOnRepairFlagssuperr  r>   r9   r:   	__class__s     r=   r>   UpdateBeta.Args  s.    33F;""6*	*c'r@   c                 :   > [         [        U ]   XX4U5      u  pgXg4$ rC   )r#  r  r  )	rX   rr   r   r   rY   r   r   r   r%  s	           r=   r  +UpdateBeta._CreateInstanceGroupManagerPatch  s4     49D4'&|V 1 
 (77r@   r  )r  r  r  r  r  r/   r7   r  r>   r  r  __classcell__r%  s   @r=   r  r    s.    7)-&( (
8 8r@   r  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
$ )UpdateAlphai  r   Tc                 ,   > [         [        U ]  U5        g rC   )r#  r,  r>   r$  s     r=   r>   UpdateAlpha.Args  s    	+s (r@   c                 :   > [         [        U ]   XX4U5      u  pgXg4$ rC   )r#  r,  r  )	rX   rr   r   r   rY   r   r   r   r%  s	           r=   r  ,UpdateAlpha._CreateInstanceGroupManagerPatch  s3     !&T!'&|V I $$r@   r  )r  r  r  r  r  r7   r  r>   r  r  r)  r*  s   @r=   r,  r,    s(    7) )	% 	%r@   r,  )(r  
__future__r   r   r   r   googlecloudsdk.api_lib.computer   r   r   6googlecloudsdk.api_lib.compute.instance_groups.managedr	   rP   googlecloudsdk.callioper
   "googlecloudsdk.command_lib.computer   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   rV   r   UniverseCompatibleReleaseTracksr2   GAUpdateCommandr   detailed_helpBETAr  ALPHAr,  r  r@   r=   <module>rA     s$   3 &  '  7 H 0 h ( 4 E ] ] Y : 
 D%%(()Zt!! Z * Z| ?
 @ D%%**+8 8 ,8. $11
  D%%++,%* % -%* '44 r@   