
    *                        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Jr  SS
KJr  SSKJr  / SQrSrSS/rSSSS.rS r\R6                  " \R8                  R:                  \R8                  R<                  \R8                  R>                  5      \R@                   " S S\RB                  5      5       5       r"\\"l#        g)z;Command for reporting a virtual machine instance as faulty.    )absolute_import)division)unicode_literals)base_classes)poller)waiter)arg_parsers)base)
exceptions)flags)	arg_utils)log)BEHAVIOR_UNSPECIFIEDPERFORMANCESILENT_DATA_CORRUPTIONUNRECOVERABLE_GPU_ERROR	IMMEDIATEFUTURE4Report a host as faulty to start the repair process.zh          *{command}* is used to report a host as faulty to start the repair
          process.
        z        To report a host as faulty for an instance named ``test-instance'', run:

          $ {command} test-instance --fault-reasons=behavior=SILENT_DATA_CORRUPTION,description="affecting our ML job"           --disruption-schedule=IMMEDIATE         )briefDESCRIPTIONEXAMPLESc                     U R                  5       nU[        ;  a&  [        R                  " SSR	                  U 5      5      eU$ )z6Validates behavior field, throws exception if invalid.behaviorzInvalid value {} for behavior)upperFAULT_REASONS_CHOICESr   InvalidArgumentExceptionformat)behavior_inputr   s     6lib/surface/compute/instances/report_host_as_faulty.py_ValidateFaultReasonsBehaviorr!   :   sD    !!#(**

-
-3::>J  
/    c                   ^    \ rS rSrSr\S 5       r\S 5       r\S 5       rS r	SS jr
S rS	rg
)ReportHostAsFaultyD   r   c                     [         R                  R                  U 5        [        R	                  U 5        [        R                  U 5        [        R                  R                  U 5        g N)	r   INSTANCE_ARGAddArgumentr$   _AddDisruptionSchedule_AddFaultReasonsr
   
ASYNC_FLAGAddToParserparsers    r    ArgsReportHostAsFaulty.ArgsK   sD    	""6*--f5''/OO'r"   c           
      p    U R                  SS[        [        R                  SR	                  [
        S9S9  g )Nz--disruption-scheduleTz        Specifies the timing for initiating the fault reporting process.
        The default value is {default_choice} which initiates the process right away.
        )default_choice)requiredchoicestypehelp)add_argumentDISRUPTION_SCHEDULE_CHOICESr   ChoiceToEnumNamer   "DISRUPTION_SCHEDULE_DEFAULT_CHOICEr.   s    r    r*   )ReportHostAsFaulty._AddDisruptionScheduleR   s;    
+'' F"DFE  	r"   c           
          U R                  S[        R                  " S[        [        S.S/S9SSSR                  [        S	9S
9  g )Nz--fault-reasons   )descriptionr   r   )
min_lengthspecrequired_keysTappendz        Specified and can include one or more of the following types:
        {choices}.
        This helps categorize the nature of the fault being reported.
        )r5   )r6   r4   actionr7   )r8   r	   ArgDictstrr!   r   r   r.   s    r    r+   #ReportHostAsFaulty._AddFaultReasons_   sW    
  "9 &,
  F0F1!  r"   c           
      D   UR                    Vs/ s Hn  nUR                  R                  [        R                  " UR                  S5      UR                  R                  R                  5      UR                  S5      S9PMp     nn[        R                  " UR                  UR                  R                  R                  5      nUR                  R                  UR                  5       UR                  UR                  UR                  R                  UUS9S9nU$ s  snf )Nr   r?   )r   r?   )disruptionSchedulefaultReasons)instanceprojectzone"instancesReportHostAsFaultyRequest)fault_reasonsmessages-InstancesReportHostAsFaultyRequestFaultReasonr   ChoiceToEnumgetBehaviorValueValuesEnumdisruption_schedule"InstancesReportHostAsFaultyRequest!DisruptionScheduleValueValuesEnum)ComputeInstancesReportHostAsFaultyRequestNamerL   rM   )selfargsinstance_refclientreasonrO   disruption_schedule_enumrequests           r    _BuildRequest ReportHostAsFaulty._BuildRequestt   s    ((	 )F 	EE++

:&MMee 

=1 	F 	
 )  	  )55  ::\\ 
 ooGG""$$$+1??+]+]7& ,^ ,
	 H G N3	s   A5Dc           
         [        U[        5      (       d  U/nU Vs/ s H,  nUR                  R                  SU R	                  XU5      4PM.     nn/ nUR                  UU5      n	U(       a  [        R                  " U5      eU	 V
s/ s H'  oR                  R                  U
R                  5      PM)     nn
U(       af  U H?  n[        R                  R                  SR                  UR                  5       5      5        MA     [        R                  R                  S5        U	$ [         R"                  " X3R                  R                  U5      n[$        R&                  " U[         R(                  " U5      SR                  SR+                  S U 5       5      5      S S9nU H?  n[        R                  R                  SR                  UR-                  5       5      5        MA     U$ s  snf s  sn
f )	Nr$   zRThe report host as faulty operation is currently in progress. Operation URI: [{}].z]Use [gcloud compute operations describe URI] command to check the status of the operation(s).z9Reporting host as faulty for instance(s) {0} in progress.z, c              3   @   #    U  H  oR                  5       v   M     g 7fr'   )rY   ).0is     r    	<genexpr>*ReportHostAsFaulty._Run.<locals>.<genexpr>   s     8-Q-s   )max_wait_msz[Successfully reported host as faulty for instance: [{0}]. The operation has been completed.)
isinstancelistapitools_client	instancesra   AsyncRequestscore_exceptions
MultiError	resourcesParseselfLinkr   statusPrintr   SelfLinkr   BatchPollerr   WaitForOperationBatchjoinrY   )rZ   r[   instance_refsr]   holderis_asyncr\   requestserrors_to_collect	responsesroperation_refsoperation_refoperation_pollerresults                  r    _RunReportHostAsFaulty._Run   s   mT**$om * *L	 "",, t6:	

 *   $$I &&'899BKL)Q&&,,QZZ8)NL)-

$$*F&&(%	
 * 
jj( ++
((22M ~~




/
E
L
Lii8-88 f (,

1178I8I8K1L	
 ( mi" Ms   3G&.G+c                    [         R                  " U R                  5       5      nUR                  n[        R
                  R                  UUR                  [        R                  " U5      S9nU R                  XX2UR                  S9$ )N)scope_lister)r}   )r   ComputeApiHolderReleaseTrackr]   r   r(   ResolveAsResourcerq   GetInstanceZoneScopeListerr   async_)rZ   r[   r|   r]   r{   s        r    RunReportHostAsFaulty.Run   st    **4+<+<+>?F]]F&&8855f= 9 M 99T&4;;9OOr"    N)F)__name__
__module____qualname____firstlineno____doc__staticmethodr0   r*   r+   ra   r   r   __static_attributes__r   r"   r    r$   r$   D   sR    
 =( ( 
 
  (88t
Pr"   r$   N)$r   
__future__r   r   r   googlecloudsdk.api_lib.computer   )googlecloudsdk.api_lib.compute.operationsr   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper	   r
   r   ,googlecloudsdk.command_lib.compute.instancesr   $googlecloudsdk.command_lib.util.apisr   googlecloudsdk.corero   r   r   r;   r9   DETAILED_HELPr!   ReleaseTracksr   ALPHABETAGAUniverseCompatibleSilentCommandr$   detailed_helpr   r"   r    <module>r      s    B &  ' 7 < . / ( . > : = #  &1 "*H5  D T..33T5F5F5I5I LP++ LP LP^ $1   r"   