
                         "   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&                   e	j(                  e	j*                  j,                         G d de	j.                                      Zy)zACommand for downloading a named set 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)DownloadNamedSetzxDownload a named set from a Compute Engine router.

  *{command}* downloads a named set 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
--set-nameTz"Name of the named set to download.)requiredhelpz--file-namez9The name of the file to download the named set 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     1lib/surface/compute/routers/download_named_set.pyArgszDownloadNamedSet.Args+   s    "'"6"6"8++F8+L
1  
 H  
  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 named set 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GetNamedSetset_nameWriteToFilefile_format)selfargsholderr#   
router_ref	named_sets         r   RunzDownloadNamedSet.Run?   s    **4+<+<+>?F]]F!,,>>"88@ ? J 
ww}}T^^$''
 
'
'
7    T]]CIY0@0@Ar   c                     |j                   j                  d |j                  j                  di |j	                         d|if}|j                  |g      d   S )Nr.   namedSetr    )apitools_clientroutersmessages ComputeRoutersGetNamedSetRequestAsDictMakeRequests)r2   r#   r5   r/   requests        r   r.   zDownloadNamedSet.GetNamedSetQ   sb    &&888 	
!	
,4	
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DownloadNamedSet.WriteToFile[   s@    k			)	$" 
%	$	$s	   <A)
__name__
__module____qualname____doc__r   classmethodr   r7   r.   r0   r:   r   r   r   r   !   s0    
 * &B$-r   r   )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   HiddenReleaseTracksr"   ALPHADescribeCommandr   r:   r   r   <module>rY      su     H &  ' 	 7 ( . E < 9 * D%%++,@t++ @ - @r   