def get_eni_id(self, interface=1):
        """Given an interface number, gets the AWS elastic network
        interface associated with the interface.

        :param interface: Integer associated to the interface/device number
        :return: String Elastic Network Interface ID or None if not found
        :raises OSError, AWSAPIError, EC2UtilError
        """
        log = logging.getLogger(self.cls_logger + '.get_eni_id')

        # Get the instance-id
        if self.instance_id is None:
            msg = 'Instance ID not found for this machine'
            log.error(msg)
            raise OSError(msg)
        log.info('Found instance ID: {i}'.format(i=self.instance_id))

        log.debug('Querying EC2 instances...')
        try:
            response = self.client.describe_instances(
                    DryRun=False,
                    InstanceIds=[self.instance_id]
            )
        except ClientError:
            _, ex, trace = sys.exc_info()
            msg = 'Unable to query EC2 for instances\n{e}'.format(e=str(ex))
            log.error(msg)
            raise AWSAPIError, msg, trace
        log.debug('Found instance info: {r}'.format(r=response))

        # Find the ENI ID
        log.info('Looking for the ENI ID to alias...')
        eni_id = None
        try:
            for reservation in response['Reservations']:
                for instance in reservation['Instances']:
                    if instance['InstanceId'] == self.instance_id:
                        for network_interface in instance['NetworkInterfaces']:
                            if network_interface['Attachment']['DeviceIndex'] == interface:
                                eni_id = network_interface['NetworkInterfaceId']
        except KeyError:
            _, ex, trace = sys.exc_info()
            msg = 'ENI ID not found in AWS response for interface: {i}'.format(i=interface)
            log.error(msg)
            raise EC2UtilError, msg, trace

        log.info('Found ENI ID: {e}'.format(e=eni_id))
        return eni_id
def get_eni_id ( self , interface = 1 ) : log = logging . getLogger ( self . cls_logger + '.get_eni_id' ) if self . instance_id is None : msg = 'Instance ID not found for this machine' log . error ( msg ) raise OSError ( msg ) log . info ( 'Found instance ID: {i}' . format ( i = self . instance_id ) ) log . debug ( 'Querying EC2 instances...' ) try : response = self . client . describe_instances ( DryRun = False , InstanceIds = [ self . instance_id ] ) except ClientError : _ , ex , trace = sys . exc_info ( ) msg = 'Unable to query EC2 for instances\n{e}' . format ( e = str ( ex ) ) log . error ( msg ) raise AWSAPIError , msg , trace log . debug ( 'Found instance info: {r}' . format ( r = response ) ) log . info ( 'Looking for the ENI ID to alias...' ) eni_id = None try : for reservation in response [ 'Reservations' ] : for instance in reservation [ 'Instances' ] : if instance [ 'InstanceId' ] == self . instance_id : for network_interface in instance [ 'NetworkInterfaces' ] : if network_interface [ 'Attachment' ] [ 'DeviceIndex' ] == interface : eni_id = network_interface [ 'NetworkInterfaceId' ] except KeyError : _ , ex , trace = sys . exc_info ( ) msg = 'ENI ID not found in AWS response for interface: {i}' . format ( i = interface ) log . error ( msg ) raise EC2UtilError , msg , trace log . info ( 'Found ENI ID: {e}' . format ( e = eni_id ) ) return eni_id
Given an interface number, gets the AWS elastic network
        interface associated with the interface.

        :param interface: Integer associated to the interface/device number
        :return: String Elastic Network Interface ID or None if not found
        :raises OSError, AWSAPIError, EC2UtilError