
    !'                     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 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efdZ d Z!d Z"edfdZ#d Z$d Z%d Z&d$dZ'd Z(d%dZ)d  Z*d! Z+d" Z,d# Z-y)&z(Methods and constants for global access.    )absolute_import)division)unicode_literals)
exceptions)api_adapterclient)util)job)service)worker_pool)apis)log)
properties)	resourcesv1beta1runv1-appdevexperiencec                 6    t        j                  t        |       S N)r   GetClientInstanceSERVERLESS_API_NAME)api_versions    0lib/googlecloudsdk/api_lib/run/global_methods.pyGetServerlessClientInstancer   ,   s    			 3[	AA    c                 d    t        t        |       D cg c]  }|j                   c}      S c c}w )zGet the list of all available regions from control plane.

  Args:
    client: (base_api.BaseApiClient), instance of a client to use for the list
      request.

  Returns:
    A list of str, which are regions.
  )sortedListLocations
locationId)r	   ls     r   ListRegionsr$   0   s,     
}V'<='<!'<=	>>=s   -c                    t        j                  t        j                  j                  j
                  j                  d            }| j                  j                  | j                  j                  |d            j                  S )zGet the list of all available regions from control plane.

  Args:
    client: (base_api.BaseApiClient), instance of a client to use for the list
      request.

  Returns:
    A list of location resources.
  Trequiredd   )namepageSize)r
   ProjectPathr   VALUEScoreprojectGetprojects_locationsListMESSAGES_MODULERunProjectsLocationsListRequest	locations)r	   project_resource_relnames     r   r!   r!   =   sx     "--$$(($(7 
	"	"	'	'<<'# = 
 I	r   Nc           	      \   t         j                  j                  j                  j	                  d      }t
        j                  j                  |d|id      }| j                  j                  |j                         |      }| j                  j                  |      }|j                  rFt        j                  dj!                  dj#                  t%        |j                                           |j&                  D cg c]"  }t)        j*                  || j                        $ c}S c c}w )	a  Get the global services for a OnePlatform project.

  Args:
    client: (base_api.BaseApiClient), instance of a client to use for the list
      request.
    region: (str) optional name of location to search for services in. If not
      passed, this defaults to the global value for all locations.
    field_selector: (str) optional parameter to pass in request.field_selector.

  Returns:
    List of googlecloudsdk.api_lib.run import service.Service objects.
  Tr&   
projectsIdzrun.projects.locationsparams
collection)parentfieldSelectorTThe following Cloud Run regions did not respond: {}. List results may be incomplete., )r   r,   r-   r.   r/   r   REGISTRYParser2   'RunProjectsLocationsServicesListRequestRelativeNameprojects_locations_servicesr1   unreachabler   warningformatjoinr    itemsr   Service)r	   regionfield_selectorr.   r4   requestresponseitems           r   ListServicesrO   Q   s    ""**...='  &&G$) ' )
 ""JJ##%^ K ' //44W=( KK	**0&IIfX1123+
 AI
@NgoodF223
  
s   ?'D)c                     t        |       S r   )rO   r   s    r   ListWorkersrQ   x   s    	f	r   c           	         | j                   j                  |j                               }| j                  j	                  |      }|j
                  rFt        j                  dj                  dj                  t        |j
                                           |j                  D cg c]"  }t        j                  || j                         $ c}S c c}w )a  Get the global services for a OnePlatform project.

  Args:
    client: (base_api.BaseApiClient), instance of a client to use for the list
      request.
    namespace: namespace/project to list jobs in

  Returns:
    List of googlecloudsdk.api_lib.run import job.Job objects.
  r;   r=   r>   )r2   RunNamespacesJobsListRequestrB   namespaces_jobsr1   rD   r   rE   rF   rG   r    rH   r   Job)r	   	namespacerL   rM   rN   s        r   ListJobsrX   |   s     ""??##% @ ' ##((1( KK	**0&IIfX1123+
 =ENN	KND#''$..
/N	KK	K   &'Cc           	         | j                   j                  |j                               }| j                  j	                  |      }|j
                  rFt        j                  dj                  dj                  t        |j
                                           |j                  D cg c]"  }t        j                  || j                         $ c}S c c}w )a/  Get the global list of worker pools for a OnePlatform project.

  Args:
    client: (base_api.BaseApiClient), instance of a client to use for the list
      request.
    project: project to list worker pools in

  Returns:
    List of googlecloudsdk.api_lib.run import worker_pool.WorkerPool objects.
  rS   r=   r>   )r2   #RunNamespacesWorkerpoolsListRequestrB   namespaces_workerpoolsr1   rD   r   rE   rF   rG   r    rH   r   
WorkerPool)r	   r.   rL   rM   rN   s        r   ListWorkerPoolsr^      s     ""FF!!# G ' **//8( KK	**0&IIfX1123+
 ..
 $ T6#9#9: 
  
rY   c                 R   t        j                  t              }|s4t        j                  j
                  j                  j                  d      }|j                  ||       }|j                  r=t        j                  dj                  dj                  |j                                     d }t        |j                  |      }t!        |      }|D cg c]H  }|j"                  |v s6|j$                  j&                  r"|j$                  j&                  j(                  s|J c}S c c}w )a  Get all clusters with Cloud Run enabled.

  Args:
    location: str optional name of location to search for clusters in. Leaving
      this field blank will search in all locations.
    project: str optional name of project to search for clusters in. Leaving
      this field blank will use the project defined by the corresponding
      property.

  Returns:
    List of
    googlecloudsdk.generated_clients.apis.container.CONTAINER_API_VERSION
    import container_CONTAINER_API_VERSION_messages.Cluster objects
  Tr&   zTThe following cluster locations did not respond: {}. List results may be incomplete.r>   c                 2    | j                   | j                  fS r   )zoner)   )clusters    r   _SortKeyzListClusters.<locals>._SortKey   s    LL',,''r   )key)container_api_adapterNewAPIAdapterCONTAINER_API_VERSIONr   r,   r-   r.   r/   ListClustersmissingZonesr   rE   rF   rG   r    clustersListCloudRunForAnthosClustersr)   addonsConfigcloudRunConfigdisabled)locationr.   container_apirM   rc   rj   crfa_cluster_namescs           r   rh   rh      s     (556KL-	$$,,00$0?G'':(KK	**0&IIh++,+
( H%%84(4W= 

!
&&&
&nn++nn33<< 

 
 

s   AD$c                    t        j                  t        j                  j                  j
                  j                  d            }| j                  j                  |      }| j                  j                  |      }|j                  S )zGet all verified domains.

  Args:
    client: (base_api.BaseApiClient), instance of a client to use for the list
      request.

  Returns:
    List of client.MESSAGES_MODULE.AuthorizedDomain objects
  Tr&   rS   )r
   r+   r   r,   r-   r.   r/   r2   'RunProjectsAuthorizeddomainsListRequestprojects_authorizeddomainsr1   domains)r	   r5   rL   rM   s       r   ListVerifiedDomainsrw      s}     "--$$(($(7 ""JJ% K ' ..33G<(			r   c                     |s4t         j                  j                  j                  j	                  d      }t
        j                  j                  | j                  || j                  dd      S )zReturns a ref for the specified cluster.

  Args:
    cluster: container_CONTAINER_API_VERSION_messages.Cluster object
    project: str optional project which overrides the default

  Returns:
    A Resource object
  Tr&   )	projectIdra   z!container.projects.zones.clustersr8   )
r   r,   r-   r.   r/   r   r?   r@   r)   ra   )rb   r.   s     r   GetClusterRefrz      s`     
$$,,00$0?G				!	!ll"GLL94 
" 
 r   c                 B    g }|j                  d|        t        ||      S )am  Returns a list of clusters accounting for multi-tenant projects.

  This function can also be used for non-multitenant projects and will
  operate on the single passed-in project_id.

  Args:
    project_id: The id of the project, which may or may not be multi-tenant
    cluster_location: The zone or region of the cluster

  Returns:
    A list of cluster refs
  r   )insert_ClustersForProjectIds)
project_idcluster_locationproject_idss      r   MultiTenantClustersForProjectr     s'     +Q
#	-=	>>r   c                 t    g }| D ]0  }t        ||      }|D ]  }|j                  t        ||              2 |S r   )rh   appendrz   )r   r   rM   r~   rj   rb   s         r   r}   r}      sB    (j,j9HoomGZ89    
/r   c                    d| dt         }	 t        j                         j                  |      }t        |      }|j                         D cg c]  \  }}|dk(  s| c}}S # t        j
                  $ r g cY S w xY wc c}}w )a  Get all clusters with Cloud Run for Anthos enabled.

  Args:
   project: str optional of project to search for clusters in. Leaving this
     field blank will use the project defined by the corresponding property.

  Returns:
    List of Cluster string names
  z	projects/z/locations/global/features/OK)CLOUDRUN_FEATURE
hub_client	HubClient
GetFeatureapi_exceptions	HttpError_ListAnthosClusterStatesrH   )r.   	crfa_specfcluster_state_objr)   states         r   rk   rk   )  s     ))))4A /q1"3"9"9";	M";;4u}$";	MM	 
	!	! I 
Ns   #A% B B %A=<A=c                 ,   	 t         j                  j                  | j                        j	                         D ci c]9  \  }}t        j                  |      |j                  j                  j                  ; }}}|S c c}}w # t        $ r i cY S w xY wr   )r   r   ToPyDictmembershipStatesrH   hub_utilMembershipShortnamer   coder)   AttributeError)r   msr   s       r   r   r   A  s     ((11!2D2DEKKMMDAq 	$$Q'):)::M   
 
 Is"   :B >A?:B ?B BB)NNr   ).__doc__
__future__r   r   r   apitools.base.pyr   r    googlecloudsdk.api_lib.containerr   re   &googlecloudsdk.api_lib.container.fleetr	   r   r
   r   googlecloudsdk.api_lib.runr   r   r   %googlecloudsdk.api_lib.runtime_configgooglecloudsdk.api_lib.utilr   googlecloudsdk.corer   r   r   rg   r   SERVERLESS_API_VERSION_ALL_REGIONSr   r   r$   r!   rO   rQ   rX   r^   rh   rw   rz   r   r}   rk   r    r   r   <module>r      s    / &  ' 9 Q G C * . 2 6 , # * )!   %  -C B
?( !-T #NL8>-`(&?$N0r   