
    "                         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 ddlmZ ddlmZ ddlmZ ddlmZ  G d dej0                        Zy)z1gcloud dns record-sets transaction start command.    )absolute_import)division)unicode_literalsN)
exceptions)
list_pager)import_util)transaction_util)util)base)flags)log)
properties)filesc                   &    e Zd ZdZed        Zd Zy)StartzStart a transaction.

  This command starts a transaction.

  ## EXAMPLES

  To start a transaction, run:

    $ {command} --zone=MANAGED_ZONE
  c                 J    t        j                         j                  |        y )N)r   
GetZoneArgAddToParser)parsers    0lib/surface/dns/record_sets/transaction/start.pyArgsz
Start.Args2   s    	""6*    c           	         d}| j                         t        j                   j                  k(  rd}n-| j                         t        j                   j                  k(  rd}t        j
                  j                  |j                        r.t        j                  dj                  |j                              t        j                  |      }t        j                  |      j                  |j                  dt         j"                  j$                  j&                  j(                  id      }	 |j*                  j-                  |j.                  j1                  |j&                  |j2                              }|j.                  j=                         }t?        j@                  |jB                  |j.                  jE                  |j&                  |jG                         |jH                  d	
      d      D cg c]  }| }	}|jJ                  jM                  |	d          |jN                  jM                  tQ        jR                  |	d   |             	 tU        jV                  |j                        5 }
t        jX                  |
|       d d d        t^        j`                  jc                  dj                  |j                               y # t4        j6                  $ r}t9        j:                  |      d }~ww xY wc c}w # 1 sw Y   wxY w# tZ        $ r8}d}|j                  |j                  |      }t        j\                  |      d }~ww xY w)Nv1v1beta2v1alpha2z#Transaction already exists at [{0}]projectzdns.managedZones)params
collection)r   managedZoneSOA)r   r    nametyperrsets)fieldr   )api_versionz/Unable to write transaction [{0}] because [{1}]zTransaction started [{0}].)2ReleaseTrackr   BETAALPHAospathisfiletransaction_filer	   TransactionFileAlreadyExistsformatr
   GetApiClientGetRegistryParsezoner   VALUEScorer   	GetOrFailmanagedZonesGetMESSAGES_MODULEDnsManagedZonesGetRequestr    apitools_exceptions	HttpErrorcalliope_exceptionsHttpExceptionChanger   YieldFromListresourceRecordSets DnsResourceRecordSetsListRequestNamednsName	deletionsappend	additionsr   NextSOARecordSetr   
FileWriterWriteToYamlFile	ExceptionUnableToAccessTransactionFiler   statusPrint)selfargsr&   dnszone_refr3   errorchangerecordrecordsr-   expmsgs                r   Runz	Start.Run6   s   K d//444k				 1 1 7 7	7k	ww~~d++,99
/
6
6t7L7L
MO O 

K
(C ,22		z((--55??
 & 3 'H5!!



7
7&&".. 8 01d   '')F %/$<$<<<$$ 	 	= 	
 %  %&v %G  GAJ'
$$WQZ[IK@D1126F(()96B 3 JJ188  ; (( 5--e445 32 @=cJJt,,c2c::3??@sO   *A
K 1	K5L -K:L K2K--K2:L?L 	M3MMN)__name__
__module____qualname____doc__staticmethodr   rY    r   r   r   r   &   s     	 + +: r   r   )r]   
__future__r   r   r   r*   apitools.base.pyr   r;   r   googlecloudsdk.api_lib.dnsr   r	   r
   googlecloudsdk.callioper   r=   googlecloudsdk.command_lib.dnsr   googlecloudsdk.corer   r   googlecloudsdk.core.utilr   Commandr   r_   r   r   <module>rh      sI     8 &  ' 	 > ' 2 7 + ( E 0 # * *J DLL J r   