
                         ^   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddlm
Z
 ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dZ e
j4                  e
j6                  j8                         G d dej:                  e
j<                               Zy)zdeployments delete command.    )absolute_import)division)unicode_literals)
exceptions)dm_api_util)dm_base)apis)base)dm_util)dm_write)flags)
properties)
console_ioi  c                       e Zd ZdZddiZ ej                   ej                  dd      j                  j                        Zed        Zd Zy)	DeletezbDelete a deployment.

  This command deletes a deployment and deletes all associated resources.
  EXAMPLESao  
To delete a deployment, run:

  $ {command} my-deployment

To issue a delete command without waiting for the operation to complete, run:

  $ {command} my-deployment --async

To delete several deployments, run:

  $ {command} my-deployment-one my-deployment-two my-deployment-three

To disable the confirmation prompt on delete, run:

  $ {command} my-deployment -q
deploymentmanagerv2c                     | j                  ddd       t        j                  j                  j	                  |        t        j                  |        y)zArgs is called by calliope to gather arguments for this command.

    Args:
      parser: An argparse parser that you can use to add arguments that go
          on the command line after this command. Positional arguments are
          allowed.
    deployment_name+zDeployment name.)nargshelpN)add_argumentr   _delete_policy_flag_map
choice_argAddToParserr   AddAsyncFlag)parsers    4lib/surface/deployment_manager/deployments/delete.pyArgszDelete.ArgsI   sC     );MN
""--99&A	v    c           
         ddj                  |j                        z   }|j                  s,t        j                  |d      st        j                  d      g }g }|j                  D ]  }| j                  j                  |dt        j                  j                  j                  j                  id      }	 | j                  j                  j!                  | j"                  j%                  t'        j(                         |j*                  t         j,                  j/                  |j0                        	            }|j2                  r|j5                  |       n|j6                  }	 t9        j:                  | j                  | j"                  |d
t'        j(                         t<              }t?        j@                  |d       | j                  jD                  jG                  | j"                  jI                  t'        j(                         |            }
|j5                  |
        |rtW        jX                  |      |S # t
        j                  $ r>}	|j5                  t        j                  djC                  ||	                   Y d}	~	d}	~	ww xY w# tJ        jL                  $ r>}|j5                  tO        jP                  |tR        jT                               Y d}~zd}~ww xY w)a}  Run 'deployments delete'.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
          with.

    Returns:
      If --async=true, returns Operation to poll.
      Else, returns boolean indicating whether insert operation succeeded.

    Raises:
      HttpException: An http error response was received while executing api
          request.
    z-The following deployments will be deleted:
- z
- F)messagedefaultzDeletion aborted by user.projectzdeploymentmanager.deployments)params
collection)r&   
deploymentdeletePolicydelete)timeoutr   z Delete operation {0} failed.
{1}N)r&   	operation)-joinr   quietr   PromptContinuer   OperationError	resourcesParser   VALUEScorer&   	GetOrFailclientdeploymentsr   messages)DeploymentmanagerDeploymentsDeleteRequestr   
GetProjectr)   r   GetEnumForChoicedelete_policyasync_appendnamer   WaitForOperationOPERATION_TIMEOUTr   LogOperationStatusformat
operationsGet%DeploymentmanagerOperationsGetRequestapitools_exceptions	HttpErrorapi_exceptionsHttpExceptionr   HTTP_ERROR_FORMATcore_exceptions
MultiError)selfargsprompt_messagerE   errorsr   deployment_refr-   op_nameecompleted_operationerrors               r    Runz
Delete.RunV   ss    GD$8$89:N::&&~uM''(CDDJF//~~++
Z..33;;EEF4 , 6n#3KK++22MMCC**,)44$<<..t/A/AB	 D 
	 ;;


I
&NN'I 11""$)+I &&y(; !% 6 6 : :mmAA!,,.# B !
 

/
0K 0T &&v..! ** IMM*333::7AFH I II !** 3n22;002 	3 	33sE   8B.J'AIA#JJ4JJJJK&(3K!!K&N)__name__
__module____qualname____doc__detailed_helpr   GetDeleteFlagEnumMapr	   GetMessagesModuler:   DeletePolicyValueValuesEnumr   staticmethodr!   rX    r"   r    r   r   *   sg      -( 7E66t148112M2MP 
 
Cr"   r   N) r\   
__future__r   r   r   apitools.base.pyr   rH   )googlecloudsdk.api_lib.deployment_managerr   r   googlecloudsdk.api_lib.utilr	   rJ   googlecloudsdk.callioper
   -googlecloudsdk.command_lib.deployment_managerr   r   r   googlecloudsdk.corerM   r   googlecloudsdk.core.consoler   rB   UseDmApiDmApiVersionV2DeleteCommand	DmCommandr   rb   r"   r    <module>rp      s     " &  ' > A = @ , D ( A B ? = * 2   '&&))*nT!2!2 n +nr"   