
    f*                     X   d Z ddlmZ ddlmZ ddlmZ ddlZddl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dZdZ ej:                  ej<                  j>                         G d dej@                               Z! ej:                  ej<                  jD                         G d de!             Z# ej:                  ej<                  jH                         G d de!             Z%ddde!_&        e!jL                  e%_&        e!jL                  e#_&        y)z@Command for configuring autoscaling of a managed instance group.    )absolute_import)division)unicode_literalsN)encoding)base_classes)managed_instance_groups_utils)autoscalers)base)flags)log)
console_io)fileszsConfiguration specifies no autoscaling configuration. Continuing will delete the existing autoscaler configuration.zConfiguration specifies autoscaling configuration with a different name than existing. Continuing will delete existing autoscaler and create new one with a different name.zDeletion aborted by user.c                   8    e Zd ZdZed        Zd Zd Zd Zd Z	y)SetAutoscaling7Set autoscaling parameters of a managed instance group.c                     t        j                  |        t        j                  j	                  |        t        j
                  | d       y )NparserFstandardr   AddAutoscalerArgsinstance_groups_flags%MULTISCOPE_INSTANCE_GROUP_MANAGER_ARGAddArgumentAddPredictiveAutoscalingr   s    >lib/surface/compute/instance_groups/managed/set_autoscaling.pyArgszSetAutoscaling.Args2   s;    !336B??KK!::6DIK    c                     t        j                  |||      }t        |dd       }t        j                  |      }|xs |j                  }t        j
                  ||j                  |||      }||fS )Nname)r   AutoscalerForMigByRefgetattrIsAutoscalerNewr!   BuildAutoscalermessages)	selfclient	resourcesigm_refargs
autoscalerautoscaler_namenew_oneautoscaler_resources	            r   CreateAutoscalerResourcez'SetAutoscaling.CreateAutoscalerResource:   sx    
 /DD	7$Jj&$7O+;;JGG%2O7GG ''r   c                 p   t        j                  t        j                  |            }|J|t	        j
                  d       y t        j                  t        dt               |j                  ||      S t        j                  ||j                        }|(t        j                  ||       |j!                  ||      S t#        |dd       rSt#        |d      |k7  rDt        j                  t$        dt               |j                  ||       |j!                  ||      S ||_        |j)                  ||      S )Nz]Configuration specifies no autoscaling and there is no autoscaling configured. Nothing to do.T)messagecancel_on_nocancel_stringr!   )jsonloadsr   ReadFileContentsr   infor   PromptContinue_DELETE_AUTOSCALER_PROMPT_DELETION_CANCEL_STRINGDeleter   DictToMessagemessage_typer   AdjustAutoscalerNameForCreationInsertr#   _REPLACE_AUTOSCALER_PROMPTr!   Update)r'   autoscaling_fileautoscalers_clientr*   existing_autoscaler_namenew_autoscalers         r   _SetAutoscalerFromFilez%SetAutoscaling._SetAutoscalerFromFileL   s%    ZZ 6 67G HIN	!	) : 	;!!-D1	3 "((2JKK++N,>,K,KMN'#CC
'#&&w??-'+CC,4/1 )AB&&w??2N$$Wn==r   c                 |    d}t        j                  d|j                        rt        j                  |ddd       y y )NzhYou should not use Compute Engine's autoscaling feature on instance groups created by Kubernetes Engine.z^gke-.*-[0-9a-f]{1,8}-grp$FTz$Setting autoscaling aborted by user.)r2   defaultr3   r4   )rematchr!   r   r9   )r'   r+   prompt_messages      r   _PromptToAutoscaleGKENodeGroupz-SetAutoscaling._PromptToAutoscaleGKENodeGroupm   s?    	;  
xx-tyy9 %d>@ :r   c                 V   t        j                  | j                               }|j                  }t	        j
                  |       t	        j                  |       t        j                  ||j                  |      }t	        j                  ||       | j                  |       | j                  ||j                  ||      \  }}t	        j                  ||       t        j                  ||      }|r(t	        j                   ||       |j#                  ||      S |j%                  ||      S )N)r   ComputeApiHolderReleaseTrackr(   r   ValidateAutoscalerArgsValidateStackdriverMetricsFlagsr   CreateGroupReferencer)   GetInstanceGroupManagerOrThrowrM   r0   "ValidateGeneratedAutoscalerIsValidautoscalers_api	GetClientr?   r@   rB   )r'   r+   holderr(   r*   r/   is_newrD   s           r   RunzSetAutoscaling.Runv   s   **4+<+<+>?F]]F!88>!AA$G#88  $(G "@@ 	''-"&"?"?  '4#1 "DD!# )2267C#CC
w(&&w0CDD$$W.ABBr   N)
__name__
__module____qualname____doc__staticmethodr   r0   rG   rM   rZ    r   r   r   r   .   s0    ?K K($>B@Cr   r   c                   &    e Zd ZdZed        Zd Zy)SetAutoscalingBetar   c                     t        j                  | dd       t        j                  j	                  |        t        j
                  | d       y NTF)r   autoscaling_file_enabled
patch_argsr   r   r   s    r   r   zSetAutoscalingBeta.Args   sF    !33!% ??KK!::6DIKr   c                    t        j                  | j                               }|j                  }t	        j
                  |       t	        j                  |       t	        j                  |t        j                         t        j                  ||j                  |      }t	        j                  ||       | j                  ||j                  ||      \  }}t	        j                  ||       t        j                   ||      }|j#                  d      r/|rd }n|j$                  }| j'                  |j(                  |||      S |r(t	        j*                  ||       |j-                  ||      S |j/                  ||      S NrC   )r   rO   rP   r(   r   rQ   rR   $ValidateConflictsWithAutoscalingFile+ARGS_CONFLICTING_WITH_AUTOSCALING_FILE_BETAr   rS   r)   rT   r0   rU   rV   rW   IsSpecifiedr!   rG   rC   r?   r@   rB   	r'   r+   rX   r(   r*   r/   rY   rD   rE   s	            r   rZ   zSetAutoscalingBeta.Run   sh   **4+<+<+>?F]]F!88>!AA$G!FF	&	4	47 $88  $(G "@@ #'"?"?  '4#1 "DD!# )2267C*+	#' #6#;#; ((


!3W
"$ $ #CC
w(&&w0CDD$$W.ABBr   Nr[   r\   r]   r^   r_   r   rZ   r`   r   r   rb   rb      s    ?K K$Cr   rb   c                   &    e Zd ZdZed        Zd Zy)SetAutoscalingAlphar   c                     t        j                  | dd       t        j                  j	                  |        t        j
                  | d       y rd   r   r   s    r   r   zSetAutoscalingAlpha.Args   sF    !33!% ??KK!::6DHJr   c                    t        j                  | j                               }|j                  }t	        j
                  |       t	        j                  |       t	        j                  |t        j                         t        j                  ||j                  |      }t	        j                  ||       | j                  ||j                  ||      \  }}t	        j                  ||       t        j                   ||      }|j#                  d      r/|rd }n|j$                  }| j'                  |j(                  |||      S |r(t	        j*                  ||       |j-                  ||      S |j/                  ||      S rh   )r   rO   rP   r(   r   rQ   rR   ri   ,ARGS_CONFLICTING_WITH_AUTOSCALING_FILE_ALPHAr   rS   r)   rT   r0   rU   rV   rW   rk   r!   rG   rC   r?   r@   rB   rl   s	            r   rZ   zSetAutoscalingAlpha.Run   sk   **4+<+<+>?F]]F!88>!AA$G!FF	&	5	58 $88  $(G "@@ #'"?"?	# "DD!# )2267C*+	#' #6#;#; ((


!3W
"$ $ #CC
w(&&w0CDD$$W.ABBr   Nrm   r`   r   r   ro   ro      s    ?J J'Cr   ro   z6Set autoscaling parameters of a managed instance groupa  
        *{command}* sets 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)
        )briefDESCRIPTION)'r^   
__future__r   r   r   r5   rJ   apitools.base.pyr   googlecloudsdk.api_lib.computer   r   6googlecloudsdk.api_lib.compute.instance_groups.managedr	   rV   googlecloudsdk.callioper
   2googlecloudsdk.command_lib.compute.instance_groupsr   r   googlecloudsdk.corer   googlecloudsdk.core.consoler   googlecloudsdk.core.utilr   r:   rA   r;   ReleaseTracksrP   GACommandr   BETArb   ALPHAro   detailed_helpr`   r   r   <module>r      s6   G &  '  	 % 7 H a ( ] # 2 * 
D  6  D%%(()cCT\\ cC *cCL D%%**+2C 2C ,2Cj D%%++,5C. 5C -5Cp F	   %3$@$@  !#1#?#?   r   