
                             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 ej                    G d
 dej"                               Zddde_        y)zDCommand for adding an empty route policy to a Compute Engine router.    )absolute_import)division)unicode_literals)base_classes)base)
exceptions)flags)	arg_utilsc                   6    e Zd ZdZdZed        Zd Zd Zd Z	y)AddRoutePolicyz5Add an empty route policy to a Compute Engine router.Nc                     t        j                         t        _        t        j                  j	                  |d       |j                  ddd       |j                  dt        j                  dd	d
dd       y )Nupdate)operation_typez--policy-namez Name of the route policy to add.T)helprequiredz--policy-typez%The route policy is an import policy.z%The route policy is an export policy.)IMPORTEXPORTz Type of the route policy to add.)typechoicesr   r   )r	   RouterArgumentr   
ROUTER_ARGAddArgumentadd_argumentr
   ChoiceToEnumName)clsparsers     /lib/surface/compute/routers/add_route_policy.pyArgszAddRoutePolicy.Args$   s|     % 4 4 6N))&)J
3  
 ''==
 4  	    c                    t        j                  | j                               }|j                  }t        j
                  j                  ||j                  t        j                  |            }|j                  j                  |j                  |j                  j                  j                  | j                  |j                                    }| j!                  |||j                         |j"                  j$                  d |j                  j&                  di |j)                         d|if}|j+                  |g      d   S )zIssues the requests needed for adding an empty route policy to a Router.

    Args:
      args: contains arguments passed to the command.

    Returns:
      The result of patching the router adding the empty route policy.
    )scope_lister)namer   UpdateRoutePolicyroutePolicyr    )r   ComputeApiHolderReleaseTrackclientr   r   ResolveAsResource	resourcescompute_flagsGetDefaultScopeListermessagesRoutePolicypolicy_nameTypeValueValuesEnumConvertRouteTypepolicy_typeRequireRoutePolicyDoesNotExistapitools_clientrouters&ComputeRoutersUpdateRoutePolicyRequestAsDictMakeRequests)selfargsholderr(   
router_refroute_policyrequests          r   RunzAddRoutePolicy.Run8   s%    **4+<+<+>?F]]F**<<"88@ = J
 ??..__((<<!!$"2"23
 / L 	''
D<L<LM&&>>> 	
!	
/;	
G y)!,,r   c                 N   |j                   j                  d |j                  j                  di |j	                         d|if}	 |j                  |g       t        j                  ddj                  |            # t        $ r}d|j                         v rY d }~y  d }~ww xY w)NGetRoutePolicypolicyz?Could not fetch resource:
 - Invalid value for field 'policy': zpolicy-namez#A policy named '{0}' already existsr%   )r4   r5   r-   #ComputeRoutersGetRoutePolicyRequestr7   r8   	Exception__str__r   BadArgumentExceptionformat)r9   r(   r<   r/   r>   	exceptions         r   r3   z-AddRoutePolicy.RequireRoutePolicyDoesNotExist[   s    &&;;; 	
!	
*5	
G7)$ 
)
)<CCKP   
L ! 	s   A> >	B$BBB$c                     |dk(  ry|dk(  ry|S )Nr   ROUTE_POLICY_TYPE_IMPORTr   ROUTE_POLICY_TYPE_EXPORTr%   )r9   
route_types     r   r1   zAddRoutePolicy.ConvertRouteTypep   s    X'	x	'r   )
__name__
__module____qualname____doc__r   classmethodr   r?   r3   r1   r%   r   r   r   r      s,    =* &!-F*r   r   zO          *{command}* adds an empty route policy to a Compute Engine router.
  z          To add an import route policy `my-policy`  to a router `my-router` in region `us-central1`, run:

              $ {command} my-router --region=us-central1 --policy-name=my-policy --policy-type=IMPORT

          )DESCRIPTIONEXAMPLESN)rP   
__future__r   r   r   googlecloudsdk.api_lib.computer   googlecloudsdk.callioper   r   "googlecloudsdk.command_lib.computer	   r+   *googlecloudsdk.command_lib.compute.routers$googlecloudsdk.command_lib.util.apisr
   UniverseCompatibleUpdateCommandr   detailed_helpr%   r   r   <module>r]      se     K &  ' 7 ( . E < : WT'' W Wv	
  r   