
                             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ZddZd dZd dZd 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!d Z"d Z#y)!z'Utilities for networkservices commands.    )absolute_import)division)unicode_literals)
list_pager)network_services)apis)concepts)	multitype)	yaml_datac                 >    t        j                  d|       fd}|S )a  Hook to transform AutoCapacityDrain flag to actual message.

  This function is called during ServiceLbPolicy create/update command to
  create the AutoCapacityDrain message. It returns a function which is called
  with arguments passed in the gcloud command.

  Args:
    api_version: Version of the networkservices api

  Returns:
     Function to transform boolean flag to AutcapacityDrain message.
  networkservicesc                 .    | rj                  |       S y )N)enable) ServiceLbPolicyAutoCapacityDrain)r   messagess    7lib/googlecloudsdk/command_lib/network_services/util.pyConstructAutoCapacityDrainz9AutoCapacityDrainHook.<locals>.ConstructAutoCapacityDrain,   s    66f6EE     r   GetMessagesModule)api_versionr   r   s     @r   AutoCapacityDrainHookr      s&     ##$5{C(F 
$#r   c                 >    t        j                  d|       fd}|S )a  Hook to transform FailoverHealthThreshold flag to actual message.

  This function is called during ServiceLbPolicy create/update command to
  create the FailoverConfig message. It returns a function which is called
  with arguments passed in the gcloud command.

  Args:
    api_version: Version of the networkservices api

  Returns:
     Function to transform integer flag to FailoverConfig message.
  r   c                 (    j                  |       S )N)failoverHealthThreshold)ServiceLbPolicyFailoverConfig)	thresholdr   s    r   ConstructFailoverConfigz<FailoverHealthThresholdHook.<locals>.ConstructFailoverConfigB   s    11 ) 2  r   r   )r   r   r   s     @r   FailoverHealthThresholdHookr   3   s%     ##$5{C(
 
! r   Nc                 f    d|v rt        | |||      S d|v rt        | |||      S t        d|z        )z0Calls appropriate List method based on the name.meshesgatewaysInvalid name: %s)_ListMeshRouteViews_ListGatewayRouteViews
ValueError)trackname	page_sizelimits       r   ListRouteViewsr+   J   sE    udIu==T!%y%@@
'$.
//r   c                     t        j                  |       }t        j                  |       }|j                  |      }t	        j
                  |j                  |d||d      S )zCalls ListMeshRouteViews API.parentmeshRouteViewspageSizeservicerequestfield
batch_sizer*   batch_size_attribute)ns_apiGetClientInstancer   ;NetworkservicesProjectsLocationsMeshesRouteViewsListRequestr   YieldFromList$projects_locations_meshes_routeViewsr'   r(   r)   r*   clientmsgr3   s          r   r$   r$   T   sh    ##E*&  '#KK L ' 
	!	!99%
 r   c                     t        j                  |       }t        j                  |       }|j                  |      }t	        j
                  |j                  |d||d      S )z Calls ListGatewayRouteViews API.r-   gatewayRouteViewsr0   r1   )r7   r8   r   =NetworkservicesProjectsLocationsGatewaysRouteViewsListRequestr   r:   &projects_locations_gateways_routeViewsr<   s          r   r%   r%   e   sh    ##E*&  '#MM N '
 
	!	!;;%
 r   c                 ^    d|v rt        | |      S d|v rt        | |      S t        d|z        )z/Calls appropriate Get method based on the name.r!   r"   r#   )_GetMeshRouteView_GetGatewayRouteViewr&   )r'   r(   s     r   GetRouteViewrF   x   s=    UD))Tt,,
'$.
//r   c                     t        j                  |       }t        j                  |       }|j                  |      }|j                  j                  |      S Nr(   )r7   r8   r   :NetworkservicesProjectsLocationsMeshesRouteViewsGetRequestr;   Getr'   r(   r=   r>   r3   s        r   rD   rD      sT    ##E*&  '#JJ K ' 
	4	4	8	8	AAr   c                     t        j                  |       }t        j                  |       }|j                  |      }|j                  j                  |      S rH   )r7   r8   r   <NetworkservicesProjectsLocationsGatewaysRouteViewsGetRequestrB   rK   rL   s        r   rE   rE      sT    ##E*&  '#LL M ' 
	6	6	:	:7	CCr   c                      t         j                  j                  d      } t        j                  j                  | j                               S )z>Reads the gateway route view resource spec from the yaml file.znetwork_services.locationr   ResourceYAMLDataFromPathr	   ResourceSpecFromYamlGetDatadatas    r   LocationResourceSpecrX      s6    		#	#	,	,-H	I$				'	'	77r   c                      t         j                  j                  d      } t        j                  j                  | j                               S )z0Reads the mesh resource spec from the yaml file.znetwork_services.meshrP   rV   s    r   MeshResourceSpecrZ      s6    		#	#	,	,-D	E$				'	'	77r   c                      t         j                  j                  d      } t        j                  j                  | j                               S )z3Reads the gateway resource spec from the yaml file.znetwork_services.gatewayrP   rV   s    r   GatewayResourceSpecr\      s6    		#	#	,	,-G	H$				'	'	77r   c                 .    d| v xr d| v xr
 d| v xs d| v S )z/Returns whether name is a fully qualified name.z	projects/	locationsr!   r"    rI   s    r   IsFullyQualifiedNamer`      s5     T 3

3t1zT1r   c                  0    t        j                  dd      S )NlocationzLocation of the {resource}r(   	help_textr	    ResourceParameterAttributeConfigr_   r   r   LocationAttributeConfigrg      s    		2	2,
 r   c                  0    t        j                  dd      S )NmeshzParent Mesh of the {resource}rc   re   r_   r   r   MeshAttributeConfigrj      s    		2	2/
 r   c                  0    t        j                  dd      S )Ngatewayz Parent Gateway of the {resource}rc   re   r_   r   r   GatewayAttributeConfigrm      s    		2	22
 r   c                  0    t        j                  dd      S )N
route-viewzThe RouteView resourcerc   re   r_   r   r   RouteViewAttributeConfigrp      s    		2	2(
 r   c            
          t        j                  ddt         j                  t               t	               t               dd      S )Nz4networkservices.projects.locations.meshes.routeViewsro   v1alpha1T)resource_name
projectsIdlocationsIdmeshesIdrouteViewsIdr   is_positional)r	   rS    DEFAULT_PROJECT_ATTRIBUTE_CONFIGrg   rj   rp   r_   r   r   MeshRouteViewResourceSpecrz      s<    			< ::)+"$+-	
 	r   c            
          t        j                  ddt         j                  t               t	               t               dd      S )Nz6networkservices.projects.locations.gateways.routeViewsro   rr   T)rs   rt   ru   
gatewaysIdrw   r   rx   )r	   rS   ry   rg   rm   rp   r_   r   r   GatewayRouteViewResourceSpecr}      s<    			> ::)+')+-	
 	r   c                  T    t        j                  dt               t               d      S )Nmesh_or_gateway_route_viewT)allow_inactive)r
   MultitypeResourceSpecrz   r}   r_   r   r   "MeshOrGatewayRouteViewResourceSpecr      s'    		(	("!"$	
 r   )v1)d   N)$__doc__
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_libr   r7   googlecloudsdk.api_lib.utilr    googlecloudsdk.calliope.conceptsr	   r
   $googlecloudsdk.command_lib.util.apisr   r   r   r+   r$   r%   rF   rD   rE   rX   rZ   r\   r`   rg   rj   rm   rp   rz   r}   r   r_   r   r   <module>r      s    . &  ' ' = , 5 6 :$,!.0"&0BD888

r   