
    \                         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\R                  5      r " S S\	R"                  5      rg)z:Command for reading the serial port output of an instance.    )absolute_import)division)unicode_literals)base_classes)arg_parsers)base)flags)
exceptions)logc                       \ rS rSrSrSrg)GetSerialPortOutputException   z0An error occurred while tailing the serial port. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       7lib/surface/compute/instances/get_serial_port_output.pyr   r      s    8r   r   c                   <    \ rS rSrSrSS0r\S 5       rS rS r	Sr
g	)
GetSerialPortOutput!   a!  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                     U R                   R                  S5        [        R                  R	                  U 5        U R                  S[        R                  " SS5      SS9  U R                  S[        SS9  g	)
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   ArgsGetSerialPortOutput.Args1   sx     !!"=>	""6*
##Aq)     r   c           
         [         R                  " U R                  5       5      nUR                  n[        R
                  R                  XR                  [        R                  " U5      S9nUR                  R                  SUR                  R                  UR                  5       UR                  UR                  UR                   UR"                  S94n/ nUR%                  U/US9nU(       a0  ['        SSR)                  U Vs/ s H  oS   PM	     sn5      -   5      eUS   n	UR                   U l        Xl        U	$ s  snf )	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/   r0   r1   MakeRequestsr   join_start	_response)
selfargsholderr7   instance_refrequesterrorsobjectserrorresponses
             r   RunGetSerialPortOutput.RunJ   s5   **4+<+<+>?F]]F%%7755f= 8 ?L %%//$II(--/'//		$)) J +,G F!!  " "G (
0
((&1&!H&1
234 4 qzH**DKNO 2s   D?c                 d   U R                   (       a]  U R                  R                  U R                   :w  a9  [        R                  " SR                  U R                  R                  5      5        [        R                  R                  SR                  U R                  R                  5      5        g )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.)	rB   rC   r0   r   warningformatstatusPrintnext)rD   unused_resources_were_displayeds     r   EpilogGetSerialPortOutput.Epilogi   sv    {{t~~++t{{:	kk>>Dfnn""?$% JJ	99?NN:!"r   )rC   rB   N)r   r   r   r   r   detailed_helpstaticmethodr)   rM   rV   r   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>ra      sJ    A &  ' 7 / ( > * #9:#3#3 9Q"$,, Q"r   