ó
    €Ïî  ã                   óˆ   • S r SSKJr  SSKJr  SSKJ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rS
 r   SS jrS rg)z0Helpers for running commands external to gcloud.é    )Úabsolute_import)Údivision)Úunicode_literalsN)Ú	ssh_utils)Ú
containers)Ússh)Úlogc           	      óÞ  •  [         R                  " U[         R                  [         R                  S9n[        UR                  R
                  S5       H@  n[        R                  R                  U5        [        R                  R                  5         MB     UR                  5         UR                  S:w  a1  [        UR                  R                  5       R                  5       5      eg! [         ax  n[        R                   R#                  SU < S[$        R&                  " U5      < 35        SR)                  U5      n[        R                   R#                  SU-  5         SnAgSnAff = f)	a   Runs a subprocess and prints out the output.

Args:
  proc_name: The name of the subprocess to call.
    Used for error logging.
  command_list: A list with all the arguments for a subprocess call.
    Must be able to be passed to a subprocess.Popen call.
)ÚstdoutÚstderrÚ r   zError running z: Ú zINVOCATION: %sN)Ú
subprocessÚPopenÚPIPEÚiterr   Úreadliner	   ÚoutÚwriteÚflushÚwaitÚ
returncodeÚOSErrorr   ÚreadÚstripÚerrÚPrintÚsixÚ	text_typeÚjoin)Ú	proc_nameÚcommand_listÚprocÚlÚeÚcommand_list_strs         ÚBlib/googlecloudsdk/command_lib/compute/diagnose/external_helper.pyÚRunSubprocessr(      sõ   € ð7Ü×ÒØœZŸ_™_´Z·_±_ñF€Dä$—+‘+×&Ñ&¨Ö+ˆÜ	‡gg‡mmAÔÜ	‡gg‡mm†oñ ,ð 	‡II„KØ‡˜!ÓäD—K‘K×$Ñ$Ó&×,Ñ,Ó.Ó/Ð/ð øô 
ó 7Ü‡GG‡M‚M«I´s·}²}ÀQÕ7GÐHÔIØ—x‘x Ó-ÐÜ‡GG‡MMÐ"Ð%5Ñ5×6Ñ6ûð7ús   ‚C'C* Ã*
E,Ã4A.E'Å'E,c           	      ó¼  • [         R                  " U5      n[         R                  " U5      n	[        R                  " X‚5      n
SnSnUR
                  (       dF  UR                  R                  nUR                  [         R                  " U5      UR                  5      n[        R                  " X:UU	5      n/ n[        R                  " SU 5      n[        R                  " U
UUUUUS9nU(       a4  [        SR!                  UR#                  UR$                  5      5      5        gUR'                  UR$                  UUS9n[(        R*                  R-                  5         U$ )a’  Runs a SSH command to a Google Compute Engine VM.

Args:
  command_list: List with the ssh command to run.
  instance: The GCE VM object.
  user: The user to be used for the SSH command.
  args: The args used to call the gcloud instance.
  ssh_helper: ssh_utils.BaseSSHCLIHelper instance initialized
    for the command.
  explicit_output_file: Use this file for piping stdout of the SSH command,
                        instead of using stdout. This is useful for
                        capturing the command and analyzing it.
  explicit_error_file: Use this file for piping stdout of the SSH command,
                       instead of using stdout. This is useful for
                       capturing the command and analyzing it.
  dry_run: Whether or not this is a dry-run (only print, not run).
Returns:
  The exit code of the SSH command
Raises:
  ssh.CommandError: there was an error running a SSH command
N)Úidentity_fileÚoptionsÚextra_flagsÚremote_commandÚ	remainderr   r   )Úexplicit_output_fileÚexplicit_error_file)r   ÚGetExternalIPAddressÚGetInternalIPAddressr   ÚRemoteÚplainÚkeysÚkey_fileÚ	GetConfigÚHostKeyAliasÚstrict_host_key_checkingÚParseAndSubstituteSSHFlagsr   ÚGetRemoteCommandÚ
SSHCommandÚ	DryRunLogr    ÚBuildÚenvÚRunr	   r   r   )r"   ÚinstanceÚuserÚargsÚ
ssh_helperr/   r0   Údry_runÚexternal_addressÚinternal_addressÚremoter*   r+   r,   r.   r-   ÚcmdÚreturn_codes                     r'   ÚRunSSHCommandToInstancerK   7   s'  € ô: ×3Ò3°HÓ=ÐÜ×3Ò3°HÓ=ÐÜ:Š:Ð&Ó-€&à€-Ø€'Ø	Ø—O‘O×,Ñ,€MØ×"Ñ"¤9×#9Ò#9¸(Ó#CØ#'×#@Ñ#@óB€Gä×.Ò.¨tÐ=MØ/?óA€+à€)ä×.Ò.¨t°\ÓB€.äŠØØ!ØØØ#Øñ	€#ö Üˆch‰hs—y‘y §¡Ó0Ó1Ô2Øà—‘Ø‡nnØ/Ø-ð ð /€+ô ‡''‡--„/Ø	Ðó    c                 óH   • [         R                  R                  SU -  5        g )Nz[COMMAND TO RUN]: %s
)r	   r   r   )Úmsgs    r'   r=   r=   w   s   € Ü‡''‡--Ð(¨3Ñ.Õ/rL   )NNF)Ú__doc__Ú
__future__r   r   r   r   Ú"googlecloudsdk.command_lib.computer   Ú#googlecloudsdk.command_lib.util.sshr   r   Úgooglecloudsdk.corer	   r   r(   rK   r=   © rL   r'   Ú<module>rU      s@   ðñ 7å &Ý Ý 'ã Ý 8Ý :Ý 3Ý #Û 
ò7ð> 26Ø04Ø$)ô=ó@0rL   