
    &0                        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dlmZ e
j&                   e
j(                  e
j*                  j,                         G d de
j.                                      Z e
j(                  e
j*                  j2                         G d de             Z e
j(                  e
j*                  j6                         G d de             Zy)z=Command for setting scheduling for virtual machine instances.    )absolute_import)division)unicode_literals)base_classes)instance_utils)arg_parsers)base)flags)util)timesc                   D    e Zd ZdZddiZdZdZdZdZe	d        Z
d Zd Zy	)
SetSchedulingInstancesSet scheduling options for Compute Engine virtual machines.

    *${command}* is used to update scheduling options for VM instances.
    You can only call this method on a VM instance that is stopped
    (a VM instance in a `TERMINATED` state).
  EXAMPLESz
  To set instance to be terminated during maintenance, run:

    $ {command} example-instance  --maintenance-policy=TERMINATE --zone=us-central1-b
  TFc                 p   |j                  dt        j                  d       t        j                  |d       t        j
                  |d       t        j                  |d       t        j                  |       t        j                  |d       t        j                  j                  |       t        j                  |d       t        j                  |       t        j                  |d       t        j                  |d       t        j                   |       t        j"                  |       y N--restart-on-failure        The instances will be restarted if they are terminated by Compute
        Engine.  This does not affect terminations performed by the user.
        This option is mutually exclusive with --preemptible.
        actionhelpT	is_updateFsupport_flex_start)add_argumentr   StoreTrueFalseActionr
   AddPreemptibleVmArgsAddProvisioningModelVmArgs"AddInstanceTerminationActionVmArgsAddMaintenancePolicyArgssole_tenancy_flagsAddNodeAffinityFlagToParserINSTANCE_ARGAddArgumentAddMinNodeCpuArgAddLocalSsdRecoveryTimeoutArgsAddMaxRunDurationVmArgsAddDiscardLocalSsdVmArgsAddHostErrorTimeoutSecondsArgsAddSkipGuestOsShutdownArgsclsparsers     /lib/surface/compute/instances/set_scheduling.pyArgszSetSchedulingInstances.Args7   s    
//   
v6	$$VF	,,VtD	""6*226TJ	""6*	6T2	((0	!!&D9	""6T:	((0	$$V,    c                    t        j                  | j                               }|j                  }t        j
                  j                  ||j                  t	        j                  |            }|j                  j                         }|j                  |_        |j                  d      r|j                  |_        | j                  rt!        |d      r|j"                  |_        | j&                  rt)        j*                  || j&                        }|i|j                  j-                         |_        d|v r|d   |j.                  _        d|v r.|j                  j3                  |d         |j.                  _        | j6                  rHt!        |d      r<|j                  d      r+|j                  j3                  |j8                        |_        t!        |d	      rE|j                  d	      r4|j                  j                  j=                  |j>                        |_         g }t!        |d
      rf|j                  d
      rUt	        jB                  || jD                         |j                  j                  jG                  |jH                        |_%        n)|j                  d      rd|_%        |jM                  d       |j                  d      rtO        |jP                        |_)        n)|j                  d      rd|_)        |jM                  d       |j                  d      r4|j                  j                  jU                  |jV                        |_,        t!        |d      r<|j                  d      r+|j                  j3                  |jZ                        |_.        t!        |d      r=|j                  d      r,|j                  j3                  |j^                        |_0        n5t!        |d      r)|j                  d      rd|_0        |jM                  d       t!        |d      r6|j                  d      r%tc        jd                  |jf                        |_4        n5t!        |d      r)|j                  d      rd|_4        |jM                  d       t!        |d      r=|j                  d      r,|j                  jk                  |jl                        |_7        n5t!        |d      r)|j                  d      rd|_7        |jM                  d       t)        jp                  |ddd      r(ts        jt                  ||j                        }||_;        n)|j                  d      rg |_;        |jM                  d        t!        |d!      r"|j                  d!      r|jx                  |_=        |j                  j|                  j                  |      5  |j                  j                  |j                         |j                  ||j                  "      }	|j                  |j|                  j                  d#|	fg      cddd       S # 1 sw Y   yxY w)$z8Issues request necessary for setting scheduling options.)scope_listerpreemptiblehost_error_timeout_secondsNenabledmaxDuration)secondslocal_ssd_recovery_timeoutprovisioning_modelinstance_termination_action!clear_instance_termination_actioninstanceTerminationActionmin_node_cpuclear_min_node_cpuminNodeCpusmaintenance_policypreemption_notice_durationmax_run_durationclear_max_run_durationmaxRunDurationtermination_timeclear_termination_timeterminationTime+discard_local_ssds_at_termination_timestamp)discardLocalSsd1clear_discard_local_ssds_at_termination_timestamponInstanceStopActionnodenode_affinity_file
node_groupclear_node_affinitiesnodeAffinitiesskip_guest_os_shutdown)instanceproject
schedulingzoneSetScheduling)Fr   ComputeApiHolderReleaseTrackclientr
   r$   ResolveAsResource	resourcesGetInstanceZoneScopeListermessages
Schedulingrestart_on_failureautomaticRestartIsSpecifiedr4   #_support_host_error_timeout_secondshasattrr5   hostErrorTimeoutSeconds_support_graceful_shutdownr   ExtractGracefulShutdownFromArgsSchedulingGracefulShutdowngracefulShutdownr6   Durationr7   #_support_local_ssd_recovery_timeoutr9   localSsdRecoveryTimeout ProvisioningModelValueValuesEnumr:   provisioningModelValidateInstanceScheduling_support_max_run_duration(InstanceTerminationActionValueValuesEnumr;   r=   appendintr>   r@    OnHostMaintenanceValueValuesEnumrA   onHostMaintenancerB   preemptionNoticeDurationrC   rE   r   FormatDateTimerF   rH   SchedulingOnInstanceStopActionrI   rL   IsAnySpecifiedsole_tenancy_util%GetSchedulingNodeAffinityListFromArgsrQ   rR   skipGuestOsShutdownapitools_clientIncludeFields$ComputeInstancesSetSchedulingRequestNamerT   rV   MakeRequests	instances)
selfargsholderrZ   instance_refscheduling_optionsgraceful_shutdowncleared_fields
affinitiesrequests
             r/   _RunzSetSchedulingInstances._RunO   s   **4+<+<+>?F]]F%%7755f= 8 ?L
  335*.*A*A'&'+'7'7$//G*5,373R3R0&&(HH
// 
	&OO668 	+ ))8I9

-
-
5 --oo&&/@/O&P 
-
-
9
 	00D679:39??3K3K11 4L 430 	*+-.
//
$
$
E
E%%' * N3467&&tT-K-KL
//
$
$
M
M..0 2 
		=	>59278''*4+<+<'=$			.	/'+$M*,-
//
$
$
E
E%% * t12t7G7G$8 5;OO4L4L11 5M 51 t'(T-=-=. +1//*B*B'' +C +' 
/	0T5E5E 6 +/',-t'(T-=-=. ,1+?+?


,( 
/	0T5E5E 6 ,0(-.;


H
I
//
8
8"NN 9  -
 
A



N
O04-23$$T63G%13$JJ
!j*4'			1	2*,',-t-.43C3C 4 04/J/J,		&	&	4	4^	DDD$$&&&'  	 E "g   6#9#9#C#C#2G#= "> ? 
E	D	Ds   A*YYc                 $    | j                  |      S Nr   r   r   s     r/   RunzSetSchedulingInstances.Run       99T?r1   N)__name__
__module____qualname____doc__detailed_helprc   rk   rp   rf   classmethodr0   r   r    r1   r/   r   r      sP     - )-%(,%"$- -.P?dr1   r   c                   6    e Zd ZdZdZdZdZdZed        Z	d Z
y)SetSchedulingInstancesBetar   Tc                    |j                  dt        j                  d       t        j                  |d       t        j
                  |d       t        j                  |d       t        j                  |       t        j                  |d       t        j                  j                  |       t        j                  |d       t        j                  |       t        j                  |d       t        j                  |d       t        j                   |       t        j"                  |       t        j$                  |       y r   )r   r   r   r
   r   r   r    r!   r"   r#   r$   r%   r&   r*   r(   r)   r'   AddGracefulShutdownArgsr+   r,   s     r/   r0   zSetSchedulingInstancesBeta.Args   s    
//   
v6	$$VF	,,VtD	""6*226TJ	""6*	6T2	((0	!!&D9	""6T:	((0	!!&)	$$V,r1   c                 $    | j                  |      S r   r   r   s     r/   r   zSetSchedulingInstancesBeta.Run  r   r1   N)r   r   r   r   rc   rp   rk   rf   r   r0   r   r   r1   r/   r   r      s8     )-%"(,%#- -0r1   r   c                   0    e Zd ZdZdZdZdZdZed        Z	y)SetSchedulingInstancesAlphar   Tc                    |j                  dt        j                  d       t        j                  |d       t        j
                  |d       t        j                  |d       t        j                  |d       t        j                  |d       t        j                  j                  |       t        j                  |d       t        j                  |       t        j                  |       t        j                  |d       t        j                   |d       t        j"                  |       t        j$                  |       t        j&                  |       y )	Nr   r   r   Tr   Fr   )	deprecate)r   r   r   r
   r   r   r    r!   r"   r#   r$   r%   r&   r*   r'   r(   r)   r   r+   AddPreemptionNoticeDurationArgsr,   s     r/   r0   z SetSchedulingInstancesAlpha.Args  s   
//   
v6	$$VF	,,VtD	""6T:226TJ	""6*	6T2	((0	((0	!!&D9	""6T:	!!&)	$$V,	))&1r1   N)
r   r   r   r   rc   rk   rp   rf   r   r0   r   r1   r/   r   r     s3     )-%(,%"#2 2r1   r   N)r   
__future__r   r   r   googlecloudsdk.api_lib.computer   r   googlecloudsdk.callioper   r	   ,googlecloudsdk.command_lib.compute.instancesr
   /googlecloudsdk.command_lib.compute.sole_tenancyr"   r   rz   googlecloudsdk.core.utilr   UniverseCompatibleReleaseTracksrY   GASilentCommandr   BETAr   ALPHAr   r   r1   r/   <module>r      s    D &  ' 7 9 / ( > W U * D%%(()AT// A * AH D%%**+&!7 & ,&R D%%++,%2"< %2 -%2r1   