
                            S r SSKJr  SSKJr  SSKJr  SSKrSSKJr  SSKJ	r	  SSK
Jr  SS	K
Jr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  \R,                  \R.                  \R0                  " \R2                  R4                  \R2                  R6                  \R2                  R8                  5       " S S\R:                  5      5       5       5       rg)z&gcloud dns record-sets import command.    )absolute_import)division)unicode_literalsN)
exceptions)
list_pager)import_util)util)base)flags)log)filesc                   .    \ rS rSrSr\S 5       rS rSrg)Import#   a  Import record-sets into your managed-zone.

This command imports record-sets contained within the specified record-sets
file into your managed-zone. Note that NS records for the origin of the zone
and the SOA NS field are not imported since name-servers are managed by
Cloud DNS. By default, record-sets cannot be imported if there are any
conflicts. A conflict exists if an existing record-set has the same name and
type as a record-set that is being imported. In contrast, if the
--delete-all-existing flag is used, the imported record-sets will replace all
the records-sets currently in the managed-zone.

## EXAMPLES

To import record-sets from a yaml record-sets file, run:

  $ {command} YAML_RECORDS_FILE --zone=MANAGED_ZONE

To import record-sets from a zone file, run:

  $ {command} ZONE_FILE --zone-file-format --zone=MANAGED_ZONE

To replace all the record-sets in your zone with records from a yaml
file, run:

  $ {command} YAML_RECORDS_FILE --delete-all-existing --zone=MANAGED_ZONE
c                 r   [         R                  " 5       R                  U5        [         R                  " 5       R                  U5        UR	                  SSS9  UR	                  SSSSS9  UR	                  S	SSS
S9  UR	                  SSSSS9  UR
                  R                  [         R                  5        g )Nrecords_filezFile from which record-sets should be imported. For examples of YAML-formatted and BIND zone-formatted records files, refer to https://cloud.google.com/dns/records#importing_and_exporting_record_sets)helpz--zone-file-formatF
store_truez|Indicates that the input records-file is in BIND zone format. If omitted, indicates that the records-file is in YAML format.)requiredactionr   z--delete-all-existingzoIndicates that all existing record-sets should be deleted before importing the record-sets in the records-file.z--replace-origin-nszPIndicates that NS records for the origin of a zone should be imported if defined)r   
GetZoneArgAddToParserGetLocationArgadd_argumentdisplay_info	AddFormatCHANGES_FORMAT)clsparsers     %lib/surface/dns/record_sets/import.pyArgsImport.ArgsC   s    	""6*	&&v.
D  E O	  Q :	  ; 	    !!%"6"67    c           	      \	   [         R                  " U R                  5       U5      n[        R                  R                  UR                  5      (       d/  [        R                  " SR                  UR                  5      5      e[        R                  R                  UR                  5      (       a/  [        R                  " SR                  UR                  5      5      e[         R                  " U5      n[         R                  " U5      R                  UR                  [         R                   " X!5      SS9n UR"                  R%                  UR&                  UR(                  S9nUS:X  a  UR*                  Ul        UR,                  R/                  U5      n0 nUR"                  R9                  UR&                  UR;                  5       S9n	US:X  a  UR*                  U	l        [<        R>                  " UR@                  U	SS9 H  n
XU
RB                  U
RD                  4'   M      [F        RH                  " UR                  5       nURJ                  (       a   [        RL                  " XRN                  US	9nO[        RP                  " US
US9nS S S 5        [        RX                  " UWURZ                  URN                  UR\                  US	9nU(       d;  SR                  UR                  5      n[^        R`                  Rc                  U5        g UR"                  Re                  XRB                  UR&                  S9nUS:X  a  UR*                  Ul        URf                  Ri                  U5      n[         R                   " X!SS9nURj                  US'   [         R                  " U5      R                  S SUS9nSR                  UR                  UR;                  5       5      n[^        R`                  Rc                  U5        [^        Rl                  " U5        U$ ! [0        R2                   a  n[4        R6                  " U5      eS nAff = f! , (       d  f       GN= f! [R         aC  nSnUR                  UR                  URT                  5      n[        RV                  " U5      eS nAff = f)Nz&Specified record file [{0}] not found.z*Specified record file [{0}] is a directoryzdns.managedZones)params
collection)projectmanagedZonev2rrsets)field)api_versionT)include_extended_recordsr,   zJUnable to read record-sets from specified records-file [{0}] because [{1}]z6Nothing to do, all the records in [{0}] already exist.)changer(   r'   managedZones)parentchangeIdzdns.changes)liner&   r%   z8Imported record-sets from [{0}] into managed-zone [{1}].)7r	   GetApiFromTrackAndArgsReleaseTrackospathexistsr   r   RecordsFileNotFoundformatisdirRecordsFileIsADirectoryGetApiClientGetRegistryParsezoneGetParamsForRegistryMESSAGES_MODULEDnsManagedZonesGetRequestr'   r(   locationr/   Getapitools_exceptions	HttpErrorcalliope_exceptionsHttpException DnsResourceRecordSetsListRequestNamer   YieldFromListresourceRecordSetsnametyper   
FileReaderzone_file_formatRecordSetsFromZoneFilednsNameRecordSetsFromYamlFile	ExceptionmessageUnableToReadRecordsFileComputeChangedelete_all_existingreplace_origin_nsr   statusPrintDnsChangesCreateRequestchangesCreateidCreatedResource)selfargsr,   dnszone_refget_requestr?   errorcurrentlist_requestrecordimport_fileimportedexpmsgr.   create_requestresultparam
change_refs                       r    Run
Import.Runa   s   --d.?.?.A4HK77>>$++,,++
2
9
9$:K:K
LN N	ww}}T&&''//
6
=
=!" " 

K
(C ,22		((;% 3 'H
	5''AA""0D0D B Fk 
	#}}!!+.d
 G&&GG  hmmo H ?L d"mml**H>,2v{{FKK()>
5D--.+   77<<[B( !77'+%'( /  &&  !F DKK


c	jjs ((@@99h6F6F A HN d $n[[/F%%kOE		E*!!+.44  5 J E
K
K8==?,CJJS
#MA (( 5--e445" /.  5cJJt((#++6c//44	5sP   :A P ' Q AQQ Q	.QQ	
QQ Q 
R+(>R&&R+ N)	__name__
__module____qualname____firstlineno____doc__classmethodr!   rr   __static_attributes__rt   r#   r    r   r   #   s!    
6 8 8:[r#   r   )ry   
__future__r   r   r   r5   apitools.base.pyr   rE   r   googlecloudsdk.api_lib.dnsr   r	   googlecloudsdk.callioper
   rG   googlecloudsdk.command_lib.dnsr   googlecloudsdk.corer   googlecloudsdk.core.utilr   UnicodeIsSupportedUniverseCompatibleReleaseTracksr4   GABETAALPHACommandr   rt   r#   r    <module>r      s     - &  ' 	 > ' 2 + ( E 0 # * D%%(($*;*;*@*@%%++-UT\\ U-  Ur#   