
                         h   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 dd
lmZ ddlmZ ddlmZ  ej*                  ej,                  j.                  ej,                  j0                  ej,                  j2                         G d dej4                               Zy)z&gcloud dns record-sets export command.    )absolute_import)division)unicode_literals)
exceptions)
list_pager)export_util)util)base)flags)log)filesc                   6    e Zd ZdZed        Zed        Zd Zy)Exporta  Export your record-sets into a file.

  This command exports the record-sets contained within the specified
  managed-zone into a file.
  The formats you can export to are YAML records format (default) and
  BIND zone file format.

  ## EXAMPLES

  To export record-sets into a yaml file, run:

    $ {command} records.yaml --zone=examplezonename

  To export record-sets into a BIND zone formatted file instead, run:

    $ {command} pathto.zonefile --zone=examplezonename --zone-file-format

  Similarly, to import record-sets into a BIND zone formatted zone file, run:

    $ gcloud dns record-sets import pathto.zonefile --zone-file-format \
      --zone=examplezonename
  c                     | j                         t        j                   j                  t        j                   j                  fv S )N)ReleaseTrackr
   BETAALPHA)clss    %lib/surface/dns/record_sets/export.py_IsBetaOrAlphazExport._IsBetaOrAlpha:   s:    $"3"3"8"8"&"3"3"9"9"; ; ;    c                     t        j                         j                  |       t        j                         j                  |       |j	                  dd       |j	                  dddd       y )	Nrecords_filez-File to which record-sets should be exported.)helpz--zone-file-formatF
store_truea  Indicates that records-file should be in the zone file format. When using this flag, expect the record-set to be exported to a BIND zone formatted file. If you omit this flag, the record-set is exported into a YAML formatted records file. Note, this format flag determines the format of the output recorded in the records-file; it is different from the global `--format` flag which affects console output alone.)requiredactionr   )r   
GetZoneArgAddToParserGetLocationArgadd_argument)r   parsers     r   ArgszExport.Args?   sl    	""6*	&&v.
L  N
J	  
Kr   c                    t        j                  | j                         |      }t        j                  |      }t        j                  |      j                  |j                  t        j                  ||      d      }	 |j                  j                  |j                  |j                        }|dk(  r|j                  |_        |j                  j                  |      }g }|j                  j'                  |j                  |j)                               }	|dk(  r|j                  |	_        t+        j,                  |j.                  |	d      D ]d  }
| j1                         r1|j2                  r5|
j4                  dk(  r&t7        j8                  d       D|
j4                  dk(  rT|j;                  |
       f 	 t=        j>                  |j@                        5 }|j2                  r"tC        jD                  |||jF                         ntC        jH                  ||       d d d        t6        jP                  jS                  d
jM                  |j@                               y # t        j                   $ r}t#        j$                  |      d }~ww xY w# 1 sw Y   rxY w# tJ        $ r6}d	jM                  |j@                  |      }tC        jN                  |      d }~ww xY w)Nzdns.managedZones)params
collection)projectmanagedZonev2rrsets)fieldALIASzSkippig ALIAS record found in zone, as ALIAS record are custom to Cloud DNS and do not have a standard BIND format. To export ALIAS records, use YAML format instead.z/Unable to export record-sets to file [{0}]: {1}zExported record-sets to [{0}].)*r	   GetApiFromTrackAndArgsr   GetApiClientGetRegistryParsezoneGetParamsForRegistryMESSAGES_MODULEDnsManagedZonesGetRequestr'   r(   locationmanagedZonesGetapitools_exceptions	HttpErrorcalliope_exceptionsHttpException DnsResourceRecordSetsListRequestNamer   YieldFromListresourceRecordSetsr   zone_file_formattyper   warningappendr   
FileWriterr   r   WriteToZoneFilednsNameWriteToYamlFile	ExceptionformatUnableToExportRecordsToFilestatusPrint)selfargsapi_versiondnszone_refget_requestr1   errorrecord_setslist_request
record_setexport_fileexpmsgs                 r   Runz
Export.RunQ   su   --d.?.?.A4HK


K
(C ,22		((d;% 3 'H	5''AA""0D0D B Fk 
	#}}!!+.d
 K&&GG  hmmo H ?L d"mml ..H>
 
			   __'KKA
  ??g%
$'>,	9D--.+  

%
%k;
M

%
%k;
?	 / JJ5<<T=N=NOPY (( 5--e445D /.
  9=DD


S"c33C889sJ    A"I 9J AJJ J1JJJJ 	K#1KKN)__name__
__module____qualname____doc__classmethodr   r#   rZ    r   r   r   r       s7    . ; ; K K">Qr   r   N)r^   
__future__r   r   r   apitools.base.pyr   r8   r   googlecloudsdk.api_lib.dnsr   r	   googlecloudsdk.callioper
   r:   googlecloudsdk.command_lib.dnsr   googlecloudsdk.corer   googlecloudsdk.core.utilr   ReleaseTracksr   GAr   r   Commandr   r`   r   r   <module>rk      s    - &  ' > ' 2 + ( E 0 # * D%%(($*;*;*@*@%%++-mQT\\ mQ-mQr   