
    2                     L   d Z ddlmZ ddlmZ ddlmZ ddl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dlZd Zd Z  ejB                  ejD                  jF                        ejH                   G d dejJ                                      Z&d Z' ejB                  ejD                  jP                  ejD                  jR                        ejH                   G d de&                    Z*y)zCommand for creating routes.    )absolute_import)division)unicode_literalsN)base_classes)actions)arg_parsers)base)
exceptions)
completers)flags)resource_manager_tags_utils)
propertiesc                     | j                  dd       | j                  dd       t        j                  j                  |        | j                  dd       y)	z8Attach arguments for GA next-hops to the a parser group.z--next-hop-instancez      Specifies the name of an instance that should handle traffic
      matching this route. When this flag is specified, the zone of
      the instance must be specified using
      ``--next-hop-instance-zone''.
      helpz--next-hop-addressa         Specifies the IP address of an instance that should handle
      matching packets. The instance must have IP forwarding enabled
      (i.e., include ``--can-ip-forward'' when creating the instance
      using `gcloud compute instances create`)
      z--next-hop-vpn-tunnelz:The target VPN tunnel that will receive forwarded traffic.N)add_argumentr   NEXT_HOP_GATEWAY_ARGAddArgument)next_hop_groups    $lib/surface/compute/routes/create.py
_AddGaHopsr   )   sl     
   
   ((8H  K    c                 D   | j                  dd       | j                  ddd       | j                  dt        j                  d	
      g dd       | j                  ddd       | j                  ddt        d       | j	                  d      }t        |       | j                  dt        j                  t        j                  j                  j                        dt        j                  z          | j                  ddt        j                  z          |j                  dd       | j                  ddt        j                  z          | j                  d t        j                          d!d"#       | j"                  j%                  t&        j(                         y$)%z!Add arguments for route creation.z--descriptionz/An optional, textual description for the route.r   z	--networkdefault9Specifies the network to which the route will be applied.)r   r   z--tags   )
min_lengthTAGz      Identifies the set of instances that this route will apply to. If no
      tags are provided, the route will apply to all instances in the network.
      )typer   metavarr   z--destination-rangeTz      The destination range of outgoing packets that the route will
      apply to. To match all traffic, use ``0.0.0.0/0''.
      )requiredr   z
--priorityi  z      Specifies the priority of this route relative to other routes
      with the same specificity. The lower the value, the higher the
      priority.
      )r   r   r   r!   z--next-hop-instance-zonez#The zone of the next hop instance. )actionr   z--next-hop-vpn-tunnel-regionz'The region of the next hop vpn tunnel. z--next-hop-ilba        Specifies the name or IP address of a forwarding rule for an internal TCP/UDP
      load balancer. The forwarding rule's `--load-balancing-scheme` must be
      `INTERNAL`. You can use any `--destination-range` that doesn't exactly
      match the destination of a subnet route and isn't more specific (has a
      longer subnet mask) than the destination of a subnet route. For
      more information, see
      https://cloud.google.com/load-balancing/docs/internal/ilb-next-hop-overview#destination_range.
      --next-hop-ilb-regionz,The region of the next hop forwarding rule. z--resource-manager-tagsz	KEY=VALUEzW          A comma-separated list of Resource Manager tags to apply to the route.
      )r   r    r   N)r   r   ArgListintadd_mutually_exclusive_groupr   r   StorePropertyr   VALUEScomputezoneinstance_flagsZONE_PROPERTY_EXPLANATIONcompute_flagsREGION_PROPERTY_EXPLANATIONArgDictdisplay_infoAddCacheUpdaterr   RoutesCompleter)parsernext_hops     r   _Argsr6   E   s    	M  O 	F  H
 	!,
   	
   	
	   00$0?(X "":#4#4#<#<#A#AB1445  7 	$5556  8
 
  
 	:556  8
 	 
	   	%%j&@&@Ar   c                   :    e Zd ZdZdZdZdZdZdZe	d        Z
d Zy)CreateaM  Create a new route.

    *{command}* is used to create routes. A route is a rule that
  specifies how certain packets should be handled by the virtual
  network. Routes are associated with virtual machine instances
  by tag, and the set of routes for a particular VM is called
  its routing table. For each packet leaving a virtual machine,
  the system searches that machine's routing table for a single
  best matching route.

  Routes match packets by destination IP address, preferring
  smaller or more specific ranges over larger ones (see
  `--destination-range`). If there is a tie, the system selects
  the route with the smallest priority value. The packet
  is then forwarded as specified by `--next-hop-address`,
  `--next-hop-instance`, `--next-hop-vpn-tunnel`, or
  `--next-hop-gateway` of the winning route. Packets that do
  not match any route in the sending virtual machine routing
  table will be dropped.

  Exactly one of `--next-hop-address`, `--next-hop-gateway`,
  `--next-hop-vpn-tunnel`, or `--next-hop-instance` must be
  provided with this command.

  ## EXAMPLES

  To create a route with the name 'route-name' with destination range
  '0.0.0.0/0' and with next hop gateway 'default-internet-gateway', run:

    $ {command} route-name \
      --destination-range=0.0.0.0/0 \
      --next-hop-gateway=default-internet-gateway

  Nc                    |j                   j                  t        j                         t	        j
                  dd      | _        t        j                  d      | _	        t        j                  d      | _        t        j                  d      | _        t        j                          | _        | j"                  j%                  |d       t'        |       y )Nr   Fr"   create)operation_type)r1   	AddFormatr   DEFAULT_LIST_FORMATnetwork_flagsNetworkArgumentForOtherResourceNETWORK_ARGr,   InstanceArgumentForRouteINSTANCE_ARG	vpn_flagsVpnTunnelArgumentForRouteVPN_TUNNEL_ARG	ilb_flagsForwardingRuleArgumentForRouteILB_ARGRouteArgument	ROUTE_ARGr   r6   )clsr4   s     r   ArgszCreate.Args   s    
!!%";";<#CCCCO &>>NC"<<eLC::EJCK'')CMMMfX>	&Mr   c                 8   t        j                  | j                               }|j                  }| j                  j                  ||j                        j                         }| j                  j                  ||j                        }|j                  rJ| j                  j                  ||j                  t        j                  |            j                         }n#|j                  rt        j                  d      d}|j                   r;t"        j$                  j                  ||j                        }|j                         }nd}d}	|j&                  rJ| j(                  j                  ||j                  t+        j,                  |            j                         }	n!|j.                  rt        j                  d      d}
|j0                  rO	 t3        j4                  |j0                         |j6                  rt9        j:                  dd      |j0                  }
n"|j6                  rt9        j:                  dd      |j@                  jC                  |jD                  |j@                  jG                  |jH                  |jJ                  |jM                         |||jN                  ||	|jP                  |jR                  
      	      }|
|jT                  _+        |jX                  /t[        |j@                  |jX                        |jT                  _.        |j_                  |j`                  jb                  d
|fg      S # t<        $ rM | j>                  j                  ||j                  t+        j,                  |            j                         }
Y Tw xY w)zEIssue API requests for route creation, callable from multiple tracks.)scope_listerz[[--next-hop-instance-zone] can only be specified in conjunction with [--next-hop-instance].Nza[--next-hop-vpn-tunnel-region] can only be specified in conjunction with [--next-hop-vpn-tunnel].r$   zKThis should not be specified if an IP address is used for [--next-hop-ilb].z@This can only be specified in conjunction with [--next-hop-ilb].)
description	destRangenamenetworknextHopInstance	nextHopIpnextHopGatewaynextHopVpnTunnelprioritytags)projectrouteInsert)2r   ComputeApiHolderReleaseTrackclientr@   ResolveAsResource	resourcesSelfLinkrJ   next_hop_instancerB   r,   GetInstanceZoneScopeListernext_hop_instance_zonecompute_exceptionsArgumentErrornext_hop_gatewayr   r   next_hop_vpn_tunnelrE   r.   GetDefaultScopeListernext_hop_vpn_tunnel_regionnext_hop_ilb	ipaddress
ip_addressnext_hop_ilb_regionr
   InvalidArgumentException
ValueErrorrH   messagesComputeRoutesInsertRequestrY   RouterO   destination_rangeNamenext_hop_addressrW   rX   rZ   
nextHopIlbresource_manager_tags_CreateRouteParamsparamsMakeRequestsapitools_clientroutes)selfargsholderr^   network_uri	route_refnext_hop_instance_urinext_hop_gateway_refnext_hop_gateway_urinext_hop_vpn_tunnel_urinext_hop_ilb_urirequests               r   Runz
Create.Run   sU   **4+<+<+>?F]]F""44f  (
  00v7G7GHI"//AA



%@@ B   xz	  
	$	$ ..*+ 	+ #"77II
  "1::<!" $ 3 3 E E



$::6B !F !D EMHJ  
	(	(,,67 7 $T../##33% (<= =  ,, 
	!	!//
! $/0 0 oo88!!oo##((,,!1++/4]] $ 
 9 G  0GMM!!-/
//455gmm 

 
 
'
'7	;< C  $<<99&<< :  "	 	$s   AM ANN)__name__
__module____qualname____doc__r@   rB   rE   rH   rJ   classmethodrL   r    r   r   r8   r8      s;    !F +,.')
 
Wr   r8   c                    t        j                  |      }| j                  }t        t	        j
                  |            D cg c]"  \  }}|j                  j                  ||      $ }}} ||j                  |            S c c}}w )N)keyvalue)additionalProperties)resourceManagerTags)r   GetResourceManagerTagsRouteParamssortedsix	iteritemsResourceManagerTagsValueAdditionalProperty)rq   rx   resource_manager_tags_maprz   r   r   additional_propertiess          r   ry   ry   *  s    !889NO  & s}}-FGHH*#u %%88S8NH   
 994 : 
 	s   'Bc                       e Zd ZdZy)CreateAlphaBetaa  Create a new route.

    *{command}* is used to create routes. A route is a rule that
  specifies how certain packets should be handled by the virtual
  network. Routes are associated with virtual machine instances
  by tag, and the set of routes for a particular VM is called
  its routing table. For each packet leaving a virtual machine,
  the system searches that machine's routing table for a single
  best matching route.

  Routes match packets by destination IP address, preferring
  smaller or more specific ranges over larger ones (see
  ``--destination-range''). If there is a tie, the system selects
  the route with the smallest priority value. If there is still
  a tie, it uses the layer 3 and 4 packet headers to
  select just one of the remaining matching routes. The packet
  is then forwarded as specified by ``--next-hop-address'',
  ``--next-hop-instance'', ``--next-hop-vpn-tunnel'', ``--next-hop-gateway'',
  or ``--next-hop-ilb'' of the winning route. Packets that do
  not match any route in the sending virtual machine routing
  table will be dropped.

  Exactly one of ``--next-hop-address'', ``--next-hop-gateway'',
  ``--next-hop-vpn-tunnel'', ``--next-hop-instance'', or ``--next-hop-ilb''
  must be provided with this command.

  ## EXAMPLES

  To create a route with the name 'route-name' with destination range
  '0.0.0.0/0' and with next hop gateway 'default-internet-gateway', run:

    $ {command} route-name \
      --destination-range=0.0.0.0/0 \
      --next-hop-gateway=default-internet-gateway

  N)r   r   r   r   r   r   r   r   r   :  s    #r   r   )+r   
__future__r   r   r   rl   googlecloudsdk.api_lib.computer   googlecloudsdk.callioper   r   r	   r
   "googlecloudsdk.command_lib.computer   re   r   r.   r   3googlecloudsdk.command_lib.compute.forwarding_rulesrF   ,googlecloudsdk.command_lib.compute.instancesr,   +googlecloudsdk.command_lib.compute.networksr>   )googlecloudsdk.command_lib.compute.routes.googlecloudsdk.command_lib.compute.vpn_tunnelsrC   googlecloudsdk.corer   r   r   r6   ReleaseTracksr]   GAUniverseCompatibleCreateCommandr8   ry   ALPHABETAr   r   r   r   <module>r      s    # &  '  7 + / ( . 9 O E J R P N ; M * 
K8OBd D%%(()NT N  *Nb  D%%++T->->-C-CD$f $  E$r   