
                         l   S r SSK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SS.r\	R"                  \	R$                  " \	R&                  R(                  \	R&                  R*                  \	R&                  R,                  5       " S S\	R.                  5      5       5       r\\l        g)z!Command for stopping an instance.    N)base_classes)poller)waiter)base)flags)
exceptions)log Stop a virtual machine instance.au          *{command}* is used to stop a Compute Engine virtual machine.
        Stopping a VM performs a clean shutdown, much like invoking the shutdown
        functionality of a workstation or laptop.

        If a VM has any attached Local SSD disks, you must use the
        `--discard-local-ssd` flag to indicate whether or not the Local SSD
        data should be discarded. To stop the VM and preserve the Local SSD
        data when you stop the VM by setting `--discard-local-ssd=False`.

        To stop the VM and discard the Local SSD data, specify
        `--discard-local-ssd=True`.

        Preserving the Local SSD disk data incurs costs and is subject to
        limitations. See
        https://cloud.google.com/compute/docs/disks/local-ssd#stop_instance
        for more information.

        Stopping a VM which is already stopped will return without errors.
        a6          To stop an instance named `test-instance`, run:

          $ {command} test-instance

        To stop an instance named `test-instance` that has a Local SSD, run:

          $ {command} test-instance --discard-local-ssd=True

        Using '--discard-local-ssd' without a value defaults to True.
      )briefDESCRIPTIONEXAMPLESc                   :    \ rS rSrSr\S 5       rS rS rS r	Sr
g)	StopC   r
   c           	         [         R                  R                  U5        UR                  SSS SS SS9  [        R
                  R                  U5        U R                  5       [        R                  R                  :X  d,  U R                  5       [        R                  R                  :X  a  UR                  SS SS	S
9  g g )Nz--discard-local-ssd?Tc                 f    [         R                  " U R                  5       R                  5       5      $ N)astliteral_evallower
capitalize)xs    %lib/surface/compute/instances/stop.py<lambda>Stop.Args.<locals>.<lambda>T   s    s''	(<(<(>?    z,If set to true, local SSD data is discarded.)nargsdefaultconsttypehelpz--no-graceful-shutdown
store_truezStops the instance immediately without gracefully shutting it down. If a graceful shutdown is in progress, then the instance is forcefully stopped.)r   actionr"   )
r   INSTANCES_ARGAddArgumentadd_argumentr   
ASYNC_FLAGAddToParserReleaseTrackALPHABETA)clsparsers     r   Args	Stop.ArgsJ   s    	##F+
 @<  ? 	OO'd//555!2!2!7!77
"(  	 8r   c                    U R                  5       [        R                   R                  :X  d,  U R                  5       [        R                   R                  :X  aS  UR                  R                  UR                  UR                  5       UR                  UR                  UR                  S9$ UR                  R                  UR                  UR                  5       UR                  UR                  S9$ )N)discardLocalSsdinstanceprojectzonenoGracefulShutdown)r2   r3   r4   r5   )r*   r   r+   r,   messagesComputeInstancesStopRequestdiscard_local_ssdNamer4   r5   no_graceful_shutdown)selfclientinstance_refargss       r   _CreateStopRequestStop._CreateStopRequestf   s    t00666$"3"3"8"88__8800$$&&&  !66 9   ??66..""$$$	 7  r   c           
          U Vs/ s H,  nUR                   R                  SU R                  XU5      4PM.     sn$ s  snf )Nr   )apitools_client	instancesr@   )r<   r=   instance_refsr?   r>   s        r   _CreateRequestsStop._CreateRequestsy   sM     !./ - ##--v$$V4@B -/ / /s   3;c           
      &   [         R                  " U R                  5       5      nUR                  n[        R
                  R                  UUR                  [        R                  " U5      S9nU R                  X4U5      n/ nUR                  XV5      nU(       a  [        R                  " U5      eU Vs/ s H'  oR                  R                  UR                  5      PM)     n	nUR                  (       af  U	 H?  n
[         R"                  R%                  SR'                  U
R)                  5       5      5        MA     [         R"                  R%                  S5        U$ [*        R,                  " X3R.                  R0                  U5      n[2        R4                  " U[*        R6                  " U	5      SR'                  SR9                  S U 5       5      5      S S9  U H1  n[         R"                  R%                  SR'                  U5      5        M3     g s  snf )	N)scope_listerz#Stop instance in progress for [{}].z]Use [gcloud compute operations describe URI] command to check the status of the operation(s).zStopping instance(s) {0}z, c              3   @   #    U  H  oR                  5       v   M     g 7fr   )r:   ).0is     r   	<genexpr>Stop.Run.<locals>.<genexpr>   s      4-+FFHHms   )max_wait_mszUpdated [{0}].)r   ComputeApiHolderr*   r=   r   r%   ResolveAsResource	resourcesGetInstanceZoneScopeListerrF   AsyncRequestscore_exceptions
MultiErrorParseselfLinkasync_r	   statusPrintformatSelfLinkr   DeleteBatchPollerrC   rD   r   WaitForOperationBatchjoin)r<   r?   holderr=   rE   requestserrors_to_collect	responsesroperation_refsoperation_refoperation_pollerr>   s                r   RunStop.Run~   s   **4+<+<+>?F]]F''9955f= : ?M
 ##F4@H$$XAI&&'899BKL)Q&&,,QZZ8)NL{{)-

>EE""$& 	' * 
jj()  //&&00- NNn-"))$)) 4-+4- +- 	. &	jj'..|<= &3 Ms   4.H N)__name__
__module____qualname____firstlineno____doc__classmethodr/   r@   rF   rj   __static_attributes__rl   r   r   r   r   C   s(    
 ) 6&/
*>r   r   )rq   r   googlecloudsdk.api_lib.computer   )googlecloudsdk.api_lib.compute.operationsr   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper   ,googlecloudsdk.command_lib.compute.instancesr   googlecloudsdk.corer   rU   r	   DETAILED_HELPUniverseCompatibleReleaseTracksr*   r+   GAr,   SilentCommandr   detailed_helprl   r   r   <module>r      s    (  7 < . ( > = # 	+	*
	
3$N T..1143D3D3I3Ia>4 a> a>H # r   