
                             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Jr  SSKJr  SSS.rSSS.rS r\R(                  " \R*                  R,                  5       " S S\R.                  5      5       r\\l        g)zCommand for attaching a persistent disk to a TPU VM.

Allows TPU VM users to attach persistent disks to TPUs
in a form that is decoupled from the Create and Delete
lifecycle of the actual TPU VM.
    )absolute_import)division)unicode_literalsN)base)
exceptions)resource_args)util)concept_parsers)
propertieszWRead-write. It is an error to attach a disk in read-write mode to more than one TPU VM.z
Read-only.)
read-write	read-onlyaP  
        *{command}* is used to attach a disk to a TPU VM. For example,

          $ gcloud compute tpus tpu-vm attach-disk example-tpu --disk=example-disk --mode=read-only --zone=us-central1-a

        attaches the disk named 'example-disk' to a TPU VM named
        'example-tpu' in read-only mode in zone ``us-central1-a''.

        a!  
        To attach a disk named 'my-disk' for read-only access to a TPU named
        'my-tpu', run:

          $ {command} my-tpu --disk=my-disk --mode=read-only

        To attach a disk named 'my-read-write-disk' for read-write access to
        a TPU named 'my-tpu', run:

          $ {command} my-tpu --disk=my-read-write-disk

        To attach a regional disk named for read-write access to a TPU named
        'my-tpu', run:

          $ {command} my-tpu --disk=projects/tpu-test-env-one-vm/region/us-central1/disks/example-disk
        )DESCRIPTIONEXAMPLESc                     [         R                  R                  S[        R                  " S5      SR                  U5      SS9R                  U 5        g)zAdds a TPU Name resource argument.

NOTE: May be used only if it's the only resource arg in the command.

Args:
  parser: the argparse parser for the command.
  verb: str, the verb to describe the resource, such as 'to attach'.
tpuTPUzThe TPU function name {}.TrequiredN)r
   ConceptParserForResourcer   GetTPUResourceSpecformatAddToParser)parserverbs     .lib/surface/compute/tpus/tpu_vm/attach_disk.pyAddTPUResourceArgr   I   sK     ++&&u-!((.	 ,  ![(    c                   .    \ rS rSrSr\S 5       rS rSrg)
AttachDiskZ   zAttach disk to TPU VM.c                 j    U R                  SSSS9  U R                  S[        SSS9  [        U S	5        g
)zPSet up arguments for this command.

Args:
  parser: An argparse.ArgumentParser.
z--diskz-The name of the disk to attach to the TPU VM.T)helpr   z--moder   zSpecifies the mode of the disk.)choicesdefaultr#   zto attach diskN)add_argumentMODE_OPTIONSr   )r   s    r   ArgsAttachDisk.Args^   sN     <  
 .	  0 f./r   c                 $   UR                   c6  [        R                  R                  R                   R	                  SS9Ul         UR
                  R                  R                  5       n[        R                  " U R                  5       5      nUR	                  UR                  5       UR                   5      n[        R                  " U5      (       d  [        R                  " SS5      eUR                  S:X  a0  UR                   R"                  R$                  R&                  Ul        OWUR                  S:X  a0  UR                   R"                  R$                  R(                  Ul        O[        R                  " SS5      e[*        R,                  " S	UR.                  5      nU(       a  UR.                  nOV[        R                  R0                  R2                  R	                  SS9nS
U-   S-   UR                   -   S-   UR.                  -   nUR4                  (       d@  UR                   R#                  UR                  US9nUR4                  R7                  U5        O/ n	UR4                   H  n
U	R7                  U
R8                  5        M      Xi;  a@  UR                   R#                  UR                  US9nUR4                  R7                  U5        O[        R                  " SS5      eUR;                  UR                  5       UR                   USSS9$ )NTr   r   zthis command is only available for Cloud TPU VM nodes. To access this node, please see https://cloud.google.com/tpu/docs/creating-deleting-tpus.r   r   modez6can only attach disks in read-write or read-only mode.z'projects/.+/(zones|regions)/.+/disks/.+z	projects/z/zones/z/disks/)r+   
sourceDiskz'disk is already attached to the TPU VM.
data_diskszAttaching disk to TPU VM)namezonenodeupdate_maskpoller_message)r/   r   VALUEScomputeGetCONCEPTSr   Parse	tpu_utilsTPUNodeReleaseTrackNameIsTPUVMNoder   BadArgumentExceptionr+   messagesAttachedDiskModeValueValuesEnum
READ_WRITE	READ_ONLYrematchdiskcoreproject	dataDisksappendr,   
UpdateNode)selfargstpu_name_refr   r0   source_path_matchsource_pathrG   disk_to_attachsource_disk_listrE   s              r   RunAttachDisk.Runs   s   yy##++0044d4Cdi ==$$**,L


D--/
0C77<$$&		2D  &&++
FG G yyL ,,++??JJdi	k	!,,++??IIdi++
J  !K!%,IIk!!&&..22D2Ag

)
+dii
7)
Cdii
O  >>||00yy  1 n nnN+..$0 !		,22" 3 
 	n---<> 	> >> YY 1   r    N)	__name__
__module____qualname____firstlineno____doc__staticmethodr(   rR   __static_attributes__rT   r   r   r    r    Z   s    0 0(>r   r    )rY   
__future__r   r   r   rC   googlecloudsdk.callioper   r   .googlecloudsdk.command_lib.compute.tpus.tpu_vmr   r	   r8   (googlecloudsdk.command_lib.util.conceptsr
   googlecloudsdk.corer   r'   DETAILED_HELPr   ReleaseTracksr:   ALPHACommandr    detailed_helprT   r   r   <module>rf      s    '  ' 	 ( . H L D *
! 			>)" D%%++,V V -Vp )
 r   