
    *                        S r SSKJr  SSKJr  SSKJr  SSKrSSKJr  SSKJ	r	  SSK
Js  Js  Js  Js  Jr  SSKJs  Js  Js  Js  Jr  SrS	rS
r " S S\	R,                  5      r " S S\5      rSrSrS rS rS rS rS rS r S r!S r"S\S\RF                  S\4S jr$ " S S\RJ                  5      r&S r'S  r(S! r)S" r*g)#z,Utilities for `gcloud network-connectivity`.    )absolute_import)division)unicode_literalsN)Any)
exceptionsz	projects/z#location:projects/{0}/locations/{1}z-type:DYNAMIC_ROUTEc                       \ rS rSrSrSrg)NetworkConnectivityError#   z8Top-level exception for all Network Connectivity errors. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       ;lib/googlecloudsdk/command_lib/network_connectivity/util.pyr	   r	   #   s    @r   r	   c                       \ rS rSrSrSrg)InvalidInputError'   zException for invalid input.r   Nr   r   r   r   r   r   '   s    $r   r   a  
    table(
      name.basename(),
      name.segment(3):label=LOCATION,
      hub.basename(),
      group.basename(),
      format(
        "{0}{1}{2}{3}{4}",
        linkedVpnTunnels.yesno(yes="VPN tunnel", no=""),
        linkedInterconnectAttachments.yesno(yes="VLAN attachment", no=""),
        linkedRouterApplianceInstances.yesno(yes="Router appliance", no=""),
        linkedVpcNetwork.yesno(yes="VPC network", no=""),
        gateway.yesno(yes="Gateway", no="")
      ):label=TYPE,
      firstof(linkedVpnTunnels.uris, linkedInterconnectAttachments.uris, linkedRouterApplianceInstances.instances).len().yesno(no="1"):label="RESOURCE COUNT",
      format(
        "{0}{1}",
        linkedVpcNetwork.yesno(yes="N/A", no=""),
        firstof(linkedVpnTunnels.siteToSiteDataTransfer, linkedInterconnectAttachments.siteToSiteDataTransfer, linkedRouterApplianceInstances.siteToSiteDataTransfer, Gateway).yesno(yes="On", no="")
      ).yesno(no="Off"):label="DATA TRANSFER",
      description
    )
an  
    table(
      name.basename(),
      group.basename(),
      name.segment(1):label=PROJECT,
      name.segment(3):label=LOCATION,
      spokeType:label=TYPE,
      state,
      reasons.code.list():label="STATE REASON",
      etag,
      format(
        "{0}{1}",
        linkedVpcNetwork.yesno(yes="N/A", no=""),
        firstof(linkedVpnTunnels.siteToSiteDataTransfer, linkedInterconnectAttachments.siteToSiteDataTransfer, linkedRouterApplianceInstances.siteToSiteDataTransfer, gateway).yesno(yes="On", no="")
      ).yesno(no="Off").if(view=detailed):label="DATA TRANSFER",
      description.if(view=detailed)
    )
c                 0    U=R                   S-  sl         U$ )z$Add locations/global to parent path.z/locations/global)parent
unused_refunused_argsrequests      r   AppendLocationsGlobalToParentr   X   s     
..''.	.r   c                     UR                  S5      (       d3  UR                  (       d  UR                  (       a  SUR                  l        U$ )z3Set legacy export_psc field based on new PSC flags.
export_pscT)IsSpecified6export_psc_published_services_and_regional_google_apisexport_psc_global_google_apis'googleCloudNetworkconnectivityV1betaHub	exportPscr   argsr   s      r   SetExportPscBetar(   _   s:    			,	'	' 	CC--BFg55?	.r   c                     [         U ;  a  [        SR                  U 5      5      eU U R                  [         5      [	        [         5      -   S nUR                  S5      S   nU$ )z+Returns the project from a resource string.z7Resource must contain a project path, but received: {0}N/r   )PROJECTS_RESOURCE_PATHr   formatindexlensplit)resourceprojects     r   DeriveProjectFromResourcer2   k   si    8+
AHH	
 
 nn+,s3I/JJL' MM#q!'	.r   c                     UR                  S5      (       aQ  UR                  n[        UR                  5      n[        R                  XC5      nSR                  U[        5      Ul        U$ )zGAppend filter to limit listing dynamic routes at an effective location.effective_locationz
{0} OR {1})r!   r4   r2   r   LOCATION_FILTER_FMTr,   ROUTE_TYPE_FILTERfilter)r   r'   r   locationr1   location_filters         r   AppendEffectiveLocationFilterr:   z   sY     
*++&&H'7G)00CO!((:KLGN	.r   c                      g)zSet default location to global.globalr   r   r   r   SetGlobalLocationr=      s    	r   c                     UR                  S5      (       a/  UR                  (       a  U=R                  S-  sl        U$ SUl        U$ )zHandles clear_overlaps flag.clear_overlapsz	,overlapsoverlapsr!   
updateMaskr   r'   patch_requests      r   ClearOverlapsrE      sH     
&''+- 
 ",m	r   c                     UR                  S5      (       a/  UR                  (       a  U=R                  S-  sl        U$ SUl        U$ )zHandles clear_labels flag.clear_labelsz,labelslabelsrA   rC   s      r   ClearLabelsrI      sG     
n%%)+ 
 "*m	r   c                 N   UR                  S5      (       a  UR                  S:w  a9  UR                  S5      (       d  UR                  S5      (       a  [        S5      eU$ UR                  S5      (       a  UR                  S5      (       d  [        S5      eUR                  S5      (       a  UR                  S:w  a  [        S	5      eUR                  (       d  [        S
5      eUR
                  (       d  [        S5      eUR                  UR
                  :X  a  [        S5      eU$ )z.Validates internal range migration parameters.usagezfor-migrationmigration_sourcemigration_targetz_migration_source and migration_target can only be specified when usage is set to for-migration.z=Both migration_source and migration_target must be specified.peeringzfor-selfzCPeering must be set to for-self when usage is set to for-migration.z!migration_source cannot be empty.z!migration_target cannot be empty.z9migration_source and migration_target cannot be the same.)r!   rK   r   rN   rL   rM   r&   s      r   ValidateMigrationrO      s   			'	"	"djjO&C*++t/?/?0 0 , 
 n			,	-	-T5E5E6 6 G  
i  T\\Z%?
M  
		
?
@@			
?
@@	d333
C  
.r   refr'   r   c                     A UR                  S5      (       aD  UR                  S:X  a4  UR                  S5      (       a  UR                  S:  a  [        S5      e U$ UR                  S5      (       a  [        S5      eU$ )z,Validates internal range allocation options.allocation_strategyRANDOM_FIRST_N_AVAILABLE"first_available_ranges_lookup_size   zwfirst_available_ranges_lookup_size must be set and greater than 0 when allocation_strategy is RANDOM_FIRST_N_AVAILABLE.zhfirst_available_ranges_lookup_size can only be set when allocation_strategy is RANDOM_FIRST_N_AVAILABLE.)r!   rR   rT   r   )rP   r'   r   s      r   ValidateAllocationOptionsrV      s     

,--

"
"&@
@ ABB22Q6C  7 
. <==
	<  
.r   c                   2   ^  \ rS rSrSr SU 4S jjrSrU =r$ )StoreGlobalAction   z1Return "global" if the --global argument is used.c           	      2   > [         [        U ]  UUSUUUS9  g )Nr<   )option_stringsdestconstdefaultrequiredhelp)superrX   __init__)selfr[   r\   r^   r_   r`   	__class__s         r   rb   StoreGlobalAction.__init__   s,     

T+% , r   r   ) FN)r   r   r   r   r   rb   r   __classcell__)rd   s   @r   rX   rX      s     : DH
 
r   rX   c                     UR                   (       a3  [        R                  R                  R                  UR
                  l        U$ )zSet the route's `recipient` field based on boolean flags.

Args:
  args: The command arguments.
  request: The request to set the `recipient` field on.

Returns:
  The request with the `recipient` field set.
)advertise_to_hubv1beta:GoogleCloudNetworkconnectivityV1betaGatewayAdvertisedRouteRecipientValueValuesEnumADVERTISE_TO_HUB:googleCloudNetworkconnectivityV1betaGatewayAdvertisedRoute	recipientr&   s      r   "SetGatewayAdvertisedRouteRecipientrp      s7     
IIbbss FFP 
.r   c                     SUR                   ;   nUR                   R                  S5      nU(       a  U(       d  [        S5      eU$ )a  If a spoke name is specified, then its region must also be specified.

This is because CCFE doesn't support a wildcard ("-") in this case but returns
a confusing error message. So we give the user a friendlier error.

Args:
  request: The request object. We will inspect the parent field.

Returns:
  The unmodified request object.
Raises:
  InvalidInputError: If the region is unspecified when a spoke is.
z/locations/-/z	/spokes/-z7A region must be specified if a spoke name is specifiedr   endswithr   )r   r   r   region_wildcardspoke_wildcards        r   $CheckRegionSpecifiedIfSpokeSpecifiedrv      sB     $w~~5/>>**;7.^
A  
.r   c                     SUR                   ;   nUR                   R                  S5      nU(       a  U(       d  [        S5      eU(       a  U(       d  [        S5      eU$ )a  Check that hub and route table are both specified or both unspecified.

This is because CCFE doesn't support wildcards ("-") in this case but returns
a confusing error message. So we give he user a friendlier error.

Args:
 request: The request object.

Returns:
  The unmodified request object.
Raises:
  InvalidInputError: If the user needs to specify a hub name or route table
  name.
z/hubs/-/z/routeTables/-z5A hub must be specified if a route table is specifiedz5A route table must be specified if a hub is specifiedrr   )r   r   r   hub_wildcardroute_table_wildcards        r   (CheckForRouteTableAndHubWildcardMismatchrz     s\     w~~-, 001AB.
?  ,
?  
.r   c                     [        UR                  S5      (       d  U$ UR                  R                  [        R                  R
                  R                  :w  a  U$ [        S5      e)zReject requests with HYBRID_INSPECTION preset topology.

Args:
  request: A CreateHubRequest object.

Returns:
  The unmodified request object.
Raises:
  InvalidInputError: If the CreateHubRequest has the HYBRID_INSPECTION preset
  topology.
presetTopologyzHYBRID_INSPECTION unsupported in the GA component; use the beta component instead. See https://cloud.google.com/sdk/gcloud#release_levels)hasattrhubr|   v1HubPresetTopologyValueValuesEnumHYBRID_INSPECTIONr   r   s      r   ProhibitHybridInspectionr   0  sW     
.	/	/Nkk  ff**<<=N?	 r   )+r   
__future__r   r   r   argparsetypingr   googlecloudsdk.corer   \googlecloudsdk.generated_clients.apis.networkconnectivity.v1.networkconnectivity_v1_messagesgenerated_clientsapisnetworkconnectivityr   networkconnectivity_v1_messagesdgooglecloudsdk.generated_clients.apis.networkconnectivity.v1beta.networkconnectivity_v1beta_messagesrj   #networkconnectivity_v1beta_messagesr+   r5   r6   Errorr	   r   LIST_FORMATLIST_SPOKES_FORMATr   r(   r2   r:   r=   rE   rI   rO   	NamespacerV   _StoreConstActionrX   rp   rv   rz   r   r   r   r   <module>r      s    3 &  '   * i i i u u u % ; ) Az// A%0 %
0 (	
D3 h.@.@ 3 022 $".8r   