
    +"                     b    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	Z	 G d d	e
      Zy)
z7API utilities for gcloud compute vpn-gateways commands.    )absolute_import)division)unicode_literals)poller)waiterNc                   |    e Zd ZdZd Zed        Zed        Zed        Z	 	 	 	 ddZ	d Z
d	 Zd
 Zd ZddZd Zy)VpnGatewayHelperz2Helper for VPN gateway service in the Compute API.c                 H    |j                   | _        |j                  | _        y)zInitializes the helper for VPN Gateway operations.

    Args:
      holder: Object representing the Compute API holder instance.
    N)client_compute_client	resources
_resources)selfholders     Elib/googlecloudsdk/api_lib/compute/vpn_gateways/vpn_gateways_utils.py__init__zVpnGatewayHelper.__init__   s     "==D&&DO    c                 .    | j                   j                  S N)r   apitools_clientr   s    r   _clientzVpnGatewayHelper._client&   s    ///r   c                 .    | j                   j                  S r   )r   messagesr   s    r   	_messageszVpnGatewayHelper._messages*   s    (((r   c                 .    | j                   j                  S r   )r   vpnGatewaysr   s    r   _servicezVpnGatewayHelper._service.   s    <<###r   Nc	           	         d}	d}
|%| j                   j                  j                  |      }	|%| j                   j                  j                  |      }
||||	|
d}|pg }t	        |j                               D ]M  \  }}|j                  | j                   j                  t        |      t        j                  |                   O ||d<   |r|||d<    | j                   j                  di |S )a  Returns the VpnGateway message for an insert request.

    Args:
      name: String representing the name of the VPN Gateway resource.
      description: String representing the description for the VPN Gateway
        resource.
      network: String representing the network URL the VPN gateway resource
        belongs to.
      vpn_interfaces_with_interconnect_attachments: Dict representing pairs
        interface id and interconnected attachment associated with vpn gateway
        on this interface.
      stack_type: Enum presenting the stack type of the vpn gateway resource.
      gateway_ip_version: Enum presenting the gateway IP version of the vpn
        gateway resource.
      params: Dict representing the resource manager tags for the VPN gateway
        resource.
      support_tagging_at_creation: Boolean representing whether tagging is
        supported at creation time.

    Returns:
      The VpnGateway message object that can be used in an insert request.
    N)namedescriptionnetwork	stackTypegatewayIpVersion)idinterconnectAttachmentvpnInterfacesparams )r   
VpnGatewayStackTypeValueValuesEnumGatewayIpVersionValueValuesEnumsorteditemsappendVpnGatewayVpnGatewayInterfaceintsix	text_type)r   r    r!   r"   ,vpn_interfaces_with_interconnect_attachments
stack_typegateway_ip_versionr(   support_tagging_at_creationtarget_stack_typetarget_gateway_ip_versionvpn_gateway_argsvpn_interfaceskeyvalues                  r   GetVpnGatewayForInsertz'VpnGatewayHelper.GetVpnGatewayForInsert2   s   B  $..33LL
 %
..
#
#
C
C    "&5 4?n
6
<
<
>*#u 	NN88s8CMM%4H 9 	
 +9' 	$#)x $4>>$$8'788r   c                 p    t        j                  | j                  |      }t        j                  |||      S )a  Waits for the specified operation to complete and returns the target.

    Args:
      vpn_gateway_ref: The VPN Gateway reference object.
      operation_ref: The operation reference object to wait for.
      wait_message: String representing the wait message to display while the
        operation is in progress.

    Returns:
      The resulting resource object after the operation completes.
    )r   Pollerr   r   WaitFor)r   vpn_gateway_refoperation_refwait_messageoperation_pollers        r   WaitForOperationz!VpnGatewayHelper.WaitForOperation|   s-     }}T]]OD>>*M<HHr   c                     | j                   j                  |j                  |j                  |      }| j                  j                  |      }| j                  j                  |j                  d      S )a  Sends an Insert request for a VPN Gateway and returns the operation.

    Args:
      ref: The VPN Gateway reference object.
      vpn_gateway: The VPN Gateway message object to use in the insert request.

    Returns:
      The operation reference object for the insert request.
    projectregion
vpnGatewaycompute.regionOperations
collection)	r   ComputeVpnGatewaysInsertRequestrI   rJ   r   Insertr   ParseselfLink)r   refvpn_gatewayrequest	operations        r   CreatezVpnGatewayHelper.Create   sk     nn<<CJJ; = HG$$W-I??  'A ! C Cr   c                     | j                   j                  |j                  |j                  |j	                               }| j
                  j                  |      S )zSends a Get request for a VPN Gateway and returns the resource.

    Args:
      ref: The VPN Gateway reference object.

    Returns:
      The VPN Gateway resource object.
    rH   )r   ComputeVpnGatewaysGetRequestrI   rJ   Namer   Get)r   rS   rU   s      r   DescribezVpnGatewayHelper.Describe   sH     nn99CJJ388: : GG==W%%r   c                    | j                   j                  |j                  |j                  |j	                               }| j
                  j                  |      }| j                  j                  |j                  d      S )zSends a Delete request for a VPN Gateway and returns the operation.

    Args:
      ref: The VPN Gateway reference object.

    Returns:
      The operation reference object for the delete request.
    rH   rL   rM   )
r   ComputeVpnGatewaysDeleteRequestrI   rJ   rZ   r   Deleter   rQ   rR   )r   rS   rU   rV   s       r   r_   zVpnGatewayHelper.Delete   sq     nn<<CJJ388: = GG$$W-I??  'A ! C Cr   c              #     K   |rj|D ]d  }d}	 | j                   j                  ||||d      }| j                  j                  |      }|j                  }|j
                  D ]  }|  |se` yd}	 | j                   j                  |||d      }| j                  j                  |      }|j                  }|j
                  j                  D ]!  }	|	j                  j                  D ]  }|  # |syw)a
  Yields a VPN Gateway resource from the list of VPN Gateways.

    Sends an AggregatedList request to obtain the list of VPN Gateways and
    yields the next VPN Gateway in this list.

    Sends a List request to obtain the list of VPN Gateways in the specified
    regions and yields the next VPN Gateway in this list.

    Args:
      project: String representing the project to use for the request.
      filter_expr: The expression used to filter the results.
      regions: List of regions to use for the request.
    NT)rI   rJ   filter	pageTokenreturnPartialSuccess)rI   ra   rb   rc   )r   ComputeVpnGatewaysListRequestr   ListnextPageTokenr.   'ComputeVpnGatewaysAggregatedListRequestAggregatedListadditionalPropertiesr=   r   )
r   rI   filter_exprregionsrJ   next_page_tokenrU   responserT   scoped_vpn_gatewayss
             r   re   zVpnGatewayHelper.List   s     &NN@@ '#' A ' ]]''0($22/%^^k ,     O
FF+# G %g --g6h ..o!)!D!D
.44@@K
 A "E  s   C4C6c                 B   | j                   j                  ||      }| j                   j                  |j                  |j                  |j                         |      }| j                  j                  |      }| j                  j                  |j                  d      S )aI  Sends a SetLabels request for a VPN Gateway and returns the operation.

    Args:
      ref: The VPN Gateway reference object.
      existing_label_fingerprint: The existing label fingerprint.
      new_labels: List of new label key, value pairs.

    Returns:
      The operation reference object for the SetLabels request.
    )labelFingerprintlabels)rI   rJ   resourceregionSetLabelsRequestrL   rM   )r   RegionSetLabelsRequest"ComputeVpnGatewaysSetLabelsRequestrI   rJ   rZ   r   	SetLabelsr   rQ   rR   )r   rS   existing_label_fingerprint
new_labelsset_labels_requestrU   rV   s          r   rv   zVpnGatewayHelper.SetLabels   s     >>3J ? Hnn??zz1	 @ 3G
 ''0I??  'A ! C Cr   )NNNFr   )__name__
__module____qualname____doc__r   propertyr   r   r   r>   rF   rW   r\   r_   re   rv   r)   r   r   r	   r	      s~    :' 0 0 ) ) $ $ "'H9TIC &C+ZCr   r	   )r}   
__future__r   r   r   )googlecloudsdk.api_lib.compute.operationsr   googlecloudsdk.api_lib.utilr   r2   objectr	   r)   r   r   <module>r      s,    > &  ' < . 
_Cv _Cr   