
                            d Z ddlmZ ddlmZ ddlmZ ddl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dZej$                   ej&                  ej(                  j*                  ej(                  j,                  ej(                  j.                         G d dej0                                      Zee_        y)zUpdate deployment command.    )absolute_import)division)unicode_literalsN)
exceptions)api)base)deployment_flags)labels_utilz
          Update an intercept deployment. Check the progress of deployment update
          by using `gcloud network-security intercept-deployments list`.

          For examples refer to the EXAMPLES section below.
        a  
            To update labels k1 and k2, run:

            $ {command} my-deployment --project=my-project --location=us-central1-a --update-labels=k1=v1,k2=v2

            To remove labels k3 and k4, run:

            $ {command} my-deployment --project=my-project --location=us-central1-a --remove-labels=k3,k4

            To clear all labels from the intercept deployment, run:

            $ {command} my-deploymen --project=my-project --location=us-central1-a --clear-labels

            To update description to 'new description', run:

            $ {command} my-deploymen --project=my-project --location=us-central1-a --description="new description"
        )DESCRIPTIONEXAMPLESc                   :    e Zd ZdZg dZed        Zd Zd Zd Z	y)UpdatezUpdate an Intercept Deployment.)z--clear-labelsz--remove-labelsz--update-labelsc                 J   t        j                  | j                         |       t        j                  |d       t        j                  |       t
        j                  j                  |       t
        j                  j                  |d       t        j                  |       y )N20mT)r	   AddDeploymentResourceReleaseTrack
AddMaxWaitAddDescriptionArgr   
ASYNC_FLAGAddToParser
SetDefaultr
   AddUpdateLabelsFlags)clsparsers     <lib/surface/network_security/intercept_deployments/update.pyArgszUpdate.ArgsH   ss    **3+;+;+=vF &&v.OO'OOvt,$$V,    c                    t        j                  | j                               }|j                  j                  j                         }	 |j                  |j                               }i }| j                  |||      }|r||d<   |st        j                  | j                        |j                  |j                         t!        |dd       |      }|j"                  r|j%                  d      sd|_        |S | j)                  |||t+        j,                  |j.                              S # t        j                  $ r t        j                  dd      w xY w)	Nzintercept-deploymentz$Intercept deployment does not exist.labelsdescription)namer    update_fieldsformatdefault)seconds)r   Clientr   CONCEPTSintercept_deploymentParseDescribeDeploymentRelativeNameapitools_exceptionsHttpNotFoundErrorr   InvalidArgumentException_process_label_updatesMinimumArgumentException_valid_argumentsUpdateDeploymentgetattrasync_IsSpecifiedr#   _wait_for_operationdatetime	timedeltamax_wait)selfargsclient
deploymentoriginalr"   r   	operations           r   Runz
Update.RunT   sE   ZZ))+,F3399;J**:+B+B+DEh M((x@F &mH//0E0EFF''$$&D-6# ( I {{ h'##4==1	 9 00 //
 
0 s   	D* **Ec                    t         j                  j                  |      }|j                         sy|j                  }|j                  |j                  j                  j                  |      }|j                  r|j                  }|S )aD  Processes the label update request.

    Args:
      client: the client to use to make the API call.
      args: the args from the command line.
      original_deployment: the original intercept deployment.

    Returns:
      the labels we would like to update if there is any update. Otherwise,
      it returns None.
    N)
r
   DiffFromUpdateArgsMayHaveUpdatesr   ApplymessagesInterceptDeploymentLabelsValueneeds_update)r:   r<   r;   original_deploymentlabels_diffr   labels_updates          r   r/   zUpdate._process_label_updates}   su     ""11$7K%%' ''F%%++77M !!##fMr   c                     |j                  |j                  |      dj                  |j                               d|      S )Nz3waiting for intercept deployment [{}] to be updatedF)operation_refmessage
has_resultr9   )WaitForOperationGetOperationRefr#   r+   )r:   r<   r?   r=   r9   s        r   r6   zUpdate._wait_for_operation   sJ    "",,Y7AHH'')  # 	 	r   N)
__name__
__module____qualname____doc__r1   classmethodr   r@   r/   r6    r   r   r   r   ;   s3    
 ( 	- 	-'R4
r   r   )rV   
__future__r   r   r   r7   apitools.base.pyr   r,   =googlecloudsdk.api_lib.network_security.intercept_deploymentsr   googlecloudsdk.callioper   5googlecloudsdk.command_lib.network_security.interceptr	   $googlecloudsdk.command_lib.util.argsr
   DETAILED_HELPDefaultUniverseOnlyReleaseTracksr   ALPHABETAGAUpdateCommandr   detailed_helprX   r   r   <module>rg      s    ! &  '  > M ( . R <6 T..33T5F5F5I5IbT b bJ % r   