
                             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 e	j                   G d	 d
e	j                               Zddde_        y)zQCommand for adding a term to an existing Route Policy of a Compute Engine router.    )absolute_import)division)unicode_literals)base_classes)arg_parsers)base)flagsc                   *    e Zd ZdZdZed        Zd Zy)AddRoutePolicyTermzFAdds a new term to an existing route policy of a Comute Engine router.Nc           	      x   t        j                         t        _        t        j                  j	                  |d       |j                  ddd       |j                  dddt        j                  d	d
             |j                  ddd       |j                  dddt        j                  d      d       y )Nupdate)operation_typez--policy-namez2Name of the route policy to which to add the term.T)helprequiredz
--priorityz$Order of the term within the policy.r   i)lower_boundupper_bound)r   r   typez--matchz$CEL expression for matching a route.z	--actionszRSemicolon separated CEL expressions for the actions to take when the rule matches.;)custom_delim_charACTION)r   r   r   metavar)	r	   RouterArgumentr   
ROUTER_ARGAddArgumentadd_argumentr   
BoundedIntArgList)clsparsers     4lib/surface/compute/routers/add_route_policy_term.pyArgszAddRoutePolicyTerm.Args#   s    $)$8$8$:!!!--fX-N
E  
 7##zJ	   7  
 e  37      c           
      P   t        j                  | j                               }|j                  }|j                  j                  }|j                  j
                  j                  }t        j                  j                  ||j                  t        j                  |            }|j                   |j                  di |j                         d|j                   i      j"                  }|j%                  |j&                  |j)                  |j*                        |j,                  D cg c]  }|j)                  |       c}      }	|j.                  j1                  |	       |d |j2                  di |j                         d|if}
|j5                  |
g      d   S c c}w )	N)scope_listerpolicy)
expression)prioritymatchactionsPatchRoutePolicyroutePolicyr    )r   ComputeApiHolderReleaseTrackclientmessagesapitools_clientroutersr   r   ResolveAsResource	resourcescompute_flagsGetDefaultScopeListerGetRoutePolicy#ComputeRoutersGetRoutePolicyRequestAsDictpolicy_nameresourceRoutePolicyPolicyTermr'   Exprr(   r)   termsappend%ComputeRoutersPatchRoutePolicyRequestMakeRequests)selfargsholderr/   r0   service
router_refroute_policycel_expressionnew_termrequests              r    RunzAddRoutePolicyTerm.Run?   s   **4+<+<+>?F]]F}}%%Hmm++33G#..@@"88@ A J
 ))444 	
!	
*.*:*:	
 h	 
 --mmtzzm2 #',,
". MM^M4".
 . H h' 	666 	
!	
$	
G y)!,,
s   +F#)__name__
__module____qualname____doc__r   classmethodr!   rK   r,   r"   r    r   r      s!    N* 6"-r"   r   z/  *{command}* adds a term to a route policy.
  af            To add a term with priority 0  with match `destination == '192.168.0.0/16'` and actions `drop()` to a route policy `my-policy` of a router `my-router` in region `us-central1`, run:

              $ {command} my-router --region=us-central1 --policy-name=my-policy --priority=0 --match="destination == '192.168.0.0/16'" --actions="drop()"

          )DESCRIPTIONEXAMPLESN)rO   
__future__r   r   r   googlecloudsdk.api_lib.computer   googlecloudsdk.callioper   r   "googlecloudsdk.command_lib.computer	   r5   *googlecloudsdk.command_lib.compute.routersUniverseCompatibleUpdateCommandr   detailed_helpr,   r"   r    <module>r[      sc     X &  ' 7 / ( E < C-++ C- C-N	
$   r"   