
    f                         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 e	j&                   G d de	j(                               Zddde_        y)zDCommand for downloading a route policy from a Compute Engine router.    )absolute_import)division)unicode_literalsN)base_classes)base)
exceptions)flags)resource_printer)filesc                   6    e Zd ZdZdZed        Zd Zd Zd Z	y)DownloadRoutePolicyz5Download a route policy from a Compute Engine router.Nc                     t        j                         t        _        t        j                  j	                  |d       |j                  ddd       |j                  ddd       |j                  d	d
dgd       y )Nexport)operation_typez--policy-nameTz%Name of the route policy to download.)requiredhelpz--file-namez<The name of the file to download the route policy config to.z--file-formatjsonyamlz(Format of the file passed to --file-name)choicesr   )r	   RouterArgumentr   
ROUTER_ARGAddArgumentadd_argument)clsparsers     4lib/surface/compute/routers/download_route_policy.pyArgszDownloadRoutePolicy.Args'   s    %*%9%9%;"""..vh.O
4  
 K  
  7      c                    t        j                  | j                               }|j                  }t        j
                  j                  ||j                  t        j                  |            }t        j                  j                  |j                        r.t        j                  dj!                  |j                              | j#                  |||j$                        }| j'                  ||j                  |j(                         y)z?Downloads a route policy from a Router into the specified file.)scope_listerz[{0}] is a directoryN)r   ComputeApiHolderReleaseTrackclientr   r   ResolveAsResource	resourcescompute_flagsGetDefaultScopeListerospathisdir	file_namer   BadFileExceptionformatGetRoutePolicypolicy_nameWriteToFilefile_format)selfargsholderr#   
router_refroute_policys         r   RunzDownloadRoutePolicy.Run;   s    **4+<+<+>?F]]F$//AA"88@ B J 
ww}}T^^$''
 
'
'
7  &&vz4;K;KLL\4>>43C3CDr   c                     |j                   j                  d |j                  j                  di |j	                         d|if}|j                  |g      d   S )Nr.   policyr    )apitools_clientroutersmessages#ComputeRoutersGetRoutePolicyRequestAsDictMakeRequests)r2   r#   r5   r/   requests        r   r.   z"DownloadRoutePolicy.GetRoutePolicyM   sb    &&;;; 	
!	
*5	
G y)!,,r   c                     |d}t        j                  |      5 }t        j                  |||       d d d        y # 1 sw Y   y xY w)Nr   )r%   print_formatout)r   
FileWriterr
   Print)r2   messager+   r1   export_files        r   r0   zDownloadRoutePolicy.WriteToFileW   s@    k			)	$" 
%	$	$s	   <A)
__name__
__module____qualname____doc__r   classmethodr   r7   r.   r0   r:   r   r   r   r   !   s,    =* &E$-r   r   zG  *{command}* downloads a route policy from a Compute Engine router.
  a            To download a route policy `my-export-policy` to a file `my-export-policy.yaml` from a router `my-router` in region `us-central1`, run:

            $ {command} my-router --region=us-central1 --policy-name=my-export-policy --file-name=my-export-policy.yaml"
  )DESCRIPTIONEXAMPLES)rL   
__future__r   r   r   r(   googlecloudsdk.api_lib.computer   googlecloudsdk.callioper   r   "googlecloudsdk.command_lib.computer	   r&   *googlecloudsdk.command_lib.compute.routersgooglecloudsdk.core.resourcer
   googlecloudsdk.core.utilr   UniverseCompatibleDescribeCommandr   detailed_helpr:   r   r   <module>rZ      si     K &  ' 	 7 ( . E < 9 * =$.. = =B		%  !r   