
                            S r SSKJr  SSKJr  SSKJr  SSK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Jr  SSKJr  SSKJr  S rS r\	R,                  " \	R.                  R0                  5       " S S\	R2                  5      5       r\	R,                  " \	R.                  R6                  5       " S S\5      5       rSSS.\l        g)z(Command to SSH into a Cloud TPU VM Node.    )absolute_import)division)unicode_literalsN)base)
exceptions)
completers)flags)	ssh_utils)ssh)
propertiesc                 b    U R                  SS9nUR                  SSS9  UR                  SSS9  g)z.Argument group for running commands using SSH.z3These arguments are used to run commands using SSH.)helpz	--commanda        Command to run on the Cloud TPU VM.

      Runs the command on the target Cloud TPU VM and then exits.

      Note: in the case of a TPU Pod, it will only run the command in the
      workers specified with the `--worker` flag (defaults to worker 0 if not
      set).
      z--output-directorya(        Path to the directory to output the logs of the commands.

      The path can be relative or absolute. The directory must already exist.

      If not specified, standard output will be used.

      The logs will be written in files named {WORKER_ID}.log. For example:
      "2.log".
      N)add_argument_groupadd_argument)parsercommand_groups     &lib/surface/compute/tpus/tpu_vm/ssh.pyAddCommandArgGroupr   !   sS    ++@ , B-
  
 	
      c                     U R                  SSSS9  U R                  S[        R                  SSS9  U R                  S	[        R                  S
SS9  g)z>Additional flags and positional args to be passed to *ssh(1)*.z
--ssh-flagappenda        Additional flags to be passed to *ssh(1)*. It is recommended that flags
      be passed using an assignment operator and quotes. Example:

        $ {command} example-instance --zone=us-central1-a --ssh-flag="-vvv" --ssh-flag="-L 80:localhost:80"

      This flag will replace occurences of ``%USER%'' and ``%TPU%'' with
      their dereferenced values. For example, passing ``80:%TPU%:80`` into
      the flag is equivalent to passing ``80:162.222.181.197:80'' to *ssh(1)*
      if the external IP address of 'example-instance' is 162.222.181.197.

      If connecting to the instance's external IP, then %TPU% is replaced
      with that, otherwise it is replaced with the internal IP.
      )actionr   user_tpuz
[USER@]TPUz      Specifies the Cloud TPU VM to SSH into.

      ``USER'' specifies the username with which to SSH. If omitted, the user
      login name is used.

      ``TPU'' specifies the name of the Cloud TPU VM to SSH into.
      )	completermetavarr   ssh_argszW          Flags and positionals passed to the underlying ssh implementation.
          zW        $ {command} example-instance --zone=us-central1-a -- -vvv -L 80:%TPU%:80
      )nargsr   exampleN)r   r   InstancesCompleterargparse	REMAINDER)r   s    r   
AddSSHArgsr"   >   st    
  $ 	--
	   	
  r   c                   6    \ rS rSrSrSrSr\S 5       rS r	Sr
g)Sshj   SSH into a Cloud TPU VM.Fc                     [         R                  R                  U5        [        U5        [        R
                  " XR                  U R                  S9  [        U5        [        R                  " USSS9  g)zPSet up arguments for this command.

Args:
  parser: An argparse.ArgumentParser.
)
enable_iapenable_batchingtpur   )resource_typeoperation_typeN)r
   BaseSSHCLIHelperArgsr"   tpu_ssh_utilsAddTPUSSHArgs_ENABLE_IAP_ENABLE_BATCHINGr   r	   AddZoneFlag)clsr   s     r   r.   Ssh.Argsr   sX     ##F+v??030D0DFv	fE%Hr   c           
          [         R                  " UR                  5      u  p#UR                  c6  [        R
                  R                  R                  R                  SS9Ul        UR                  (       a  UR                  (       d  [        R                  " SS5      e[        R                  R                  [        R                  R                  [        R                  R!                  UR                  5      5      5      n[        R                  R#                  U5      (       d&  [        R                  " SSR%                  U5      5      eSUR                  ;   nS /n[&        R(                  " UUUU R+                  5       U R,                  UUS5        SnU R,                  (       aA  US   (       a7  [&        R.                  " UR0                  [3        US   R4                  5      5      n[&        R6                  " UUU5        g )	NT)requiredz--output_directoryz|cannot be specified without the `--command` flag. Please specify the `--command` flag or remove the --output-directory flag.zJFailed to find directory {}. Please create it or specify another directory@r      )r
   GetUserAndInstancer   zoner   VALUEScomputeGetoutput_directorycommandr   InvalidArgumentExceptionospathabspath
expandvars
expanduserisdirformatr/   PrepareNodeForSSHReleaseTrackr2   ParseBatchSize
batch_sizelen
worker_ipsSSHIntoPreppedNodes)selfargsusertpu_nameoutput_directory_pathusername_requestedprepped_nodessh_batch_sizes           r   RunSsh.Run   s   11$--@ND yy##++0044d4Cdi\\11  #'( 	( !ggoo
''

RWW//0E0EF
GIWW]]01111  #..4f5J.KM 	M -6L##		 Na$33
//3|A99:n %%r    N)__name__
__module____qualname____firstlineno____doc__r1   r2   classmethodr.   rX   __static_attributes__rZ   r   r   r$   r$   j   s+      +I I+r   r$   c                        \ rS rSrSrSrSrSrg)SshAlpha   z SSH into a Cloud TPU VM (Alpha).TrZ   N)r[   r\   r]   r^   r_   r1   r2   ra   rZ   r   r   rc   rc      s    (+r   rc   r&   a  
        To SSH into a Cloud TPU VM, run:

            $ {command} my-tpu

        To SSH into worker 1 on a Cloud TPU VM Pod, run:

            $ {command} my-tpu --worker=1

        To run an SSH command in a Cloud TPU VM (for example, to print the
        time since last boot), run:

            $ {command} my-tpu --command="last boot"

        To run the same command in all workers in a Cloud TPU VM simultaneously,
        run:

            $ {command} my-tpu --command="last boot" --worker=all
        )briefEXAMPLES)r_   
__future__r   r   r   r    os.pathrB   googlecloudsdk.callioper   r   "googlecloudsdk.command_lib.computer   r	   r
   .googlecloudsdk.command_lib.compute.tpus.tpu_vmr   r/   googlecloudsdk.corer   r   r"   ReleaseTracksrJ   GACommandr$   ALPHArc   detailed_helprZ   r   r   <module>rr      s    / &  '   ( . 9 4 8 O *:)X D%%(()@$,, @ *@F D%%++,s  - 	#		 r   