
                         "   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Z e
j$                  e
j&                  j(                         G d dej*                  e
j,                               Zy)zdeployments cancel command.    )absolute_import)division)unicode_literals)
exceptions)dm_api_util)dm_base)base)dm_util)dm_write)flagsi  c                   .    e Zd ZdZddiZed        Zd Zy)CancelPreviewzCancel a pending or running deployment preview.

  This command will cancel a currently running or pending preview operation on
  a deployment.
  EXAMPLESa  
To cancel a running operation on a deployment, run:

  $ {command} my-deployment

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

  $ {command} my-deployment --async

To cancel a preview command providing a fingerprint:

  $ {command} my-deployment --fingerprint=deployment-fingerprint

When a deployment preview is cancelled, the deployment itself is not
deleted.
c                     t        j                  |        t        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.
    N)r   AddDeploymentNameFlagAddAsyncFlagAddFingerprintFlag)parsers    <lib/surface/deployment_manager/deployments/cancel_preview.pyArgszCancelPreview.Args@   s.     
'	v	V$    c           	         |j                   r t        j                  |j                         }nLt        j                  | j
                  | j                  t        j                         |j                        xs d}	 | j
                  j                  j                  | j                  j                  t        j                         |j                  | j                  j                  |                  }t        j                  | j
                  | j                  t        j                         |j                        }t        j                  |       |j(                  r|S |j*                  }	 t-        j.                  | j
                  | j                  |dt        j                         t0              }t        j2                  |d       	 | j
                  j4                  j7                  | j                  j9                  t        j                         |j                              }|j4                  r|j4                  S g S # t        j                   $ r)}t#        j$                  |t        j&                        d}~ww xY w# t        j                   $ r)}t#        j$                  |t        j&                        d}~ww xY w# t        j                   $ r)}t#        j$                  |t        j&                        d}~ww xY w)	a  Run 'deployments cancel-preview'.

    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 cancel preview operation
      succeeded.

    Raises:
      HttpException: An http error response was received while executing api
          request.
    r   )fingerprint)project
deploymentdeploymentsCancelPreviewRequestNzcancel-preview)timeoutzCancel preview)r   r   )r   r
   DecodeFingerprintr   FetchDeploymentFingerprintclientmessagesr   
GetProjectdeployment_namedeploymentsr   0DeploymentmanagerDeploymentsCancelPreviewRequestDeploymentsCancelPreviewRequestPrintFingerprintapitools_exceptions	HttpErrorr   HttpExceptionHTTP_ERROR_FORMATasync_namer   WaitForOperationOPERATION_TIMEOUTLogOperationStatus	resourcesList%DeploymentmanagerResourcesListRequest)selfargsr   	operationnew_fingerprinterrorop_nameresponses           r   RunzCancelPreview.RunM   ss   " --d.>.>?k
  ::
++
--






	! ( %(	 K++))77
--
:
:((*--mm;;) < 	 ; 
i $>>
++
--






	 o
 / {{g
M--KKMM %'	 	""9.>?M;;((--MM??**,// @ 
 &.%7%7x!!?R?5 (( K$$UK,I,IJJK !** M&&uk.K.KLLM !** M&&uk.K.KLLMsQ   :CH; )AI: A3J9 9J9 ;I7$I22I7:J6$J11J69K5$K00K5N)__name__
__module____qualname____doc__detailed_helpstaticmethodr   r;    r   r   r   r   %   s3      -& 
% 
%LMr   r   N)r?   
__future__r   r   r   apitools.base.pyr   r(   )googlecloudsdk.api_lib.deployment_managerr   r   googlecloudsdk.callioper	   -googlecloudsdk.command_lib.deployment_managerr
   r   r   r/   UseDmApiDmApiVersionV2Command	DmCommandr   rB   r   r   <module>rM      sy     " &  ' > A = ( . A B ?   '&&))*sMDLL'"3"3 sM +sMr   