ó
è?F[c           @   s\   d  Z  d d l Z d d l m Z d d l m Z d d l m Z d e f d „  ƒ  YZ	 d S(   i<   iÿÿÿÿN(   t   TooManyRecordsException(   t   ResourceRecordSets(   t   Statust   Zonec           B   sO  e  Z d  Z d „  Z d „  Z d „  Z d d „ Z d d d d „ Z d d d d „ Z	 d d	 „ Z
 d d d d
 „ Z d d d d „ Z d d d d „ Z d e d d „ Z e d „ Z e d „ Z e d „ Z d d d d „ Z d d d d „ Z d d d d „ Z d e d „ Z d e d „ Z d e d „ Z d „  Z d „  Z d „  Z RS(   sŸ   
    A Route53 Zone.

    :ivar route53connection: A :class:`boto.route53.connection.Route53Connection` connection
    :ivar id: The ID of the hosted zone
    c         C   s`   | |  _  xP | D]H } | d k r> | d j d d ƒ |  _ q |  j | j ƒ  | | ƒ q Wd  S(   Nt   Ids   /hostedzone/t    (   t   route53connectiont   replacet   idt   __setattr__t   lower(   t   selfR   t	   zone_dictt   key(    (    s0   lib/python2.7/site-packages/boto/route53/zone.pyt   __init__(   s
    	c         C   s   d |  j  S(   Ns	   <Zone:%s>(   t   name(   R   (    (    s0   lib/python2.7/site-packages/boto/route53/zone.pyt   __repr__0   s    c         C   s   | j  ƒ  } | d d S(   s¿   
        Commit a set of changes and return the ChangeInfo portion of
        the response.

        :type changes: ResourceRecordSets
        :param changes: changes to be committed
        t    ChangeResourceRecordSetsResponset
   ChangeInfo(   t   commit(   R   t   changest   response(    (    s0   lib/python2.7/site-packages/boto/route53/zone.pyt   _commit3   s    R   c         C   sÖ   d } d }	 | d k	 r_ y& t | d ƒ | d } | d } Wq_ | d }	 | d } q_ Xn  | j d | | | d | d | d |	 ƒ}
 t | ƒ t t t g k rÅ x+ | D] } |
 j | ƒ q« Wn |
 j | ƒ d S(   sw  
        Add a CREATE change record to an existing ResourceRecordSets

        :type changes: ResourceRecordSets
        :param changes: change set to append to

        :type name: str
        :param name: The name of the resource record you want to
            perform the action on.

        :type resource_type: str
        :param resource_type: The DNS record type

        :param value: Appropriate value for resource_type

        :type ttl: int
        :param ttl: The resource record cache time to live (TTL), in seconds.

        :type identifier: tuple
        :param identifier: A tuple for setting WRR or LBR attributes.  Valid
           forms are:

           * (str, int): WRR record [e.g. ('foo',10)]
           * (str, str): LBR record [e.g. ('foo','us-east-1')

        :type comment: str
        :param comment: A comment that will be stored with the change.
        i   i    t   CREATEt
   identifiert   weightt   regionN(   t   Nonet   intt
   add_changet   typet   listt   tuplet   sett	   add_value(   R   R   t   resource_typeR   t   valuet   ttlR   t   commentR   R   t   changet   record(    (    s0   lib/python2.7/site-packages/boto/route53/zone.pyt   _new_record>   s"    

	i<   c         C   sP   t  |  j |  j | ƒ } |  j | | | | | | | ƒ t |  j |  j | ƒ ƒ S(   s€   
        Add a new record to this Zone.  See _new_record for parameter
        documentation.  Returns a Status object.
        (   R   R   R   R)   R   R   (   R   R#   R   R$   R%   R   R&   R   (    (    s0   lib/python2.7/site-packages/boto/route53/zone.pyt
   add_recordo   s    c         C   s   | p	 t  } t j | ƒ } t |  j |  j | ƒ } | j d | ƒ |  j | | j | j | | | | ƒ t	 |  j |  j
 | ƒ ƒ S(   s
  
        Update an existing record in this Zone.  Returns a Status object.

        :type old_record: ResourceRecord
        :param old_record: A ResourceRecord (e.g. returned by find_records)

        See _new_record for additional parameter documentation.
        t   DELETE(   t   default_ttlt   copyR   R   R   t   add_change_recordR)   R   R   R   R   (   R   t
   old_recordt	   new_valuet   new_ttlt   new_identifierR&   R(   R   (    (    s0   lib/python2.7/site-packages/boto/route53/zone.pyt   update_recordz   s    
c         C   s€   t  |  j |  j | ƒ } t | ƒ t t t g k rW x1 | D] } | j d | ƒ q: Wn | j d | ƒ t |  j |  j	 | ƒ ƒ S(   s8  
        Delete one or more records from this Zone.  Returns a Status object.

        :param record: A ResourceRecord (e.g. returned by
           find_records) or list, tuple, or set of ResourceRecords.

        :type comment: str
        :param comment: A comment that will be stored with the change.
        R+   (
   R   R   R   R   R   R    R!   R.   R   R   (   R   R(   R&   R   t   r(    (    s0   lib/python2.7/site-packages/boto/route53/zone.pyt   delete_recordŒ   s    
c         C   s^   | p	 t  } |  j j | ƒ } |  j j | ƒ } |  j d d d | d | d | d | d | ƒ S(   s†   
        Add a new CNAME record to this Zone.  See _new_record for
        parameter documentation.  Returns a Status object.
        R#   t   CNAMER   R$   R%   R   R&   (   R,   R   t   _make_qualifiedR*   (   R   R   R$   R%   R   R&   (    (    s0   lib/python2.7/site-packages/boto/route53/zone.pyt	   add_cnamež   s    c         C   sL   | p	 t  } |  j j | ƒ } |  j d d d | d | d | d | d | ƒ S(   s‚   
        Add a new A record to this Zone.  See _new_record for
        parameter documentation.  Returns a Status object.
        R#   t   AR   R$   R%   R   R&   (   R,   R   R7   R*   (   R   R   R$   R%   R   R&   (    (    s0   lib/python2.7/site-packages/boto/route53/zone.pyt   add_a­   s    c         C   sL   | p	 t  } |  j j | ƒ } |  j d d d | d | d | d | d | ƒ S(   sƒ   
        Add a new MX record to this Zone.  See _new_record for
        parameter documentation.  Returns a Status object.
        R#   t   MXR   R$   R%   R   R&   (   R,   R   R7   R*   (   R   R   t   recordsR%   R   R&   (    (    s0   lib/python2.7/site-packages/boto/route53/zone.pyt   add_mx»   s    i   c         C   s  |  j  j | ƒ } |  j  j |  j d | d | ƒ} g  } x= | D]5 } | j | k rt | j | k rt | j | ƒ q@ Pq@ Wd	 }	 d	 }
 | d	 k	 rÄ y t | d ƒ | d }	 WqÄ | d }
 qÄ Xn  |	 d	 k	 rg  | D]. } | j	 |	 k r× | j
 | d k r× | ^ q× } n  |
 d	 k	 rXg  | D]. } | j |
 k r!| j
 | d k r!| ^ q!} n  | rÙt | ƒ | k rÙd | | f } | d 7} | d j g  | D]% } d | j | j | j ƒ  f ^ q›ƒ 7} t | ƒ ‚ n4 t | ƒ d k rï| St | ƒ d k r	| d Sd	 Sd	 S(
   sæ  
        Search this Zone for records that match given parameters.
        Returns None if no results, a ResourceRecord if one result, or
        a ResourceRecordSets if more than one result.

        :type name: str
        :param name: The name of the records should match this parameter

        :type type: str
        :param type: The type of the records should match this parameter

        :type desired: int
        :param desired: The number of desired results.  If the number of
           matching records in the Zone exceeds the value of this parameter,
           throw TooManyRecordsException

        :type all: Boolean
        :param all: If true return all records that match name, type, and
          identifier parameters

        :type identifier: Tuple
        :param identifier: A tuple specifying WRR or LBR attributes.  Valid
           forms are:

           * (str, int): WRR record [e.g. ('foo',10)]
           * (str, str): LBR record [e.g. ('foo','us-east-1')

        R   R   i   i    s   Search: name %s type %ss   
Found: s   , s   %s %s %sN(   R   R7   t   get_all_rrsetsR   R   R   t   appendR   R   R   R   R   t   lent   joint   to_printR    (   R   R   R   t   desiredt   allR   t   returnedt   resultsR4   R   R   t   message(    (    s0   lib/python2.7/site-packages/boto/route53/zone.pyt   find_recordsÉ   sB    	""
3c         C   s   |  j  | d d | ƒS(   sþ   
        Search this Zone for CNAME records that match name.

        Returns a ResourceRecord.

        If there is more than one match return all as a
        ResourceRecordSets if all is True, otherwise throws
        TooManyRecordsException.
        R6   RD   (   RH   (   R   R   RD   (    (    s0   lib/python2.7/site-packages/boto/route53/zone.pyt	   get_cname  s    
c         C   s   |  j  | d d | ƒS(   sú   
        Search this Zone for A records that match name.

        Returns a ResourceRecord.

        If there is more than one match return all as a
        ResourceRecordSets if all is True, otherwise throws
        TooManyRecordsException.
        R9   RD   (   RH   (   R   R   RD   (    (    s0   lib/python2.7/site-packages/boto/route53/zone.pyt   get_a  s    
c         C   s   |  j  | d d | ƒS(   sû   
        Search this Zone for MX records that match name.

        Returns a ResourceRecord.

        If there is more than one match return all as a
        ResourceRecordSets if all is True, otherwise throws
        TooManyRecordsException.
        R;   RD   (   RH   (   R   R   RD   (    (    s0   lib/python2.7/site-packages/boto/route53/zone.pyt   get_mx*  s    
c      
   C   sg   |  j  j | ƒ } |  j  j | ƒ } |  j | ƒ } | p? | j } |  j | d | d | d | d | ƒS(   sæ   
        Update the given CNAME record in this Zone to a new value, ttl,
        and identifier.  Returns a Status object.

        Will throw TooManyRecordsException is name, value does not match
        a single record.
        R0   R1   R2   R&   (   R   R7   RI   R%   R3   (   R   R   R$   R%   R   R&   R/   (    (    s0   lib/python2.7/site-packages/boto/route53/zone.pyt   update_cname6  s    c      
   C   sU   |  j  j | ƒ } |  j | ƒ } | p- | j } |  j | d | d | d | d | ƒS(   sâ   
        Update the given A record in this Zone to a new value, ttl,
        and identifier.  Returns a Status object.

        Will throw TooManyRecordsException is name, value does not match
        a single record.
        R0   R1   R2   R&   (   R   R7   RJ   R%   R3   (   R   R   R$   R%   R   R&   R/   (    (    s0   lib/python2.7/site-packages/boto/route53/zone.pyt   update_aH  s    c      
   C   sg   |  j  j | ƒ } |  j  j | ƒ } |  j | ƒ } | p? | j } |  j | d | d | d | d | ƒS(   sã   
        Update the given MX record in this Zone to a new value, ttl,
        and identifier.  Returns a Status object.

        Will throw TooManyRecordsException is name, value does not match
        a single record.
        R0   R1   R2   R&   (   R   R7   RK   R%   R3   (   R   R   R$   R%   R   R&   R/   (    (    s0   lib/python2.7/site-packages/boto/route53/zone.pyt	   update_mxY  s    c         C   s=   |  j  j | ƒ } |  j | d d | d | ƒ} |  j | ƒ S(   sý   
        Delete a CNAME record matching name and identifier from
        this Zone.  Returns a Status object.

        If there is more than one match delete all matching records if
        all is True, otherwise throws TooManyRecordsException.
        R6   R   RD   (   R   R7   RH   R5   (   R   R   R   RD   R(   (    (    s0   lib/python2.7/site-packages/boto/route53/zone.pyt   delete_cnamek  s    	c         C   s=   |  j  j | ƒ } |  j | d d | d | ƒ} |  j | ƒ S(   sú   
        Delete an A record matching name and identifier from this
        Zone.  Returns a Status object.

        If there is more than one match delete all matching records if
        all is True, otherwise throws TooManyRecordsException.
        R9   R   RD   (   R   R7   RH   R5   (   R   R   R   RD   R(   (    (    s0   lib/python2.7/site-packages/boto/route53/zone.pyt   delete_ax  s    	c         C   s=   |  j  j | ƒ } |  j | d d | d | ƒ} |  j | ƒ S(   sû   
        Delete an MX record matching name and identifier from this
        Zone.  Returns a Status object.

        If there is more than one match delete all matching records if
        all is True, otherwise throws TooManyRecordsException.
        R;   R   RD   (   R   R7   RH   R5   (   R   R   R   RD   R(   (    (    s0   lib/python2.7/site-packages/boto/route53/zone.pyt	   delete_mx…  s    	c         C   s   |  j  j |  j ƒ S(   sS   
        Return a ResourceRecordsSets for all of the records in this zone.
        (   R   R>   R   (   R   (    (    s0   lib/python2.7/site-packages/boto/route53/zone.pyt   get_records’  s    c         C   s   |  j  j |  j ƒ d S(   s>   
        Request that this zone be deleted by Amazon.
        N(   R   t   delete_hosted_zoneR   (   R   (    (    s0   lib/python2.7/site-packages/boto/route53/zone.pyt   delete˜  s    c         C   s1   |  j  |  j d ƒ } | d k	 r- | j } n  | S(   s+    Get the list of nameservers for this zone.t   NSN(   RH   R   R   t   resource_records(   R   t   ns(    (    s0   lib/python2.7/site-packages/boto/route53/zone.pyt   get_nameserversž  s    N(   t   __name__t
   __module__t   __doc__R   R   R   R)   R   R*   R3   R5   R8   R:   R=   t   FalseRH   RI   RJ   RK   RL   RM   RN   RO   RP   RQ   RR   RT   RX   (    (    (    s0   lib/python2.7/site-packages/boto/route53/zone.pyR   !   s4   			0
I		(
   R,   R-   t   boto.exceptionR    t   boto.route53.recordR   t   boto.route53.statusR   t   objectR   (    (    (    s0   lib/python2.7/site-packages/boto/route53/zone.pyt   <module>   s
   