
    k                        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 r\R&                  " \R(                  R*                  5       " S S\R,                  5      5       r\\l        g)zCommand for detaching a persistent disk to a TPU VM.

Allows TPU VM users to detach 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)
propertiesa3  
        *{command}* is used to detach a disk from a TPU VM. For example,

          $ gcloud compute tpus tpu-vm detach-disk example-tpu --disk=example-disk --zone=us-central1-a

        detaches the disk named `example-disk` from the TPU VM named
        `example-tpu` in zone ``us-central1-a''.

        a>  
        To detach a disk named `my-disk` from a TPU named `my-tpu`, run:

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

        To detach a regional disk with the below path from 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 detach'.
tpuTPUzThe TPU {} from.TrequiredN)r
   ConceptParserForResourcer   GetTPUResourceSpecformatAddToParser)parserverbs     .lib/surface/compute/tpus/tpu_vm/detach_disk.pyAddTPUResourceArgr   ;   sK     ++&&u-%	 ,  ![(    c                   .    \ rS rSrSr\S 5       rS rSrg)
DetachDiskL   zDetach a disk from an instance.c                 >    U R                  SSSS9  [        U S5        g)zPSet up arguments for this command.

Args:
  parser: An argparse.ArgumentParser.
z--diskz+Name of the disk to detach from the TPU VM.T)helpr   zto detach diskN)add_argumentr   )r   s    r   ArgsDetachDisk.ArgsP   s-     :  
 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                  (       d  [        R                  " SS5      e[         R"                  " SUR$                  5      nU(       a  UR$                  nOV[        R                  R&                  R(                  R	                  SS9nSU-   S-   UR                   -   S	-   UR$                  -   n/ nUR                   H  n	UR+                  U	R,                  5        M      [/        U5       H   u  pXk:w  a  M  Xk:X  d  M  UR                  U
	   O   [        R                  " SS
5      eUR1                  UR                  5       UR                   USS5      $ )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.z,no data disks to detach from current TPU VM.z'projects/.+/(zones|regions)/.+/disks/.+z	projects/z/zones/z/disks/zCerror: specified data disk is not currently attached to the TPU VM.
data_diskszDetaching disk from TPU VM)zoner   VALUEScomputeGetCONCEPTSr   Parse	tpu_utilsTPUNodeReleaseTrackNameIsTPUVMNoder   BadArgumentException	dataDisksrematchdiskcoreprojectappend
sourceDisk	enumerate
UpdateNode)selfargstpu_name_refr   nodesource_path_matchsource_pathr8   source_disk_listr6   isource_disks               r   RunDetachDisk.Run_   s   yy##++0044d4Cdi ==$$**,L


D--/
0C77<$$&		2D  &&++
FG G >>++
?A A !K!%,IIk!!&&..22D2Ag

)
+dii
7)
Cdii
O  doo. #$45		#		#NN1 6 ++

O 
 >>		$ r    N)	__name__
__module____qualname____firstlineno____doc__staticmethodr#   rF   __static_attributes__rH   r   r   r   r   L   s    '0 04r   r   )rM   
__future__r   r   r   r4   googlecloudsdk.callioper   r   .googlecloudsdk.command_lib.compute.tpus.tpu_vmr   r	   r-   (googlecloudsdk.command_lib.util.conceptsr
   googlecloudsdk.corer   DETAILED_HELPr   ReleaseTracksr/   ALPHACommandr   detailed_helprH   r   r   <module>rZ      s    '  ' 	 ( . H L D *
		0)" D%%++,F F -FP )
 r   