
                         v   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dZe	j                    e	j"                  e	j$                  j&                  e	j$                  j(                  e	j$                  j*                         G d de	j,                                      Zee_        y)zUpdate endpoint group command.    )absolute_import)division)unicode_literalsN)api)base)
exceptions)endpoint_group_flags)labels_utilz
          Update a mirroring endpoint groups. Check the progress of endpoint
          group update by using `gcloud network-security mirroring-endpoint-groups list`.

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

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

            To remove labels k3 and k4, run:

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

            To clear all labels from the mirroring endpoint group, run:

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

            To update description to 'new description', run:

            $ {command} my-endpoint-group --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	d Z
y)	Updatez"Update a Mirroring Endpoint Group.)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	   AddEndpointGroupResourceReleaseTrack
AddMaxWaitAddDescriptionArgr   
ASYNC_FLAGAddToParser
SetDefaultr
   AddUpdateLabelsFlags)clsparsers     @lib/surface/network_security/mirroring_endpoint_groups/update.pyArgszUpdate.ArgsE   ss    11#2B2B2DfM## **62OO'OOvt,$$V,    c                 t   t        j                  | 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 )Nlabelsdescription)namer    update_fieldsformatdefault)seconds)r   Clientr   CONCEPTSmirroring_endpoint_groupParseDescribeEndpointGroupRelativeName!_validate_original_endpoint_group_process_label_updatesr   MinimumArgumentException_valid_argumentsUpdateEndpointGroupgetattrasync_IsSpecifiedr#   _wait_for_operationdatetime	timedeltamax_wait)selfargsclientegoriginalr"   r   	operations           r   Runz
Update.RunQ   s   ZZ))+,F		/	/	5	5	7B++BOO,=>H**84M((x@F &mH//0E0EFF**__D-6# + I {{ h'##
4==1	 r   c                 4    |t        j                  dd      y )Nzmirroring-endpoint-groupz(Mirroring endpoint group does not exist.)r   InvalidArgumentException)r8   original_egs     r   r,   z(Update._validate_original_endpoint_groupu   s&    //
$
4  r   c                    t         j                  j                  |      }|j                         sy|j                  }|j                  |j                  j                  j                  |      }|j                  r|j                  }|S )a@  Processes the label update request.

    Args:
      client: the client to use to make the API call.
      args: the args from the command line.
      original_eg: the original mirroring endpoint group.

    Returns:
      the labels we would like to update if there is any update. Otherwise,
      it returns None.
    N)
r
   DiffFromUpdateArgsMayHaveUpdatesr   ApplymessagesMirroringEndpointGroupLabelsValueneeds_update)r8   r:   r9   rA   labels_diffr   labels_updates          r   r-   zUpdate._process_label_updates|   su     ""11$7K%%'F%%..::M !!##fMr   c                     |j                  |j                  |      dj                  |j                               d|      S )Nz7waiting for mirroring endpoint group [{}] to be updatedF)operation_refmessage
has_resultr7   )WaitForOperationGetOperationRefr#   r+   )r8   r:   r=   r;   r7   s        r   r4   zUpdate._wait_for_operation   sH    "",,Y7ELL!  # 	 	r   N)__name__
__module____qualname____doc__r/   classmethodr   r>   r,   r-   r4    r   r   r   r   9   s8     + 	- 	-"H4
r   r   )rV   
__future__r   r   r   r5   Agooglecloudsdk.api_lib.network_security.mirroring_endpoint_groupsr   googlecloudsdk.callioper   r   +googlecloudsdk.command_lib.network_securityr	   $googlecloudsdk.command_lib.util.argsr
   DETAILED_HELPDefaultUniverseOnlyReleaseTracksr   ALPHABETAGAUpdateCommandr   detailed_helprX   r   r   <module>rf      s    % &  '  Q ( . L <6 D%%++T->->-C-C%%((*dT d* dN % r   