
    }                         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r SS jrS rg)z=Create requests for rolling-action restart/recreate commands.    )absolute_import)division)unicode_literals)managed_instance_groups_utils)flags)scope)update_instances_utils)
exceptions)timesNc                    [         R                  n[        R                  R                  n[
        R                  " U5      nUR                  XXgS9nUR                  5       S;  a(  [        SR                  UR                  5       5      5      eUR                  R                  R                  R                  n	[        R                   " SSU R"                  UR                  5      n
[$        R&                  " X5      nUR(                  =(       d$    UR                  R+                  UR,                  S9/n[.        R0                  " [2        R4                  " [2        R6                  5      5      n[9        U5       H  u  pSX4-  Ul        M     UR                  R                  UU
UU	S9n[=        U S	5      (       a  U R>                  Ul         [=        U S
5      (       a2  [        RB                  " U RD                  UR                  5      nUUl#        [I        UXU 5        UR                  RK                  SUUS9nUR                  5       S:X  aU  URL                  RN                  nUR                  RQ                  URS                  5       UURT                  URV                  S9nOTURL                  RX                  nUR                  R[                  URS                  5       UURT                  UR\                  S9nUSU4$ )a  Create request helper for compute instance-groups managed rolling-action.

Args:
  args: argparse namespace
  client: The compute client
  resources: The compute resources
  minimal_action: MinimalActionValueValuesEnum value
  max_surge: InstanceGroupManagerUpdatePolicy.maxSurge value

Returns:
  ComputeInstanceGroupManagersPatchRequest or
  ComputeRegionInstanceGroupManagersPatchRequest instance

Raises:
  ValueError: if instance group manager collection path is unknown
)default_scopescope_lister)compute.instanceGroupManagersz#compute.regionInstanceGroupManagerszUnknown reference type {0}z--max-unavailablezmax-unavailable)instanceTemplatez%d/%s)maxSurgemaxUnavailableminimalActiontype	min_readyreplacement_methodN)r   updatePolicyversionsr   )instanceGroupManagerinstanceGroupManagerResourceprojectzone)r   r   r   regionPatch)/instance_groups_flags%MULTISCOPE_INSTANCE_GROUP_MANAGER_ARGcompute_scope	ScopeEnumZONEr   GetDefaultScopeListerResolveAsResource
Collection
ValueErrorformatmessages InstanceGroupManagerUpdatePolicyTypeValueValuesEnum	PROACTIVEr	   ParseFixedOrPercentmax_unavailabler   GetInstanceGroupManagerOrThrowr   InstanceGroupManagerVersionr   six	text_typer   NowUTC	enumeratenamehasattrr   minReadySecParseReplacementMethodr   replacementMethod$ValidateAndFixUpdaterAgainstStatefulInstanceGroupManagerapitools_clientinstanceGroupManagers(ComputeInstanceGroupManagersPatchRequestNamer   r   regionInstanceGroupManagers.ComputeRegionInstanceGroupManagersPatchRequestr   )argsclient	resourcesminimal_action	max_surgeresource_argr   r   igm_refupdate_policy_typer.   igm_infor   current_time_striversionupdate_policyr   igm_resourceservicerequests                        Plib/googlecloudsdk/command_lib/compute/instance_groups/managed/rolling_action.pyCreateRequestrT      s   * 'LL,))..-,,V4,**
] + O'  "  1889K9K9MN
OOHH++II *>>,d.B.Boo/ +II(  oo11#44 2 6$( ]]599UYY#78h'jaa22GL ( //BB$"	 C - T; $MT'((/FF2&8M#&}hM55-( 6 L,<<$$::GooFF$\\^%1\\	 G G $$@@GooLL$\\^%1~~	 M G
 7G	$$    c                    [         R                  " U5      (       d  g[        US5      (       ad  UR                  R                  R
                  R                  nU R                  c  X@l        O&U R                  U:w  a  [        R                  " S5      eU R                  c  UR                  R                  SS9U l
        gSnU R                  R                  b  U R                  R                  S:w  a  SnU R                  R                  b  U R                  R                  S:w  a  SnU(       d  [        R                  " S5      eg)	a  Validates and fixes update policy for patching stateful IGM.

Updating stateful IGMs requires maxSurge=0 and replacementMethod=RECREATE.
If the field has the value set, it is validated.
If the field has the value not set, it is being set.

Args:
  update_policy: Update policy to be validated
  igm_info: Full resource of IGM being validated
  client: The compute API client
  args: argparse namespace used to select used version
Nr   zUFor performing this action on a stateful IGMs --replacement-method has to be RECREATEr   )fixedTFzEFor performing this action on a stateful IGMs --max-surge has to be 0)r   
IsStatefulr7   r)   r*    ReplacementMethodValueValuesEnumRECREATEr:   r
   Errorr   FixedOrPercentrW   percent)rO   rK   rD   rC   recreatemax_surge_is_zeros         rS   r;   r;   s   s"    
'	1	1(	;	;
T'((88	)	)((  &&.(0%		(	(H	445 5 ##__;;!;DM##/				%	%	*!%%1				'	'1	,!$% % rU   )N)__doc__
__future__r   r   r   googlecloudsdk.api_lib.computer   "googlecloudsdk.command_lib.computer   r   r!   2googlecloudsdk.command_lib.compute.instance_groupsr   :googlecloudsdk.command_lib.compute.managed_instance_groupsr	   googlecloudsdk.corer
   googlecloudsdk.core.utilr   r1   rT   r;    rU   rS   <module>ri      s=    D &  ' H 4 E ] ] * * 
 !	Q%h&%rU   