
    A                         S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ	r	  SSKJ
r
  S	r " S
 S\	R                  5      r " S S\5      rS rg)zBUtilities for the API to configure cross-project networking (XPN).    )absolute_import)division)unicode_literals)
list_pager)base_classes)
exceptions)utilsv1c                       \ rS rSrSrg)XpnApiError    N)__name__
__module____qualname____firstlineno____static_attributes__r       -lib/googlecloudsdk/api_lib/compute/xpn_api.pyr   r      s    r   r   c                   d    \ rS rSrSrS rS rSS jrS rS r	S	 r
S
 rS rS rS rS rS rSrg)	XpnClient"   zA client for interacting with the cross-project networking (XPN) API.

The XPN API is a subset of the Google Compute Engine API.
c                 T    Xl         UR                  U l        UR                  U l        g N)compute_clientapitools_clientclientmessages)selfr   s     r   __init__XpnClient.__init__(   s"    ( 00DK"++DMr   c                 8    U R                   R                  U/US9$ )N)requestserrors_to_collect)r   MakeRequests)r   requesterrorss      r   _MakeRequestXpnClient._MakeRequest-   s(    ++  , " "r   Nc                     / n[        U R                  X5      5      nU(       a8  U=(       d    SnSR                  U5      n[        R                  " U[
        U5        US   $ )Nzcomplete all requestszCould not {0}:r   )listr(   formatr	   RaiseExceptionr   )r   request_tupleoperation_msgr'   resultsmsgs         r   _MakeRequestSyncXpnClient._MakeRequestSync2   sV    F4$$];<G#>'>m##M2c6;41:r   c                     U R                   R                  SU R                  R                  US94nSR	                  US9nU R                  X#5        g)z4Enable the project with the given ID as an XPN host.EnableXpnHostprojectzenable [{project}] as XPN hostN)r   projectsr   #ComputeProjectsEnableXpnHostRequestr,   r2   r   r7   r.   r1   s       r   
EnableHostXpnClient.EnableHost=   sT     	99'9JLM +
1
1'
1
BC--r   c                     U R                   R                  SU R                  R                  US94nSR	                  US9nU R                  X#5        g)z5Disable the project with the given ID as an XPN host.DisableXpnHostr6   zdisable [{project}] as XPN hostN)r   r8   r   $ComputeProjectsDisableXpnHostRequestr,   r2   r:   s       r   DisableHostXpnClient.DisableHostF   sT     	::7:KMM ,
2
27
2
CC--r   c                     U R                   R                  SU R                  R                  US94nSR	                  US9nU R                  X#5      $ )z'Get the XPN host for the given project.
GetXpnHostr6   z$get XPN host for project [{project}])r   r8   r    ComputeProjectsGetXpnHostRequestr,   r2   r:   s       r   GetHostProjectXpnClient.GetHostProjectO   sW     	66w6GIM 1
7
7
7
HC  44r   c           	          U R                   R                  US9n[        R                  " U R                  R
                  USSSSS9$ )Nr6   GetXpnResources
maxResults  	resourcesmethodbatch_size_attribute
batch_sizefield)r   %ComputeProjectsGetXpnResourcesRequestr   YieldFromListr   r8   )r   r7   r&   s      r   ListEnabledResourcesXpnClient.ListEnabledResourcesX   sN    mmAA B G## ) r   c           	          U R                   R                  UU R                   R                  US9S9n[        R                  " U R
                  R                  USSSSS9$ )a]  List the projects in an organization that are enabled as XPN hosts.

Args:
  project: str, project ID to make the request with.
  organization_id: str, the ID of the organization to list XPN hosts
      for. If None, the organization is inferred from the project.

Returns:
  Generator for `Project`s corresponding to XPN hosts in the organization.
)organization)r7   projectsListXpnHostsRequestListXpnHostsrI   rJ   itemsrL   )r   "ComputeProjectsListXpnHostsRequestProjectsListXpnHostsRequestr   rR   r   r8   )r   r7   organization_idr&   s       r   ListOrganizationHostProjects&XpnClient.ListOrganizationHostProjectsc   sl     mm>>$(MM$M$M( %N %* ? +G ##) r   c                    U R                   R                  U R                   R                  UUS9S9nU R                   R                  UUS9nU R                  R
                  SU4nSR                  X!5      nU R                  Xg5        g)a  Associate the given resource with the given XPN host project.

Args:
  host_project: str, ID of the XPN host project
  associated_resource: ID of the resource to associate with host_project
  xpn_resource_type: XpnResourceId.TypeValueValuesEnum, the type of the
     resource
idtypexpnResource)r7    projectsEnableXpnResourceRequestEnableXpnResourcezAenable resource [{0}] as an associated resource for project [{1}]N)r    ProjectsEnableXpnResourceRequestXpnResourceId'ComputeProjectsEnableXpnResourceRequestr   r8   r,   r2   )r   host_projectassociated_resourcexpn_resource_typeprojects_enable_requestr&   r.   r1   s           r   _EnableXpnAssociatedResource&XpnClient._EnableXpnAssociatedResourcez   s     #mmLLMM//"" 0 $ M 
 mmCC)@ D BG [[))+>HM &': I --r   c                 x    U R                   R                  R                  nU R                  XUR                  S9  g)zAssociate the given project with the given XPN host project.

Args:
  host_project: str, ID of the XPN host project
  associated_project: ID of the project to associate
rl   N)r   rh   TypeValueValuesEnumrn   PROJECTr   rj   associated_project	xpn_typess       r   EnableXpnAssociatedProject$XpnClient.EnableXpnAssociatedProject   s8     ++??I%%I<M<M & Or   c                    U R                   R                  U R                   R                  UUS9S9nU R                   R                  UUS9nU R                  R
                  SU4nSR                  X!5      nU R                  Xg5        g)a  Disassociate the given resource from the given XPN host project.

Args:
  host_project: str, ID of the XPN host project
  associated_resource: ID of the resource to disassociate from host_project
  xpn_resource_type: XpnResourceId.TypeValueValuesEnum, the type of the
     resource
r`   rc   )r7   !projectsDisableXpnResourceRequestDisableXpnResourcezBdisable resource [{0}] as an associated resource for project [{1}]N)r   !ProjectsDisableXpnResourceRequestrh   (ComputeProjectsDisableXpnResourceRequestr   r8   r,   r2   )r   rj   rk   rl   projects_disable_requestr&   r.   r1   s           r   _DisableXpnAssociatedResource'XpnClient._DisableXpnAssociatedResource   s      $}}NNMM//"" 0 $  O  
 mmDD*B E DG [[))+?IM &': I --r   c                 x    U R                   R                  R                  nU R                  XUR                  S9  g)zDisassociate the given project from the given XPN host project.

Args:
  host_project: str, ID of the XPN host project
  associated_project: ID of the project to disassociate from host_project
rq   N)r   rh   rr   r   rs   rt   s       r   DisableXpnAssociatedProject%XpnClient.DisableXpnAssociatedProject   s8     ++??I&&I<M<M ' Or   )r   r   r   r   )r   r   r   r   __doc__r    r(   r2   r;   r@   rE   rS   r]   rn   rw   r   r   r   r   r   r   r   r   "   sE    
,
"
	..5	...	O..	Or   r   c                 X    [         R                  " U 5      n[        UR                  5      $ r   )r   ComputeApiHolderr   r   )release_trackholders     r   GetXpnClientr      s!    ((7&	6==	!!r   N)r   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.computer   r   r	   _DEFAULT_API_VERSIONErrorr   objectr   r   r   r   r   <module>r      sP    I &  ' ' 7 5 0  *"" ZO ZOz"r   