
                         \   S 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  \R*                  " \R,                  R.                  \R,                  R0                  \R,                  R2                  5       " S S\R4                  5      5       rg)z.Command for detaching a disk from an instance.    )absolute_import)division)unicode_literals)encoding)base_classes)instance_utils)base)
exceptions)scope)flags)logc                   T    \ rS rSrSrSS0r\S 5       rS rS r	S r
S	 rS
 rS rSrg)
DetachDisk    am  Detach disks from Compute Engine virtual machine instances.

*{command}* is used to detach disks from virtual machines.

Detaching a disk without first unmounting it may result in
incomplete I/O operations and data corruption.
To unmount a persistent disk on a Linux-based image,
ssh into the instance and run:

    $ sudo umount /dev/disk/by-id/google-DEVICE_NAME
EXAMPLESaA  
          To detach a disk named 'my-disk' from an instance named 'my-instance',
          run:

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

          To detach a device named 'my-device' from an instance named
          'my-instance', run:

            $ {command} my-instance --device-name=my-device
          c                     [         R                  R                  U 5        U R                  SS9nUR	                  SSS9  UR	                  SSS9  [         R
                  " U 5        g )NT)requiredz--diskz        Specifies a disk to detach by its resource name. If you specify a
        disk to remove by persistent disk name, then you must not specify its
        device name using the ``--device-name'' flag.
        )helpz--device-namea          Specifies a disk to detach by its device name, which is the name
        that the guest operating system sees. The device name is set
        at the time that the disk is attached to the instance, and needs not be
        the same as the persistent disk name. If the disk's device name is
        specified, then its persistent disk name must not be specified
        using the ``--disk'' flag.
        )r   INSTANCE_ARGAddArgumentadd_mutually_exclusive_groupadd_argumentAddDiskScopeFlag)parser
disk_groups     ,lib/surface/compute/instances/detach_disk.pyArgsDetachDisk.Args=   sq    	""6*44d4CJ     	 
6"    c                 f    [         R                  R                  X2[         R                  " U5      S9$ )N)scope_lister)r   r   ResolveAsResourceGetInstanceZoneScopeLister)selfclient	resourcesargss       r   CreateReferenceDetachDisk.CreateReferenceV   s2    //e&F&Fv&N 0 P Pr   c                     UR                   R                  SUR                  R                  " S0 UR	                  5       D64$ )NGet )apitools_client	instancesmessagesComputeInstancesGetRequestAsDict)r$   r%   instance_refs      r   GetGetRequestDetachDisk.GetGetRequestZ   s>    "",,OO66O9L9L9NOQ Qr   c                    [        [        S UR                   5       5      [        S UR                   5       5      -
  5      S   nUR                  R                  SUR
                  R                  " SSU0UR                  5       D64$ )Nc              3   8   #    U  H  oR                   v   M     g 7fN
deviceName.0disks     r   	<genexpr>+DetachDisk.GetSetRequest.<locals>.<genexpr>a   s     7OO   c              3   8   #    U  H  oR                   v   M     g 7fr7   r8   r:   s     r   r=   r>   b   s     :(9OO(9r?   r   r   r9   r,   )listsetdisksr-   r.   r/   !ComputeInstancesDetachDiskRequestr1   )r$   r%   r2   replacementexistingremoved_disks         r   GetSetRequestDetachDisk.GetSetRequest_   s    777:(9(9::	;<<=?L "",,OO== )')%%')* *r   c                    [         R                  " U5      nUR                  (       a  U R                  XU5      nUR                   Vs/ s HS  nUR
                  (       a=  UR                  UR
                  5      R                  5       UR                  5       :w  d  MQ  UPMU     snUl        [        UR                  5      [        UR                  5      :X  aI  [        R                  " SR                  UR                  5       UR                  UR                  5      5      e U$ UR                   Vs/ s H!  nUR                  UR                   :w  d  M  UPM#     snUl        [        UR                  5      [        UR                  5      :X  aE  [        R                  " SR                  UR                   UR                  UR                  5      5      eU$ s  snf s  snf )Nz;Disk [{0}] is not attached to instance [{1}] in zone [{2}].zKNo disk with device name [{0}] is attached to instance [{1}] in zone [{2}].)r   CopyProtoMessager<   ParseDiskRefrC   sourceParseURLRelativeNamelencompute_exceptionsArgumentErrorformatNameinstancezoner9   device_name)r$   r&   r'   r2   rF   rE   disk_refr<   s           r   ModifyDetachDisk.Modifyj   s   ++H5Kyy""9LAh $>>)4	 2 24;; ? L L N""$!% >k 
X^^	K$5$5 6	6 ..IVHMMO\%:%:L<M<MNP 	P 
7  -5NN CND"oo1A1AA  N Ck 
X^^	K$5$5 6	6 ..VD$$l&;&;\=N=NOQ 	Q
 +Cs   AGG0GGc           	         [         R                  " U R                  5       5      nUR                  nU R	                  X2R
                  U5      nU R                  X45      nUR                  U/5      nU R                  UR
                  XUS   5      nUS   U:X  a=  [        R                  R                  SR                  US   R                  5      5        U$ UR                  U R                  X4XvS   5      /5      $ )Nr   z/No change requested; skipping update for [{0}].)r   ComputeApiHolderReleaseTrackr%   r(   r&   r3   MakeRequestsrY   r   statusPrintrS   namerH   )r$   r'   holderr%   r2   get_requestobjects
new_objects           r   RunDetachDisk.Run   s    **4+<+<+>?F]]F''0@0@$GL$$V:K!!;-0GV--t71:NJ
 qzZ	jj
;
B
Bajoo  n			F*aj	IJL Lr   c                     UR                   S:X  a  [        R                  R                  nO[        R                  R                  n[
        R                  " XR                  UR                  UR                  U5      $ )Nregional)

disk_scopecompute_scopes	ScopeEnumREGIONZONEr   ParseDiskResourcer<   projectrV   )r$   r&   r'   r2   r   s        r   rL   DetachDisk.ParseDiskRef   s^    *$&&--e&&++e++Iyy,8,@,@,8,=,=,13 3r   r,   N)__name__
__module____qualname____firstlineno____doc__detailed_helpstaticmethodr   r(   r3   rH   rY   rf   rL   __static_attributes__r,   r   r   r   r       sM    
  
- # #0PQ
	*:L.3r   r   N)rv   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.computer   r   googlecloudsdk.callioper	   "googlecloudsdk.command_lib.computer
   rQ   r   rk   ,googlecloudsdk.command_lib.compute.instancesr   googlecloudsdk.corer   ReleaseTracksr]   GABETAALPHAUpdateCommandr   r,   r   r   <module>r      s    5 &  ' % 7 9 ( O F > # D%%(($*;*;*@*@%%++-D3## D3-D3r   