
                         4   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SKJr  SSKJr  S r " S S\R4                  5      r " S S\R8                  5      rS r\" 5       \l        g)z!Command for starting an instance.    )absolute_import)division)unicode_literals)base_classes)
csek_utils)poller)waiter)base)flags)GetExternalIPAddress)GetInternalIPAddress)
exceptions)log)	resources)zipc                     [         R                  R                  U 5        [        R                  " U SS9  [
        R                  R                  U 5        g)z*Add parser arguments common to all tracks.F)flags_about_creationN)r   INSTANCES_ARGAddArgumentr   AddCsekKeyArgsr
   
ASYNC_FLAGAddToParserparsers    &lib/surface/compute/instances/start.py_CommonArgsr   $   s8    !!&)F?//f%    c                       \ rS rSrSrg)FailedToFetchInstancesError+    N)__name__
__module____qualname____firstlineno____static_attributes__r!   r   r   r   r   +   s    r   r   c                   4    \ rS rSrSr\S 5       rS rS rSr	g)Start/   )Start a stopped virtual machine instance.c                     [        U 5        g N)r   r   s    r   Args
Start.Args2   s
    r   c                    / nU Hh  nUR                   R                  UR                  5       UR                  UR                  S9nUR                  UR                  R                  SU45        Mj     UR                  U5      nU$ )z?Fetches instance objects corresponding to the given references.)instancezoneprojectGet)	messagesComputeInstancesGetRequestNamer1   r2   appendapitools_client	instancesMakeRequests)selfclientrefsinstance_get_requestsrefrequest_protobufr9   s          r   GetInstancesStart.GetInstances6   s    CC88:xx++ D  ""F$:$:$D$De$4$6 7  ##$9:Ir   c           
      	   [         R                  " U R                  5       5      nUR                  nUR                  n/ n[
        R                  R                  XR                  [
        R                  " U5      S9nU(       a  U R                  X65      nOU Vs/ s H  nS PM     nn[        Xg5       GH  u  p/ nU(       a  U R                  5       [        R                  R                  [        R                  R                  4;   n[        R                   R#                  X5      nU
R$                   H  n[        R&                  R)                  UR*                  5      n[        R,                  " XUR.                  5      nU(       d  MV  UR1                  UR2                  R5                  UUR*                  S95        M     U(       ao  UR2                  R7                  US9nUR.                  R8                  SUR2                  R;                  U	R=                  5       UU	R>                  U	R@                  S94nOTUR.                  R8                  SUR2                  RC                  U	R=                  5       U	R>                  U	R@                  S94nUR1                  U5        GM     / nURE                  UU5      nU(       a  [F        RH                  " U5      eU Vs/ s H(  nUR                  R)                  URJ                  5      PM*     nnURL                  (       af  U H?  n[N        RP                  RS                  SRU                  URW                  5       5      5        MA     [N        RP                  RS                  S	5        U$ [X        RZ                  " X3R.                  R8                  U5      n[\        R^                  " U[X        R`                  " U5      S
RU                  SRc                  S U 5       5      5      S S9n[        UU5       H  u  n	n[N        RP                  RS                  SRU                  U	5      5        [N        RP                  RS                  SRU                  [e        U5      5      5        [g        USS9(       d  M|  [N        RP                  RS                  SRU                  [g        U5      5      5        M     U$ s  snf s  snf )N)scope_lister)diskEncryptionKeysource)disksStartWithEncryptionKey)r0   &instancesStartWithEncryptionKeyRequestr2   r1   r(   )r0   r2   r1   z$Start instance in progress for [{}].z]Use [gcloud compute operations describe URI] command to check the status of the operation(s).zStarting instance(s) {0}z, c              3   @   #    U  H  oR                  5       v   M     g 7fr,   )r6   ).0is     r   	<genexpr>Start.Run.<locals>.<genexpr>   s      4-+FFHHms   )max_wait_mszUpdated [{0}].zInstance internal IP is {0}T)no_raisezInstance external IP is {0})4r   ComputeApiHolderReleaseTrackr<   csek_key_filer   r   ResolveAsResourcer   GetInstanceZoneScopeListerrA   r   r
   ALPHABETAr   CsekKeyStoreFromArgsrG   REGISTRYParserF   MaybeLookupKeyMessager8   r7   r4   "CustomerEncryptionKeyProtectedDisk&InstancesStartWithEncryptionKeyRequestr9   -ComputeInstancesStartWithEncryptionKeyRequestr6   r2   r1   ComputeInstancesStartRequestAsyncRequestsr   
MultiErrorselfLinkasync_r   statusPrintformatSelfLinkr   BatchPollerr	   WaitForOperationBatchjoinr   r   )r;   argsholderr<   rS   request_listinstance_refsr9   _instance_refr0   rG   allow_rsa_encrypted	csek_keysdiskdisk_resourcedisk_key_or_noneencryption_reqrequesterrors_to_collect	responsesroperation_refsoperation_refoperation_pollerresultress                              r   Run	Start.RunD   s   **4+<+<+>?F]]F&&ML''9955f= : ?M ##F:i!./A4i/"%m"?e	"//1d6G6G6M6M6:6G6G6L6L6N N++44TO	NND#,,224;;?-'==(>(>@
 LLKK"2{{ L $ % # 
OO P  "",,$OOII%**,7E$,,!&&	 J () "",,OO88%**,$,,!&& 9 () '"O #@R $$\3DEI!!"344BKL)Qf&&,,QZZ8)NL{{)-

?FF""$& 	' * 
jj() ))&&00-A ^^n-"))$)) 4-+4- +- 	.F !7c	jj'..|<=	jj4;;
s
#% &	cD	1	1

6== %' 	( 8 M[ 0^ Ms   R:/R?r!   N)
r"   r#   r$   r%   __doc__staticmethodr-   rA   r   r&   r!   r   r   r(   r(   /   s"    1 Yr   r(   c                      SSSS.n U $ )z7Construct help text based on the command release track.r*   z
        *{command}* is used to start a stopped Compute Engine virtual
        machine. Only a stopped virtual machine can be started.
        z
        To start a stopped instance named 'example-instance' in zone
        ``us-central1-a'', run:

          $ {command} example-instance --zone=us-central1-a
        )briefDESCRIPTIONEXAMPLESr!   )detailed_helps    r   DetailedHelpr      s      ;- 
r   N) r   
__future__r   r   r   googlecloudsdk.api_lib.computer   r   )googlecloudsdk.api_lib.compute.operationsr   googlecloudsdk.api_lib.utilr	   googlecloudsdk.callioper
   ,googlecloudsdk.command_lib.compute.instancesr   ,googlecloudsdk.command_lib.compute.ssh_utilsr   r   googlecloudsdk.corer   r   r   	six.movesr   r   Errorr   SilentCommandr(   r   r   r!   r   r   <module>r      st     ( &  ' 7 5 < . ( > M M * # ) &*"2"2 nD nb$ #n r   