
    \                         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  G d dej                        Z G d de	j"                        Zy)z:Command for reading the serial port output of an instance.    )absolute_import)division)unicode_literals)base_classes)arg_parsers)base)flags)
exceptions)logc                       e Zd ZdZy)GetSerialPortOutputExceptionz0An error occurred while tailing the serial port.N)__name__
__module____qualname____doc__     7lib/surface/compute/instances/get_serial_port_output.pyr   r      s    8r   r   c                   4    e Zd ZdZddiZed        Zd Zd Zy)GetSerialPortOutputa+  Read output from a virtual machine instance's serial port.

  {command} is used to get the output from a Compute
  Engine virtual machine's serial port. The serial port output
  from the virtual machine will be printed to standard output. This
  information can be useful for diagnostic purposes.
  EXAMPLESzp
  To get the output from instance's serial port, run:

    $ {command} example-instance --zone=us-central1-b
  c                     | j                   j                  d       t        j                  j	                  |        | j                  dt        j                  dd      d       | j                  dt        d       y	)
zAdd expected arguments.zvalue[no-quote](contents)z--port      a          Instances can support up to four serial port outputs, numbered 1 through
        4. By default, this command will return the output of the first serial
        port. Setting this flag will return the output of the requested serial
        port.
        )typehelpz--starta2          Specifies the byte index (zero-based) of the first byte you want
        returned.  Use this flag if you want to continue getting the output from
        a previous request that was too long to return in one attempt.  The last
        byte returned in a request will be reported on STDERR.
        N)	display_info	AddFormatr	   INSTANCE_ARGAddArgumentadd_argumentr   
BoundedIntint)parsers    r   ArgszGetSerialPortOutput.Args1   sx     !!"=>	""6*
##Aq)     r   c           
         t        j                  | j                               }|j                  }t        j
                  j                  ||j                  t	        j                  |            }|j                  j                  d|j                  j                  |j                         |j                  |j                  |j                   |j"                        f}g }|j%                  |g|      }|r.t'        ddj)                  |D cg c]  }|d   	 c}      z         |d   }	|j                   | _        |	| _        |	S c c}w )	N)scope_listerr   )instanceprojectportstartzone)requestserrors_to_collectz$Could not fetch serial port output: ,r   r   )r   ComputeApiHolderReleaseTrackclientr	   r   ResolveAsResource	resourcesGetInstanceZoneScopeListerapitools_client	instancesmessages*ComputeInstancesGetSerialPortOutputRequestNamer)   r*   r+   r,   MakeRequestsr   join_start	_response)
selfargsholderr2   instance_refrequesterrorsobjectserrorresponses
             r   RunzGetSerialPortOutput.RunJ   s;   **4+<+<+>?F]]F%%77f55f= 8 ?L %%//$II(--/'//		$)) J +,G F!!  " "G (
0
((&1&E!H&1
234 4 qzH**DKDNO 2s   	Ec                 V   | j                   r[| j                  j                  | j                   k7  r8t        j                  dj                  | j                  j                               t        j                  j                  dj                  | j                  j                               y )NzoSome serial port output was lost due to a limited buffer. The oldest byte of output returned was at offset {0}.zq
Specify --start={0} in the next get-serial-port-output invocation to get only the new output starting from here.)	r=   r>   r+   r   warningformatstatusPrintnext)r?   unused_resources_were_displayeds     r   EpilogzGetSerialPortOutput.Epilogi   sv    {{t~~++t{{:	kk>>Dfnn""?$% JJ	99?NN:!"r   N)	r   r   r   r   detailed_helpstaticmethodr%   rH   rP   r   r   r   r   r   !   s6      -  0>	"r   r   N)r   
__future__r   r   r   googlecloudsdk.api_lib.computer   googlecloudsdk.callioper   r   ,googlecloudsdk.command_lib.compute.instancesr	   googlecloudsdk.corer
   r   Errorr   Commandr   r   r   r   <module>rZ      sJ    A &  ' 7 / ( > * #9:#3#3 9Q"$,, Q"r   