
    <                         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Zd Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)z&services vpc-peering helper functions.    )absolute_import)division)unicode_literals)
exceptions)apiszprojects/%s/global/networks/%sc                 n   t               }|j                  }|j                  d|z   |j                  t        | |fz  |            }	 |j
                  j                  |      S # t        j                  t        j                  f$ r.}t        j                  |t        j                         Y d}~yd}~ww xY w)aZ  Make API call to create a connection to a specific service.

  Args:
    project_number: The number of the project for which to peer the service.
    service: The name of the service to peer with.
    network: The network in consumer project to peer with.
    ranges: The names of IP CIDR ranges for peering service to use.

  Raises:
    exceptions.CreateConnectionsPermissionDeniedException: when the create
        connection API fails.
    apitools_exceptions.HttpError: Another miscellaneous error with the peering
        service.

  Returns:
    The result of the create connection operation.
  	services/networkreservedPeeringRanges)parent
connectionN)_GetClientInstanceMESSAGES_MODULE1ServicenetworkingServicesConnectionsCreateRequest
ConnectionNETWORK_URL_FORMATservices_connectionsCreateapitools_exceptionsHttpForbiddenErrorHttpNotFoundErrorr   ReraiseError*CreateConnectionsPermissionDeniedException)project_numberservicer   rangesclientmessagesrequestes           .lib/googlecloudsdk/api_lib/services/peering.pyCreateConnectionr#      s    $ &##( FF7"$$$'@@ & %  G '&&--g66,,++
  	:@@ 	s   A# ##B4$B//B4c                 l   t               }|j                  }|j                  d|z  |j                  t        | |fz              }	 |j
                  j                  |      S # t        j                  t        j                  f$ r.}t        j                  |t        j                         Y d}~yd}~ww xY w)a  Make API call to delete an existing connection to a specific service.

  Args:
    project_number: The number of the project which is peered to the service.
    service: The name of the service peered with.
    network: The network in consumer project peered with.

  Raises:
    exceptions.DeleteConnectionsPermissionDeniedException: when the delete
        connection API fails.
    apitools_exceptions.HttpError: Another miscellaneous error with the peering
        service.

  Returns:
    The result of the delete connection operation.
  services/%s/connections/-consumerNetwork)namedeleteConnectionRequestN)r   r   ;ServicenetworkingServicesConnectionsDeleteConnectionRequestDeleteConnectionRequestr   r   DeleteConnectionr   r   r   r   r   *DeleteConnectionsPermissionDeniedExceptionr   r   r   r   r   r    r!   s          r"   r,   r,   D   s    " &##( JJ*W4"*"B"B0NG3LL #C # K  
&&77@@,,++
  	:@@ 	   A" "#B3$B..B3c                 p   t               }|j                  }|j                  d|z  |j                  t        | |fz  |      |      }	 |j
                  j                  |      S # t        j                  t        j                  f$ r.}t        j                  |t        j                         Y d}~yd}~ww xY w)a  Make API call to update a connection to a specific service.

  Args:
    project_number: The number of the project for which to peer the service.
    service: The name of the service to peer with.
    network: The network in consumer project to peer with.
    ranges: The names of IP CIDR ranges for peering service to use.
    force: If true, update the connection even if the update can be destructive.

  Raises:
    exceptions.UpdateConnectionsPermissionDeniedException: when the update
        connection API fails.
    apitools_exceptions.HttpError: Another miscellaneous error with the peering
        service.

  Returns:
    The result of the update connection operation.
  r%   r
   )r(   r   forceN)r   r   0ServicenetworkingServicesConnectionsPatchRequestr   r   r   Patchr   r   r   r   r   *UpdateConnectionsPermissionDeniedException)	r   r   r   r   r1   r   r   r    r!   s	            r"   UpdateConnectionr5   l   s    & &##( EE&0$$$'@@ & %   F '&&,,W55,,++
  	:@@ 	s   	A$ $#B5$B00B5c                 n   t               }|j                  }|j                  d|z   dj                  | |            }	 |j                  j                  |      j                  S # t        j                  t        j                  f$ r.}t        j                  |t        j                         Y d}~yd}~ww xY w)a  Make API call to list connections of a network for a specific service.

  Args:
    project_number: The number of the project for which to peer the service.
    service: The name of the service to peer with.
    network: The network in consumer project to peer with.

  Raises:
    exceptions.ListConnectionsPermissionDeniedException: when the list
    connections API fails.
    apitools_exceptions.HttpError: Another miscellaneous error with the peering
        service.

  Returns:
    The list of connections.
  r	   z projects/{0}/global/networks/{1})r   r   N)r   r   /ServicenetworkingServicesConnectionsListRequestformatr   Listconnectionsr   r   r   r   r   (ListConnectionsPermissionDeniedExceptionr.   s          r"   ListConnectionsr<      s    " &##( DD7"077
' E '&&++G4@@@,,++
  	:>> 	s   $A# ##B4$B//B4c                 l   t               }|j                  }|j                  |j                  t        | |fz        d|z         }	 |j
                  j                  |      S # t        j                  t        j                  f$ r.}t        j                  |t        j                         Y d}~yd}~ww xY w)a^  Make API call to enable VPC service controls for a specific service.

  Args:
    project_number: The number of the project which is peered with the service.
    service: The name of the service to enable VPC service controls for.
    network: The network in the consumer project peered with the service.

  Raises:
    exceptions.EnableVpcServiceControlsPermissionDeniedException: when the
    enable VPC service controls API fails.
    apitools_exceptions.HttpError: Another miscellaneous error with the peering
        service.

  Returns:
    The result of the enable VPC service controls operation.
  r&   r	   )enableVpcServiceControlsRequestr   N)r   r   8ServicenetworkingServicesEnableVpcServiceControlsRequestEnableVpcServiceControlsRequestr   servicesEnableVpcServiceControlsr   r   r   r   r   1EnableVpcServiceControlsPermissionDeniedExceptionr.   s          r"   rB   rB      s    " &##( MM&.&N&N,/HH 'O ' 7"	 N '??33G<<,,++
  	:GG 	r/   c                 D   t               }|j                  }|j                  d|d| d|      }	 |j                  j	                  |      S # t
        j                  t
        j                  f$ r.}t        j                  |t        j                         Y d}~yd}~ww xY w)aW  Make API call to get VPC service controls for a specific service.

  Args:
    project_number: The number of the project which is peered with the service.
    service: The name of the service to get VPC service controls for.
    network: The network in the consumer project peered with the service.

  Raises:
    exceptions.GetVpcServiceControlsPermissionDeniedException: when the
    get VPC service controls API fails.
    apitools_exceptions.HttpError: Another miscellaneous error with the peering
    service.

  Returns:
    The state of the VPC service controls for the peering connection.
  r	   
/projects//global/networks/r(   N)r   r   KServicenetworkingServicesProjectsGlobalNetworksGetVpcServiceControlsRequest!services_projects_global_networksGetVpcServiceControlsr   r   r   r   r   .GetVpcServiceControlsPermissionDeniedExceptionr.   s          r"   rJ   rJ      s    " &##(``	.'+ a '
33II  ,,++
  	:DD 	s   A #B1$BBc                 l   t               }|j                  }|j                  |j                  t        | |fz        d|z         }	 |j
                  j                  |      S # t        j                  t        j                  f$ r.}t        j                  |t        j                         Y d}~yd}~ww xY w)ac  Make API call to disable VPC service controls for a specific service.

  Args:
    project_number: The number of the project which is peered with the service.
    service: The name of the service to disable VPC service controls for.
    network: The network in the consumer project peered with the service.

  Raises:
    exceptions.DisableVpcServiceControlsPermissionDeniedException: when the
    disable VPC service controls API fails.
    apitools_exceptions.HttpError: Another miscellaneous error with the peering
        service.

  Returns:
    The result of the disable VPC service controls operation.
  r&   r	   ) disableVpcServiceControlsRequestr   N)r   r   9ServicenetworkingServicesDisableVpcServiceControlsRequest DisableVpcServiceControlsRequestr   rA   DisableVpcServiceControlsr   r   r   r   r   2DisableVpcServiceControlsPermissionDeniedExceptionr.   s          r"   rP   rP     s    " &##( NN'/'P'P,/HH (Q ( 7"	 O '??44W==,,++
  	:HH 	r/   c                 h   t               }|j                  }|j                  d|d| d||j                  ||            }	 |j                  j                  |      S # t        j                  t        j                  f$ r.}t        j                  |t        j                         Y d}~yd}~ww xY w)a  Make API call to create a peered DNS domain for a specific connection.

  Args:
    project_number: The number of the project which is peered with the service.
    service: The name of the service to create a peered DNS domain for.
    network: The network in the consumer project peered with the service.
    name: The name of the peered DNS domain.
    dns_suffix: The DNS domain name suffix of the peered DNS domain.

  Raises:
    exceptions.CreatePeeredDnsDomainPermissionDeniedException: when the create
    peered DNS domain API fails.
    apitools_exceptions.HttpError: Another miscellaneous error with the peering
    service.

  Returns:
    The result of the create peered DNS domain operation.
  r	   rE   rF   )	dnsSuffixr(   )r   peeredDnsDomainN)r   r   LServicenetworkingServicesProjectsGlobalNetworksPeeredDnsDomainsCreateRequestPeeredDnsDomain2services_projects_global_networks_peeredDnsDomainsr   r   r   r   r   r   .CreatePeeredDnsDomainPermissionDeniedException)	r   r   r   r(   
dns_suffixr   r   r    r!   s	            r"   CreatePeeredDnsDomainrZ   ,  s    & &##( aa	.'+..$.O b '
DDKK  ,,++
  	AA 	s   A   #B1$B,,B1c           
      J   t               }|j                  }|j                  d|d| d|d|      }	 |j                  j	                  |      S # t
        j                  t
        j                  f$ r.}t        j                  |t        j                         Y d}~yd}~ww xY w)a  Make API call to delete a peered DNS domain for a specific connection.

  Args:
    project_number: The number of the project which is peered with the service.
    service: The name of the service to delete a peered DNS domain for.
    network: The network in the consumer project peered with the service.
    name: The name of the peered DNS domain.

  Raises:
    exceptions.DeletePeeredDnsDomainPermissionDeniedException: when the delete
    peered DNS domain API fails.
    apitools_exceptions.HttpError: Another miscellaneous error with the peering
    service.

  Returns:
    The result of the delete peered DNS domain operation.
  r	   rE   rF   z/peeredDnsDomains/rG   N)r   r   LServicenetworkingServicesProjectsGlobalNetworksPeeredDnsDomainsDeleteRequestrW   Deleter   r   r   r   r   .DeletePeeredDnsDomainPermissionDeniedException)r   r   r   r(   r   r   r    r!   s           r"   DeletePeeredDnsDomainr_   V  s    $ &##( aa	.'41 b 'DDKK  ,,++
  	AA 	s   A #B"4$BB"c                 X   t               }|j                  }|j                  d|d| d|      }	 |j                  j	                  |      j
                  S # t        j                  t        j                  f$ r.}t        j                  |t        j                         Y d}~yd}~ww xY w)a=  Make API call to list the peered DNS domains for a specific connection.

  Args:
    project_number: The number of the project which is peered with the service.
    service: The name of the service to list the peered DNS domains for.
    network: The network in the consumer project peered with the service.

  Raises:
    exceptions.ListPeeredDnsDomainsPermissionDeniedException: when the delete
    peered DNS domain API fails.
    apitools_exceptions.HttpError: Another miscellaneous error with the peering
    service.

  Returns:
    The list of peered DNS domains.
  r	   rE   rF   )r   N)r   r   JServicenetworkingServicesProjectsGlobalNetworksPeeredDnsDomainsListRequestrW   r9   peeredDnsDomainsr   r   r   r   r   -ListPeeredDnsDomainsPermissionDeniedExceptionr.   s          r"   ListPeeredDnsDomainsrd   ~  s    " &##( __	.'+ ` 'DDII ,,++
  	@@ 	s   $A #B);$B$$B)c                 2   t               }|j                  }|j                  |       }	 |j                  j	                  |      S # t
        j                  t
        j                  f$ r.}t        j                  |t        j                         Y d}~yd}~ww xY w)a5  Make API call to get an operation.

  Args:
    name: The name of operation.

  Raises:
    exceptions.OperationErrorException: when the getting operation API fails.
    apitools_exceptions.HttpError: Another miscellaneous error with the peering
        service.

  Returns:
    The long running operation.
  rG   N)r   r   %ServicenetworkingOperationsGetRequest
operationsGetr   r   r   r   r   OperationErrorException)r(   r   r   r    r!   s        r"   GetOperationrj     s     &##(:::E'C  )),,++
 C AzAABB	Cs   A #B($BBc                  2    t        j                  ddd      S )Nservicenetworkingv1F)no_http)r   GetClientInstance     r"   r   r     s    			 3T5	IIrq   N)__doc__
__future__r   r   r   apitools.base.pyr   r   googlecloudsdk.api_lib.servicesgooglecloudsdk.api_lib.utilr   r   r#   r,   r5   r<   rB   rJ   rP   rZ   r_   rd   rj   r   rp   rq   r"   <module>rw      sj    - &  ' > 6 ,5 %P%P'T#L#L!H#L'T%P$NC4Jrq   