
    (                        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  SSKJr  SrSrSrSSSS.rSS0r\	R8                   " S S\	R:                  5      5       r\\l        g)zCommand for deleting instances.    )absolute_import)division)unicode_literals)base_classes)utils)base)
completers)
exceptions)flags)	resources)
console_io)zipz(The following instances will be deleted.zAny attached disks configured to be auto-deleted will be deleted unless they are attached to any other instances or the `--keep-disks` flag is given and specifies them for keeping. Deleting a disk is irreversible and any data on the disk will be lost.ih  z8The first partition is reserved for the root filesystem.zA non-boot disk.zAll disk types.)bootdataallEXAMPLESz
    To delete an instance called 'instance-1' in the zone 'us-central-2-a', run:

      $ {command} instance-1 --zone=us-central2-a

  c                   @    \ rS rSrSr\S 5       rS rS rS r	S r
Srg	)
Delete<   z|Delete Compute Engine virtual machine instances.

*{command}* deletes one or more Compute Engine virtual machine
instances.
c                    UR                  5       nUR                  S[        SSS9  UR                  S[        SSS9  [        R                  R                  USS9  U R                  5       [        R                  R                  :X  d,  U R                  5       [        R                  R                  :X  a  UR                  S	S
S SS9  UR                  R                  [        R                  5        g )Nz--delete-disks	DISK_TYPEa          The types of disks to delete with instance deletion regardless
        of the disks' auto-delete configuration. When this flag is
        provided, the auto-delete bits on the attached disks are
        modified accordingly before the instance deletion requests are
        issued. For more information on disk auto-deletion, see
        [Set the auto-delete state of a zonal persistent disk](https://cloud.google.com/compute/docs/disks/modify-persistent-disk#updateautodelete)
        )choicesmetavarhelpz--keep-disksa          The types of disks to not delete with instance deletion regardless
        of the disks' auto-delete configuration. When this flag is
        provided, the auto-delete bits on the attached disks are
        modified accordingly before the instance deletion requests are
        issued. For more information on disk auto-deletion, see
        [Set the auto-delete state of a zonal persistent disk](https://cloud.google.com/compute/docs/disks/modify-persistent-disk#updateautodelete)
        delete)operation_typez--no-graceful-shutdown
store_truezDeletes the instance immediately without gracefully shutting it down. If a graceful shutdown is in progress, then the instance is forcefully stopped and deleted.)actiondefaultr   )add_mutually_exclusive_groupadd_argumentAUTO_DELETE_OVERRIDE_CHOICESr   INSTANCES_ARGAddArgumentReleaseTrackr   ALPHABETAdisplay_infoAddCacheUpdaterr	   InstancesCompleter)clsparserauto_delete_overrides      'lib/surface/compute/instances/delete.pyArgsDelete.ArgsD   s    !>>@%%,	 &  %%,	 &  
##F8#D 	d//555!2!2!7!77
"4  	 ''
(E(EF    c                    / nU HU  nUR                   R                  " S0 UR                  5       D6nUR                  UR                  R
                  SU45        MW     / nUR                  UUS9nU(       a  [        R                  " USS9  U$ )z?Fetches instance objects corresponding to the given references.Get)requestserrors_to_collectzFailed to fetch some instances:error_message )	messagesComputeInstancesGetRequestAsDictappendapitools_client	instancesMakeRequestsr   RaiseToolException)selfrefsclientinstance_get_requestsrefrequest_protobuferrorsr>   s           r.   GetInstancesDelete.GetInstancesu   s    CC JJL""F$:$:$D$De$4$6 7  F##&  $ "I 
9; r1   c                 P   U(       d  g/ nU HP  u  p4UR                  SR                  UR                  5       US:X  a  UR                  OUR                  5      5        MR     [
        R                  " SU5      n[        R                  " US9(       d  [        R                  " S5      eg)zPrompts if disks with False autoDelete will be deleted.

Args:
  disks_to_warn_for: list of tuple of (references to disk resources, disk
    type). disk_type(str)-> either 'zonalDisk' or 'regionalDisk'.
Nz[{0}] in [{1}]	zonalDiskzThe following disks are not configured to be automatically deleted with instance deletion, but they will be deleted as a result of this operation if they are not attached to any other instances:)messagezDeletion aborted by user.)r<   formatNamezoneregionr   ConstructListr   PromptContinuecompute_exceptionsAbortedError)rA   disks_to_warn_forprompt_listrE   	disk_typeprompt_messages         r.   +PromptIfDisksWithoutAutoDeleteWillBeDeleted2Delete.PromptIfDisksWithoutAutoDeleteWillBeDeleted   s     K+

!
!hhji;&>#((CJJ , ((	J 		N $$^<++,GHH =r1   c                    UR                   S:X  a  UR                  =(       a    UR                  $ UR                   S:X  a$  UR                  =(       a    UR                  (       + $ UR                   S:X  a  UR                  $ UR                  S:X  a)  UR                  (       + =(       a    UR                  (       + $ UR                  S:X  a  UR                  (       + $ UR                  S:X  a$  UR                  (       + =(       a    UR                  $ g)zDReturns True if the autoDelete property of the disk must be changed.r   r   r   F)
keep_disks
autoDeleter   delete_disks)rA   argsdisk_resources      r.   AutoDeleteMustBeChangedDelete.AutoDeleteMustBeChanged   s    & %%<-*<*<<	F	"%%@m.@.@*@@	E	!%%%			f	$)))D-2D2D.DD			e	#))))			f	$)))@m.@.@@r1   c                     [         R                  " U R                  5       5      nUR                  n[        R
                  R                  XR                  [        R                  " U5      S9n[        nUR                  S:w  a  US[        -   -  n[        R                  " USUS9  UR                  (       d  UR                  (       Gai  U R                  XC5      n/ n/ n[!        XF5       H  u  pU
R"                   H  nU R%                  X5      (       d  M  UR&                  (       + nU(       aC   UR)                  UR                  R+                  UR,                  SSU	R.                  0S9S45        UR)                  UR4                  R6                  SUR8                  R;                  UUR<                  U	R?                  5       U	R@                  U	R.                  S945        M     M     U(       aD  U RC                  U5        / nURE                  UU[F        S9  U(       a  [        RH                  " USS9  / nU H  n	U R                  5       [J        R                  RL                  :X  d,  U R                  5       [J        R                  RN                  :X  a9  UR8                  RP                  " S0 U	RS                  5       DSURT                  0D6nO*UR8                  RP                  " S0 U	RS                  5       D6nUR)                  UR4                  R6                  SU45        M     URE                  U[F        S9$ ! [0        R2                   aF    UR)                  UR                  R+                  UR,                  S	SU	R.                  0S9S
45         GNf = f)N)scope_listerr    rO   )
scope_nameprompt_titlezcompute.disks)
collectionparamsrK   zcompute.regionDisksregionalDiskSetDiskAutoDelete)r]   
deviceNameinstanceprojectrO   )r4   r5   timeoutz9Some requests to change disk auto-delete behavior failed:r6   noGracefulShutdownr   )ro   r8   )+r   ComputeApiHolderr%   rC   r   r#   ResolveAsResourcer   GetInstanceZoneScopeLister_INSTANCE_DELETE_PROMPTr\   %_INSTANCE_DELETE_PROMPT_DISK_ADDENDUMr   PromptForDeletionr^   rH   r   disksra   r]   r<   ParsesourcerO   cloud_resources WrongResourceCollectionExceptionr=   r>   r9   (ComputeInstancesSetDiskAutoDeleteRequestrl   rN   rn   rY   r?   _TIMEOUT_IN_SECr@   r   r&   r'   ComputeInstancesDeleteRequestr;   no_graceful_shutdown)rA   r_   holderrC   rB   msginstance_resourcesrU   set_auto_delete_requestsrE   resourcedisknew_auto_deleterG   delete_requestsrF   s                   r.   Run
Delete.Run   s=   **4+<+<+>?F]]F0055f= 1 ?D "C%	S888c	DV#FDOOO,,T:!#t8-#NND --d99 !%//&&""((kk!0$chh/ ) 
 ( $ #
)
)$$..!ooFF,!__88:++xx G !+" #A # 9V 
"889JK-$# 	 	

 

"
"02
 O



!2!2!8!8
8 D$5$5$:$::!??HH 
jjl
/3/H/H
 "??HH 
jjl
 f44>>.0 1  HHe #CC &&""((kk!6$chh/ ) 
 !( s   -AL33ANNr8   N)__name__
__module____qualname____firstlineno____doc__classmethodr/   rH   rY   ra   r   __static_attributes__r8   r1   r.   r   r   <   s5     .G .G`&I6$[Ir1   r   N) r   
__future__r   r   r   googlecloudsdk.api_lib.computer   r   googlecloudsdk.callioper   "googlecloudsdk.command_lib.computer	   r
   rS   ,googlecloudsdk.command_lib.compute.instancesr   googlecloudsdk.corer   rz   googlecloudsdk.core.consoler   	six.movesr   rt   ru   r}   r"   DETAILED_HELPUniverseCompatibleDeleteCommandr   detailed_helpr8   r1   r.   <module>r      s    & &  ' 7 0 ( 9 O > < 2  E )J %  G     SIT SI SIj % r1   