
                         V   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 Z G d dej,                        Z ej0                  ej2                  j4                         G d dej6                               Z ej0                  ej2                  j:                         G d de             Z ej0                  ej2                  j>                         G d de             Z dddde_!        ejB                  e _!        ejB                  e_!        y)zGCommand to PATCH-style update autoscaling for a managed instance group.    )absolute_import)division)unicode_literals)base_classes)managed_instance_groups_utils)autoscalers)base)flags)	arg_utils)
exceptionsc                    t         j                  j                  |        t        j                         j                  |        t        j                  | d       t        j                  | d       t        j                  | d       y )NT)include_clearF)max_required)
patch_args)	instance_groups_flags%MULTISCOPE_INSTANCE_GROUP_MANAGER_ARGAddArgument	mig_utilsGetModeFlagAddToParserAddScaleInControlFlagAddMinMaxControlAddScheduledAutoscalingparsers    Alib/surface/compute/instance_groups/managed/update_autoscaling.py_CommonArgsr      s`    ==II%%f-!!&=V%8##Ft<    c                       e Zd Zy)NoMatchingAutoscalerFoundErrorN)__name__
__module____qualname__ r   r   r    r    '   s    r   r    c                   0    e Zd ZdZdZed        Zd Zd Zy)UpdateAutoscaling:Update autoscaling parameters of a managed instance group.Fc                 H    t        |        t        j                  | d       y NF)standard)r   r   AddPredictiveAutoscalingr   s    r   ArgszUpdateAutoscaling.Args1   s    &&v>r   c                    t        j                  | j                               }|j                  }t	        j
                  ||j                  |      }t        j                  ||       t        j                  ||j                  |      }t        j                  |      r(t        dj                  |j                                     t        j                  ||      }|j!                  |j"                  |j$                  j'                               }|j)                  d      r;t        j*                  |j,                  |j$                        }||j.                  _        |j)                  d      rd |j.                  _        n/t        j2                  ||j$                        |j.                  _        | j4                  r"|j)                  d      rd |j.                  _        |j)                  d      r|j$                  j8                  j:                  }	|j$                  j9                         |j.                  _        t?        j@                  |jB                  |	      |j.                  j<                  _"        t        jF                  ||j$                        }
|
r|
|j.                  _$        |j)                  d      r|jJ                  |j.                  _&        |j)                  d      r|jN                  |j.                  _(        | jS                  |||||      S )	NzFInstance group manager [{}] has no existing autoscaler; cannot update.)nameautoscalingPolicymodeclear_scale_in_controlclear_scale_down_control!cpu_utilization_predictive_methodmin_num_replicasmax_num_replicas)*r   ComputeApiHolderReleaseTrackclientr   CreateGroupReference	resourcesr   GetInstanceGroupManagerOrThrowAutoscalerForMigByRefIsAutoscalerNewr    formatNameautoscalers_api	GetClientmessage_typer.   messagesAutoscalingPolicyIsSpecifiedParseModeStringr0   r/   scaleInControlBuildScaleInclear_scale_downscaleDownControlAutoscalingPolicyCpuUtilizationPredictiveMethodValueValuesEnumcpuUtilizationr   ChoiceToEnumr3   predictiveMethodBuildSchedulesscalingSchedulesr4   minNumReplicasr5   maxNumReplicas_SendPatchRequest)selfargsholderr8   igm_refold_autoscalerautoscalers_clientnew_autoscalerr0   cpu_predictive_enum	scheduleds              r   RunzUpdateAutoscaling.Run6   s   **4+<+<+>?F]]F#88  $(G ,,Wf=44VV=M=M5<>N  0*!6',,.13 3 )2267C'44   //;;= 5 ?N &&tyy&//Bd.2n&&+018<n&&5 	tV__5 &&5 !1!12L!M:>n&&7;<"OOKKkk8>8g8g 9n&&5IRI_I_

0
02EJGn&&55F ((v?I:Cn&&7*+8<8M8Mn&&5*+8<8M8Mn&&5!!$0BG"02 2r   c                    |j                  d      r8|j                  j                  dg      5  |j                  ||      cd d d        S | j                  rI|j                  d      r8|j                  j                  dg      5  |j                  ||      cd d d        S |j                  ||      S # 1 sw Y   y xY w# 1 sw Y   y xY w)Nr1   z autoscalingPolicy.scaleInControlr2   z"autoscalingPolicy.scaleDownControl)rE   apitools_clientIncludeFieldsPatchrI   )rU   rV   r8   rZ   rX   r[   s         r   rT   z#UpdateAutoscaling._SendPatchRequestj   s    01!!//-
.0!''@0 0 
		4#3#34N#O!!///
02!''@2 2  %%g~>>0 02 2s   B1B=1B:=CN)	r!   r"   r#   __doc__rI   staticmethodr,   r^   rT   r$   r   r   r&   r&   +   s(    B? ?22h?r   r&   c                   $    e Zd ZdZdZed        Zy)UpdateAutoscalingBetar'   Tc                 r    t        |        t        j                  | d       t        j                  |        y r)   r   r   r+   AddClearScaleDownControlFlagr   s    r   r,   zUpdateAutoscalingBeta.Args   s(    &&v>**62r   Nr!   r"   r#   rc   rI   rd   r,   r$   r   r   rf   rf   y       B3 3r   rf   c                   $    e Zd ZdZdZed        Zy)UpdateAutoscalingAlphar'   Tc                 n    t        |        t        j                  |        t        j                  |        y )Nrh   r   s    r   r,   zUpdateAutoscalingAlpha.Args   s&    &&v.**62r   Nrj   r$   r   r   rm   rm      rk   r   rm   z9Update autoscaling parameters of a managed instance groupzf        To update an existing instance group:

            $ {command} --mode=only-scale-out

        a  
*{command}* updates autoscaling parameters of specified managed instance
group.

Autoscalers can use one or more autoscaling signals. Information on using
multiple autoscaling signals can be found here: [](https://cloud.google.com/compute/docs/autoscaler/multiple-signals)

In contrast to *{parent_command} set-autoscaling*, this command *only* updates
specified fields. For instance:

    $ {command} --mode only-scale-out

would change the *mode* field of the autoscaler policy, but leave the rest of
the settings intact.
        )briefEXAMPLESDESCRIPTIONN)"rc   
__future__r   r   r   googlecloudsdk.api_lib.computer   r   r   6googlecloudsdk.api_lib.compute.instance_groups.managedr   r@   googlecloudsdk.callioper	   2googlecloudsdk.command_lib.compute.instance_groupsr
   r   $googlecloudsdk.command_lib.util.apisr   googlecloudsdk.corer   r   Errorr    ReleaseTracksr7   GACommandr&   BETArf   ALPHArm   detailed_helpr$   r   r   <module>r      s!   N &  ' 7 U a ( ] : *=Z%5%5  D%%(()J? J? *J?Z D%%**+	3- 	3 ,	3 D%%++,	32 	3 -	3 I	#  2 (9'F'F  $&7&E&E  #r   