
    A                     j   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ddZ ej&                  ej(                  j*                  ej(                  j,                  ej(                  j.                         G d dej0                               Zee_        y)z*Command for resuming a suspended instance.    )absolute_import)division)unicode_literals)base_classes)poller)waiter)base)flags)
exceptions)logz"Resume a virtual machine instance.zm        *{command}* is used to resume a previously suspended Compute
        Engine virtual machine.
        zg        To resume an instance named ``test-instance'', run:

          $ {command} test-instance
      )briefDESCRIPTIONEXAMPLESc                   ,    e Zd ZdZed        Zd Zd Zy)ResumezResume a virtual machine instance.

  *{command}* is used to resume a previously suspended Compute Engine
  virtual machine.
  c                     t         j                  j                  |       t        j                  j                  |       y N)r
   INSTANCES_ARGAddArgumentr	   
ASYNC_FLAGAddToParser)clsparsers     'lib/surface/compute/instances/resume.pyArgszResume.Args7   s(    	##F+OO'    c                 
   g }|D ]j  }|j                   j                  |j                         |j                  |j                        }|j                  |j                  j                  d|f       l |j                  |      }|S )z?Fetches instance objects corresponding to the given references.)instancezoneprojectGet)	messagesComputeInstancesGetRequestNamer   r    appendapitools_client	instancesMakeRequests)selfclientrefsinstance_get_requestsrefrequest_protobufr'   s          r   GetInstanceszResume.GetInstances<   s    CC88:CHHckk D C""F$:$:$D$De$4$6 7  ##$9:Ir   c           
         t        j                  | j                               }|j                  }g }t        j
                  j                  ||j                  t	        j                  |            }|D ]j  }|j                  j                  d|j                  j                  |j                         |j                  |j                        f}|j!                  |       l g }|j#                  ||      }	|rt%        j&                  |      |	D 
cg c]'  }
|j                  j)                  |
j*                        ) }}
|j,                  rd|D ]>  }t.        j0                  j3                  dj5                  |j7                                      @ t.        j0                  j3                  d       |	S t9        j:                  ||j                  j                  |      }t=        j>                  |t9        j@                  |      dj5                  djC                  d |D                    d 	      }|D ]0  }t.        j0                  j3                  d
j5                  |             2 |S c c}
w )N)scope_listerr   )r   r    r   z%Resume instance in progress for [{}].z]Use [gcloud compute operations describe URI] command to check the status of the operation(s).zResuming instance(s) {0}z, c              3   <   K   | ]  }|j                           y wr   )r$   ).0is     r   	<genexpr>zResume.Run.<locals>.<genexpr>q   s      4-+AFFHms   )max_wait_mszUpdated [{0}].)"r   ComputeApiHolderReleaseTrackr*   r
   r   ResolveAsResource	resourcesGetInstanceZoneScopeListerr&   r'   r"   ComputeInstancesResumeRequestr$   r    r   r%   AsyncRequestsr   
MultiErrorParseselfLinkasync_r   statusPrintformatSelfLinkr   BatchPollerr   WaitForOperationBatchjoin)r)   argsholderr*   request_listinstance_refsinstance_refrequesterrors_to_collect	responsesroperation_refsoperation_refoperation_pollerresults                  r   Runz
Resume.RunH   s$   **4+<+<+>?F]]FL''9955f= : ?M
 &''118>>*//1)11&++ ? -.g '" & $$\3DEI!!"344BKL)Qf&&,,QZZ8)NL{{)-

@GG""$& 	' * 
jj() ))&&00-A ^^n-"))$)) 4-+4- +- 	.F &	jj'..|<= & M1 Ms   ,I N)__name__
__module____qualname____doc__classmethodr   r/   rW    r   r   r   r   .   s%     ( (
0r   r   N)r[   
__future__r   r   r   googlecloudsdk.api_lib.computer   )googlecloudsdk.api_lib.compute.operationsr   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper	   ,googlecloudsdk.command_lib.compute.instancesr
   googlecloudsdk.corer   r   DETAILED_HELPReleaseTracksr8   ALPHABETAGASilentCommandr   detailed_helpr]   r   r   <module>rl      s    1 &  ' 7 < . ( > * # 	-	
	
" D%%++T->->-C-C%%((*HT H*HV % r   