ó
è?F[c           @   s¸   d  Z  d d l m Z d d l m Z d d l m Z d d l m Z d e	 f d „  ƒ  YZ
 d e f d	 „  ƒ  YZ d
 e	 f d „  ƒ  YZ d e f d „  ƒ  YZ d e	 f d „  ƒ  YZ d S(   s-   
Represents an EC2 Elastic Network Interface
iÿÿÿÿ(   t   BotoClientError(   t   TaggedEC2Object(   t	   ResultSet(   t   Groupt
   Attachmentc           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s`  
    :ivar id: The ID of the attachment.
    :ivar instance_id: The ID of the instance.
    :ivar device_index: The index of this device.
    :ivar status: The status of the device.
    :ivar attach_time: The time the device was attached.
    :ivar delete_on_termination: Whether the device will be deleted
        when the instance is terminated.
    c         C   sC   d  |  _ d  |  _ d  |  _ d |  _ d  |  _ d  |  _ t |  _ d  S(   Ni    (	   t   Nonet   idt   instance_idt   instance_owner_idt   device_indext   statust   attach_timet   Falset   delete_on_termination(   t   self(    (    s8   lib/python2.7/site-packages/boto/ec2/networkinterface.pyt   __init__+   s    						c         C   s   d |  j  S(   Ns   Attachment:%s(   R   (   R   (    (    s8   lib/python2.7/site-packages/boto/ec2/networkinterface.pyt   __repr__4   s    c         C   s   d  S(   N(   R   (   R   t   namet   attrst
   connection(    (    s8   lib/python2.7/site-packages/boto/ec2/networkinterface.pyt   startElement7   s    c         C   sà   | d k r | |  _  nÄ | d k r0 | |  _ n¬ | d k rN t | ƒ |  _ nŽ | d k rf | |  _ nv | d k r~ | |  _ n^ | d k r– | |  _ nF | d k rÌ | j ƒ  d k rÀ t |  _	 qÜ t
 |  _	 n t |  | | ƒ d  S(	   Nt   attachmentIdt
   instanceIdt   deviceIndext   instanceOwnerIdR
   t
   attachTimet   deleteOnTerminationt   true(   R   R   t   intR	   R   R
   R   t   lowert   TrueR   R   t   setattr(   R   R   t   valueR   (    (    s8   lib/python2.7/site-packages/boto/ec2/networkinterface.pyt
   endElement:   s"    (   t   __name__t
   __module__t   __doc__R   R   R   R!   (    (    (    s8   lib/python2.7/site-packages/boto/ec2/networkinterface.pyR       s
   					t   NetworkInterfacec           B   st   e  Z d  Z d
 d „ Z d „  Z d „  Z d „  Z d „  Z e	 e	 d „ Z
 e	 d „ Z e	 e	 d „ Z e	 d	 „ Z RS(   s  
    An Elastic Network Interface.

    :ivar id: The ID of the ENI.
    :ivar subnet_id: The ID of the VPC subnet.
    :ivar vpc_id: The ID of the VPC.
    :ivar description: The description.
    :ivar owner_id: The ID of the owner of the ENI.
    :ivar requester_managed:
    :ivar status: The interface's status (available|in-use).
    :ivar mac_address: The MAC address of the interface.
    :ivar private_ip_address: The IP address of the interface within
        the subnet.
    :ivar source_dest_check: Flag to indicate whether to validate
        network traffic to or from this network interface.
    :ivar groups: List of security groups associated with the interface.
    :ivar attachment: The attachment object.
    :ivar private_ip_addresses: A list of PrivateIPAddress objects.
    c         C   s˜   t  t |  ƒ j | ƒ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _	 t
 |  _ d  |  _ d  |  _ d  |  _ d  |  _ g  |  _ d  |  _ g  |  _ d  S(   N(   t   superR%   R   R   R   t	   subnet_idt   vpc_idt   availability_zonet   descriptiont   owner_idR   t   requester_managedR
   t   mac_addresst   private_ip_addresst   source_dest_checkt   groupst
   attachmentt   private_ip_addresses(   R   R   (    (    s8   lib/python2.7/site-packages/boto/ec2/networkinterface.pyR   e   s    													c         C   s   d |  j  S(   Ns   NetworkInterface:%s(   R   (   R   (    (    s8   lib/python2.7/site-packages/boto/ec2/networkinterface.pyR   v   s    c         C   s«   t  t |  ƒ j | | | ƒ } | d  k	 r. | S| d k rY t d t f g ƒ |  _ |  j S| d k rx t ƒ  |  _ |  j S| d k r£ t d t	 f g ƒ |  _
 |  j
 Sd  Sd  S(   Nt   groupSett   itemR1   t   privateIpAddressesSet(   R&   R%   R   R   R   R   R0   R   R1   t   PrivateIPAddressR2   (   R   R   R   R   t   retval(    (    s8   lib/python2.7/site-packages/boto/ec2/networkinterface.pyR   y   s    c         C   sX  | d k r | |  _  n<| d k r0 | |  _ n$| d k rH | |  _ n| d k r` | |  _ nô | d k rx | |  _ nÜ | d k r | |  _ nÄ | d k rÆ | j ƒ  d k rº t |  _ qTt	 |  _ nŽ | d	 k rÞ | |  _
 nv | d
 k rö | |  _ n^ | d k r| |  _ nF | d k rD| j ƒ  d k r8t |  _ qTt	 |  _ n t |  | | ƒ d  S(   Nt   networkInterfaceIdt   subnetIdt   vpcIdt   availabilityZoneR*   t   ownerIdt   requesterManagedR   R
   t
   macAddresst   privateIpAddresst   sourceDestCheck(   R   R'   R(   R)   R*   R+   R   R   R,   R   R
   R-   R.   R/   R   (   R   R   R    R   (    (    s8   lib/python2.7/site-packages/boto/ec2/networkinterface.pyR!   ‰   s6    c         C   s   |  j  j | j  ƒ d  S(   N(   t   __dict__t   update(   R   t   updated(    (    s8   lib/python2.7/site-packages/boto/ec2/networkinterface.pyt   _update©   s    c         C   sg   |  j  j |  j g d | ƒ} t | ƒ d k rD |  j | d ƒ n | r` t d |  j ƒ ‚ n  |  j S(   s©  
        Update the data associated with this ENI by querying EC2.

        :type validate: bool
        :param validate: By default, if EC2 returns no data about the
                         ENI the update method returns quietly.  If
                         the validate param is True, however, it will
                         raise a ValueError exception if no data is
                         returned from EC2.
        t   dry_runi    s   %s is not a valid ENI ID(   R   t   get_all_network_interfacesR   t   lenRD   t
   ValueErrorR
   (   R   t   validateRE   t   rs(    (    s8   lib/python2.7/site-packages/boto/ec2/networkinterface.pyRB   ¬   s    		c         C   s   |  j  j |  j | | d | ƒS(   sr  
        Attach this ENI to an EC2 instance.

        :type instance_id: str
        :param instance_id: The ID of the EC2 instance to which it will
                            be attached.

        :type device_index: int
        :param device_index: The interface nunber, N, on the instance (eg. ethN)

        :rtype: bool
        :return: True if successful
        RE   (   R   t   attach_network_interfaceR   (   R   R   R	   RE   (    (    s8   lib/python2.7/site-packages/boto/ec2/networkinterface.pyt   attachÁ   s
    	c         C   s.   t  |  j d d ƒ } |  j j | | d | ƒS(   s  
        Detach this ENI from an EC2 instance.

        :type force: bool
        :param force: Forces detachment if the previous detachment
                      attempt did not occur cleanly.

        :rtype: bool
        :return: True if successful
        R   RE   N(   t   getattrR1   R   R   t   detach_network_interface(   R   t   forceRE   t   attachment_id(    (    s8   lib/python2.7/site-packages/boto/ec2/networkinterface.pyt   detachÖ   s
    	c         C   s   |  j  j |  j d | ƒS(   NRE   (   R   t   delete_network_interfaceR   (   R   RE   (    (    s8   lib/python2.7/site-packages/boto/ec2/networkinterface.pyt   deleteé   s    		N(   R"   R#   R$   R   R   R   R   R!   RD   R   RB   RL   RQ   RS   (    (    (    s8   lib/python2.7/site-packages/boto/ec2/networkinterface.pyR%   P   s   			 	R6   c           B   s5   e  Z d d d d  „ Z d „  Z d „  Z d „  Z RS(   c         C   s   | |  _  | |  _ | |  _ d  S(   N(   R   R.   t   primary(   R   R   R.   RT   (    (    s8   lib/python2.7/site-packages/boto/ec2/networkinterface.pyR   ñ   s    		c         C   s   d  S(   N(    (   R   R   R   R   (    (    s8   lib/python2.7/site-packages/boto/ec2/networkinterface.pyR   ÷   s    c         C   sL   | d k r | |  _  n0 | d k rH | j ƒ  d k r< t n t |  _ n  d  S(   NR?   RT   R   (   R.   R   R   R   RT   (   R   R   R    R   (    (    s8   lib/python2.7/site-packages/boto/ec2/networkinterface.pyR!   ú   s    c         C   s   d |  j  |  j f S(   Ns    PrivateIPAddress(%s, primary=%s)(   R.   RT   (   R   (    (    s8   lib/python2.7/site-packages/boto/ec2/networkinterface.pyR      s    	N(   R"   R#   R   R   R   R!   R   (    (    (    s8   lib/python2.7/site-packages/boto/ec2/networkinterface.pyR6   ð   s
   		t   NetworkInterfaceCollectionc           B   s   e  Z d  „  Z d d „ Z RS(   c         G   s   |  j  | ƒ d  S(   N(   t   extend(   R   t
   interfaces(    (    s8   lib/python2.7/site-packages/boto/ec2/networkinterface.pyR     s    t    c         C   sÊ  xÃt  |  ƒ D]µ\ } } d | | f } | j d  k	 rR t | j ƒ | | d <n  | j d  k	 r{ t | j ƒ | | d <n d | | d <| j d  k	 r² t | j ƒ | | d <n  | j d  k	 rÛ t | j ƒ | | d <n  | j d  k	 r
| j rù d n d | | d	 <n  | j d  k	 r3t | j ƒ | | d
 <n  | j	 d  k	 r\t | j	 ƒ | | d <n  | j
 d  k	 r®x@ t  | j
 ƒ D], \ } } d | | f } t | ƒ | | <q{Wn  | j d  k	 r6xv t  | j ƒ D]b \ }	 }
 d | |	 f } t |
 j	 ƒ | | d <|
 j d  k	 rÍ|
 j rd n d | | d <qÍqÍWn  | j d  k	 r | | d d k rpt d d d ƒ ‚ n  t |  ƒ d k r•t d d ƒ ‚ n  | d } | j rµd | | <qÂd | | <q q Wd  S(   Ns   %sNetworkInterface.%s.t   NetworkInterfaceIdt   DeviceIndexi    t   SubnetIdt   DescriptionR   t   falset   DeleteOnTerminationt   SecondaryPrivateIpAddressCountt   PrivateIpAddresss   %sSecurityGroupId.%ss   %sPrivateIpAddresses.%ss   .PrivateIpAddresss   .Primaryt   0s.   Only the interface with device index of 0 can s   be provided when using s   'associate_public_ip_address'.i   s.   Only one interface can be provided when using t   AssociatePublicIpAddress(   i    Ra   (   t	   enumeratet   network_interface_idR   t   strR	   R'   R*   R   t"   secondary_private_ip_address_countR.   R0   R2   RT   t   associate_public_ip_addressR    RG   (   R   t   paramst   prefixt   it   spect   full_prefixt   jt   group_idt   query_param_keyt   kt   ip_addrt   query_param_key_prefixt   key(    (    s8   lib/python2.7/site-packages/boto/ec2/networkinterface.pyt   build_list_params	  sP     '
	(   R"   R#   R   Rt   (    (    (    s8   lib/python2.7/site-packages/boto/ec2/networkinterface.pyRU     s   	t   NetworkInterfaceSpecificationc           B   s/   e  Z d d d d d d d d d d d  „
 Z RS(   c         C   s^   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ |	 |  _ |
 |  _	 d  S(   N(
   Rd   R	   R'   R*   R.   R0   R   R2   Rf   Rg   (   R   Rd   R	   R'   R*   R.   R0   R   R2   Rf   Rg   (    (    s8   lib/python2.7/site-packages/boto/ec2/networkinterface.pyR   O  s    									N(   R"   R#   R   R   (    (    (    s8   lib/python2.7/site-packages/boto/ec2/networkinterface.pyRu   N  s   	N(   R$   t   boto.exceptionR    t   boto.ec2.ec2objectR   t   boto.resultsetR   t   boto.ec2.groupR   t   objectR   R%   R6   t   listRU   Ru   (    (    (    s8   lib/python2.7/site-packages/boto/ec2/networkinterface.pyt   <module>   s   0 I