
    e                     2   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  ej,                  ej.                  j0                  ej.                  j2                         G d dej4                               Zy)z1Command to update labels for target VPN gateways.    )absolute_import)division)unicode_literals)base_classes)poller)waiter)base)
exceptions)flags)labels_utilc                   0    e Zd ZdZdZed        Zd Zd Zy)Updatea`  Update a Compute Engine Cloud VPN Classic Target VPN Gateway.

  *{command}* updates labels for a Compute Engine Cloud VPN Classic
  Target VPN gateway.  For example:

    $ {command} example-gateway --region us-central1 \
      --update-labels=k0=value1,k1=value2 --remove-labels=k3

  will add/update labels ``k0'' and ``k1'' and remove labels with key ``k3''.

  Labels can be used to identify the target VPN gateway and to filter them as in

    $ {parent_command} list --filter='labels.k1:value2'

  To list existing labels

    $ {parent_command} describe example-gateway --format="default(labels)"

  Nc                     t        j                         | _        | j                  j                  |       t	        j
                  |       y)zmAdds arguments to the supplied parser.

    Args:
      parser: The argparse parser to add arguments to.
    N)target_vpn_gateway_flagsTargetVpnGatewayArgumentTARGET_VPN_GATEWAY_ARGAddArgumentr   AddUpdateLabelsFlags)clsparsers     1lib/surface/compute/target_vpn_gateways/update.pyArgszUpdate.Args7   s:     	!99; **62$$V,    c           	          |j                  |j                  |j                         |j                  |j	                  |j
                  |            S )a  Creates the API request to update labels on a Target VPN Gateway.

    Args:
      messages: Module with request messages.
      target_vpn_gateway_ref: Resource reference for the target VPN gateway.
      target_vpn_gateway: The target_vpn_gateway being updated.
      replacement: A new labels request proto representing the update and remove
                   edits.
    Returns:
      Request to be sent to update the target VPN gateway's labels.
    )labelFingerprintlabels)projectresourceregionregionSetLabelsRequest)(ComputeTargetVpnGatewaysSetLabelsRequestr   Namer   RegionSetLabelsRequestr   )selfmessagestarget_vpn_gateway_reftarget_vpn_gatewayreplacements        r   _CreateRegionalSetLabelsRequestz&Update._CreateRegionalSetLabelsRequestC   sY     <<&..',,.%,,'>>/@@  ?   	 = ! !r   c                    t        j                  | j                               }|j                  j                  }|j                  j
                  }| j                  j                  ||j                  t        j                  |j                              }t        j                  j                  |      }|j                         st        j                   dd      |j"                  j%                   |j&                  di |j)                               }|j*                  j,                  }|j/                  ||j0                        }	|	j2                  s|S | j5                  ||||	j0                        }
|j"                  j7                  |
      }|j                  j9                  |j:                  d      }t=        j>                  |j"                        }tA        jB                  ||djE                  |jG                                     S )zIssues API requests to update a Target VPN Gateway.

    Args:
      args: argparse.Namespace, The arguments received by this command.
    Returns:
      [protorpc.messages.Message], A list of responses returned
      by the compute API.
    )scope_listerLABELSzEAt least one of --update-labels or --remove-labels must be specified.zcompute.regionOperations)
collectionz+Updating labels of target VPN gateway [{0}] )$r   ComputeApiHolderReleaseTrackclientapitools_clientr%   r   ResolveAsResource	resourcescompute_flagsGetDefaultScopeListerr   DiffFromUpdateArgsMayHaveUpdatescalliope_exceptionsRequiredArgumentExceptiontargetVpnGatewaysGet"ComputeTargetVpnGatewaysGetRequestAsDictr#   LabelsValueApplyr   needs_updater)   	SetLabelsParseselfLinkr   Pollerr   WaitForformatr"   )r$   argsholderr1   r%   r&   labels_diffr'   labels_valuelabels_updaterequest	operationoperation_refoperation_pollers                 r   Runz
Update.RunX   s    **4+<+<+>?F]]**F}}%%H!88JJ"88G K I
 ""11$7K%%'99
 /0 0  1155333 	/$++-	/0 22>>L%%l4F4M4MNM%%22(*<G ((227;I$$**'A + CM }}V%=%=>>>*MGNN499;=> >r   )	__name__
__module____qualname____doc__r   classmethodr   r)   rR   r.   r   r   r   r      s+    (  	- 	-!*.>r   r   N)rV   
__future__r   r   r   googlecloudsdk.api_lib.computer   )googlecloudsdk.api_lib.compute.operationsr   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper	   r
   r:   "googlecloudsdk.command_lib.computer   r5   6googlecloudsdk.command_lib.compute.target_vpn_gatewaysr   $googlecloudsdk.command_lib.util.argsr   ReleaseTracksr0   ALPHABETAUpdateCommandr   r.   r   r   <module>rd      sw    8 &  ' 7 < . ( E E d < D%%++T->->-C-CDf>T f> Ef>r   