
                            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SKJr  SSKJr  SSKJr  SSKJr  S r\
R6                  " \
R8                  R:                  \
R8                  R<                  5       " S S\
R>                  5      5       r SSS.\ l!        g)z=Command to SCP to/from a Cloud TPU Queued Resource's Node(s).    )absolute_import)division)unicode_literalsN)FilesCompleter)base)
exceptions)flags)	ssh_utils)ssh)util)log)
propertiesc                     U R                  SSSS9  U R                  S[        SSSS	9  U R                  S
SSS9  U R                  SSSS9  U R                  SSSS9  U R                  SSSS9  g)z>Additional flags and positional args to be passed to *scp(1)*.z
--scp-flagappendzR      Additional flags to be passed to *scp(1)*. This flag may be repeated.
      )actionhelpsourceszSpecifies the files to copy.z[[USER@]INSTANCE:]SRC+)	completerr   metavarnargsdestinationz-Specifies a destination for the source files.z[[USER@]INSTANCE:]DEST)r   r   z	--recurse
store_truezUpload directories recursively.z
--compresszEnable compression.--node0a-            TPU node(s) to connect to. The supported value is a single 0-based
          index of the node(s) in the case of a TPU Pod. It additionally
          supports a comma-separated list (e.g. '1,4,6'), range (e.g. '1-3'), or
          special keyword ``all" to run the command concurrently on each of the
          specified node(s).

          Note that when targeting multiple nodes, you should run 'ssh-add'
          with your private key prior to executing the gcloud command. Default:
          'ssh-add ~/.ssh/google_compute_engine'.
          )defaultr   N)add_argumentr   )parsers    0lib/surface/compute/tpus/queued_resources/scp.py
AddSCPArgsr    %   s    
   	)%   	:&   	,-N   	<.C   	
      c                   :    \ rS rSrSrSrSrSr\S 5       r	S r
Srg)	ScpV   ;Copy files to and from a Cloud TPU Queued Resource via SCP.T@   c                     [         R                  R                  U5        [        R                  " UU R
                  U 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_batching_defaulttpuscp)resource_typeoperation_typeN)r
   BaseSSHCLIHelperArgstpu_ssh_utilsAddTPUSSHArgs_ENABLE_IAP_ENABLE_BATCHINGDEFAULT_BATCH_SIZEr    r	   AddZoneFlag)clsr   s     r   r.   Scp.Args^   s^     ##F+ # 6 6	 v	fE%Hr!   c                    [         R                   " 5       n[        R                  R                  UR                  5      nUR
                   Vs/ s H"  n[        R                  R                  U5      PM$     nn[        R                  R                  XSSS9  UR                  =(       d    US   R                  nUR                  nUR                  (       d  U H	  nXdl        M     SnUR                  (       d  Sn[        R                  " SS9Ul
        UR                  c6  [        R                  R                  R                  R!                  SS9Ul        ["        R$                  " U R'                  5       5      n	U	R!                  XqR                  5      n
[(        R*                  " UR,                  U
R.                  R0                  5      n[3        U5      S:  a+  US   R                  (       a  [4        R6                  " SS	5      e/ nSn[3        U5      n[8        R:                  " UR<                  [3        U5      5      nS /U-  n[?        U5       H  u  nnURA                  [B        RD                  " [8        RF                  URH                  UU R'                  5       U RJ                  UUUUUU4
S
95        US   RM                  5         US-  nX:X  d  M  [(        RN                  " UU5        Sn/ nM     US:  a  [(        RN                  " UU5        U Vs/ s H
  nUc  M  UPM     nn[3        U5      U:  a%  [P        RR                  " SRU                  U5      5        [8        R:                  " UR<                  U RV                  5      n[8        RX                  " UUU5        [P        RZ                  R]                  S[         R                   " 5       U-
  -  5        g s  snf s  snf )NT)single_remoter   F)warn_on_account_user)required   r   z;cannot target multiple nodes while copying files to client.)targetargsz@Could not prepare all {} nodes, attempting to ssh into the rest.z!Completed execution in %s seconds)/timer   FileReferenceFromPathr   r   
SCPCommandVerifyremotehostuserGetDefaultSshUsernamezoner   VALUEScomputeGetqueued_resource_utilsTPUQueuedResourceReleaseTrackqr_ssh_utilsParseNodeFlagnoder)   nodeSpeclenr   InvalidArgumentExceptionr/   ParseBatchSize
batch_size	enumerater   	threadingThreadPrepareNodeForSCPnodeIdr2   startWaitForNodeBatchCompletionr   warningformatr3   SCPIntoPreppedNodesstatusPrint)selfr=   
start_timedstsrcsrcsrD   qr_nameusername_requestedqueued_resource_clientqueued_resource
node_specsprep_nodes_threadscurrent_batch_size	num_nodesprep_node_batch_sizeprepped_nodesindexrQ   prepped_nodescp_batch_sizes                        r   RunScp.Runo   sQ   J



$
$T%5%5
6C7;||D|C&&s+|DDNN$48ZZ)47>>FkkG::#
  ;; --4Hfk yy##++0044d4Cdi2DD -00))DO ++		?&&//J :tAw~~//

G 
 JI(77Z FY&M ,t


"44++##%''$" ""$A		3//	
 3 -6 A--.@-P
 *)L 	)  
 =I%	kk6)$
 #1100N %% JJ+tyy{Z/GH} ETs   )OOO N)__name__
__module____qualname____firstlineno____doc__r1   r2   r3   classmethodr.   ru   __static_attributes__rw   r!   r   r#   r#   V   s0    C+I I cr!   r#   r%   a  
        To copy a file (for example, a text file in the local home directory) to
        a Cloud Queued Resource, run:

            $ {command} ~/my-file my-qr:

        To copy a file into all nodes and workers in a Cloud TPU Queued Resource (with the default batch size), run:

            $ {command} ~/my-file my-qr: --worker=all --node=all

        To copy a file into all nodes and workers in a Cloud TPU Queued Resource with a batch size of 4, run:

            $ {command} ~/my-file my-qr: --worker=all --node=all --batch-size=4

        To copy a file into all workers in the first node of a Cloud TPU Queued Resource, run:

            $ {command} ~/my-file my-qr: --worker=all

        To copy a file from a Cloud TPU Queued Resource to the home directory of the local
        computer, run:

            $ {command} my-qr:~/my-file ~/

        To copy all files in a folder to a Cloud TPU Queued Resource, run:

            $ {command} ~/my-folder/ my-qr: --recurse
        )briefEXAMPLES)"r|   
__future__r   r   r   rX   r?   argcomplete.completersr   googlecloudsdk.callioper   r   "googlecloudsdk.command_lib.computer	   r
   8googlecloudsdk.command_lib.compute.tpus.queued_resourcesr   rO   r   rL   .googlecloudsdk.command_lib.compute.tpus.tpu_vmr/   #googlecloudsdk.command_lib.util.sshgooglecloudsdk.corer   r   r    ReleaseTracksrN   ALPHAGACommandr#   detailed_helprw   r!   r   <module>r      s    D &  '   1 ( . 4 8 X b O 3 # *.b D%%++T->->-A-AB{$,, { C{~ K r!   