o ckF[5@sdZddlmZddlmZddlmZddlmZGddde Z Gdd d eZ Gd d d e Z Gd d d e ZGddde ZdS)z- Represents an EC2 Elastic Network Interface )BotoClientError)TaggedEC2Object) ResultSet)Groupc@s0eZdZdZddZddZddZdd Zd S) Attachmenta` :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. cCs.d|_d|_d|_d|_d|_d|_d|_dS)NrF)id instance_idinstance_owner_id device_indexstatus attach_timedelete_on_terminationselfr;/usr/lib/python3/dist-packages/boto/ec2/networkinterface.py__init__+s zAttachment.__init__cC d|jS)Nz Attachment:%srrrrr__repr__4 zAttachment.__repr__cCdSNrrnameattrs connectionrrr startElement7zAttachment.startElementcCs|dkr ||_dS|dkr||_dS|dkrt||_dS|dkr&||_dS|dkr/||_dS|dkr8||_dS|dkrL|dkrGd |_dSd |_dSt |||dS) N attachmentId instanceId deviceIndexinstanceOwnerIdr attachTimedeleteOnTerminationtrueTF) rrintr r r r lowerr setattrrrvaluerrrr endElement:s"        zAttachment.endElementN)__name__ __module__ __qualname____doc__rrrr+rrrrr s    rcsneZdZdZdfdd ZddZfddZd d Zd d ZdddZ dddZ dddZ dddZ Z S)NetworkInterfacea 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. Ncshtt||d|_d|_d|_d|_d|_d|_d|_ d|_ d|_ d|_ d|_ g|_d|_g|_dS)NF)superr0rr subnet_idvpc_idavailability_zone descriptionowner_idrequester_managedr mac_addressprivate_ip_addresssource_dest_checkgroups attachmentprivate_ip_addresses)rr __class__rrres zNetworkInterface.__init__cCr)NzNetworkInterface:%srrrrrrvrzNetworkInterface.__repr__csvtt||||}|dur|S|dkrtdtfg|_|jS|dkr*t|_|jS|dkr9tdtfg|_ |j SdS)NgroupSetitemr<privateIpAddressesSet) r1r0rrrr;rr<PrivateIPAddressr=)rrrrretvalr>rrryszNetworkInterface.startElementcCs|dkr ||_dS|dkr||_dS|dkr||_dS|dkr$||_dS|dkr-||_dS|dkr6||_dS|dkrJ|dkrEd |_dSd |_dS|d krS||_dS|d kr\||_ dS|d kre||_ dS|dkry|dkrtd |_ dSd |_ dSt |||dS)NnetworkInterfaceIdsubnetIdvpcIdavailabilityZoner5ownerIdrequesterManagedr%TFr macAddressprivateIpAddresssourceDestCheck) rr2r3r4r5r6r'r7r r8r9r:r(r)rrrr+s6               zNetworkInterface.endElementcCs|j|jdSr)__dict__update)rupdatedrrr_updateszNetworkInterface._updateFcCsL|jj|jg|d}t|dkr||d|jS|r#td|j|jS)a 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. dry_runrz%s is not a valid ENI ID)rget_all_network_interfacesrlenrQ ValueErrorr )rvalidaterSrsrrrrOs  zNetworkInterface.updatecCs|jj|j|||dS)ar 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 rR)rattach_network_interfacer)rrr rSrrrattachs zNetworkInterface.attachcCs t|jdd}|jj|||dS)a 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 rNrR)getattrr<rdetach_network_interface)rforcerS attachment_idrrrdetachs  zNetworkInterface.detachcCs|jj|j|dS)NrR)rdelete_network_interfacer)rrSrrrdeleteszNetworkInterface.deleter)FF)F)r,r-r.r/rrrr+rQrOrZr_ra __classcell__rrr>rr0Ps    r0c@s2eZdZ  d ddZddZddZdd ZdS) rCNcCs||_||_||_dSr)rr9primary)rrr9rcrrrrs zPrivateIPAddress.__init__cCrrrrrrrrrzPrivateIPAddress.startElementcCs8|dkr ||_dS|dkr|dkrdnd|_dSdS)NrLrcr%TF)r9r'rcr)rrrr+s  zPrivateIPAddress.endElementcCsd|j|jfS)Nz PrivateIPAddress(%s, primary=%s))r9rcrrrrrszPrivateIPAddress.__repr__)NNN)r,r-r.rrr+rrrrrrCs  rCc@seZdZddZdddZdS)NetworkInterfaceCollectioncGs||dSr)extend)r interfacesrrrrsz#NetworkInterfaceCollection.__init__c Cst|D]\}}d||f}|jdurt|j||d<|jdur+t|j||d<nd||d<|jdur?t|j||d<|jdurMt|j||d<|jdur]|jrWdnd||d <|jdurkt|j||d <|jduryt|j||d <|j durt|j D]\}}d ||f}t|||<q|j durt|j D]#\} } d || f} t| j|| d<| j dur| j rdnd|| d<q|j dur||ddvrt dt|dkrt d|d} |j rd|| <qd|| <qdS)Nz%sNetworkInterface.%s.NetworkInterfaceId DeviceIndexrSubnetId Descriptionr%falseDeleteOnTerminationSecondaryPrivateIpAddressCountPrivateIpAddressz%sSecurityGroupId.%sz%sPrivateIpAddresses.%sz.PrivateIpAddressz.Primary)r0zcOnly the interface with device index of 0 can be provided when using 'associate_public_ip_address'.zLOnly one interface can be provided when using 'associate_public_ip_address'.AssociatePublicIpAddress) enumeratenetwork_interface_idstrr r2r5r "secondary_private_ip_address_countr9r;r=rcassociate_public_ip_addressrrU) rparamsprefixispec full_prefixjgroup_idquery_param_keykip_addrquery_param_key_prefixkeyrrrbuild_list_params sf                    z,NetworkInterfaceCollection.build_list_paramsN)rg)r,r-r.rrrrrrrdsrdc@s"eZdZ      dddZdS)NetworkInterfaceSpecificationNc Cs@||_||_||_||_||_||_||_||_| |_| |_ dSr) rtr r2r5r9r;r r=rvrw) rrtr r2r5r9r;r r=rvrwrrrrOs z&NetworkInterfaceSpecification.__init__) NNNNNNNNNN)r,r-r.rrrrrrNsrN)r/boto.exceptionrboto.ec2.ec2objectrboto.resultsetrboto.ec2.grouprobjectrr0rClistrdrrrrrs    0!I