labpack/platforms/aws/ec2.py
def list_images(self, tag_values=None):

        '''
            a method to retrieve the list of images of account on AWS EC2

        :param tag_values: [optional] list of tag values
        :return: list of image AWS ids
        '''

        title = '%s.list_images' % self.__class__.__name__

    # validate inputs
        input_fields = {
            'tag_values': tag_values
        }
        for key, value in input_fields.items():
            if value:
                object_title = '%s(%s=%s)' % (title, key, str(value))
                self.fields.validate(value, '.%s' % key, object_title)
        self._validate_tags(tag_values, title)
            
    # add tags to method arguments
        kw_args = { 'Owners': [ self.iam.owner_id ] }
        tag_text = ''
        if tag_values:
            kw_args = {
                'Filters': []
            }
            tag_words = []
            for key, value in tag_values.items():
                kw_args['Filters'].append({ 'Name': 'tag:%s' % key, 'Values': [value] })
            from labpack.parsing.grammar import join_words
            plural_value = ''
            if len(tag_values) > 1:
                plural_value = 's'
            tag_text = ' with tag value%s %s' % (plural_value, join_words(tag_words))
            
    # request image details from AWS
        self.iam.printer('Querying AWS region %s for images%s.' % (self.iam.region_name, tag_text))
        image_list = []
        try:
            response = self.connection.describe_images(**kw_args)
        except:
            raise AWSConnectionError(title)
        response_list = response['Images']

    # repeat request
        if not response_list:
            from time import sleep
            from timeit import default_timer as timer
            self.iam.printer('No images found initially. Checking again', flush=True)
            state_timeout = 0
            delay = 3
            while not response_list and state_timeout < 12:
                self.iam.printer('.', flush=True)
                sleep(delay)
                t3 = timer()
                try:
                    response = self.connection.describe_images(**kw_args)
                except:
                    raise AWSConnectionError(title)
                response_list = response['Images']
                t4 = timer()
                state_timeout += 1
                response_time = t4 - t3
                if 3 - response_time > 0:
                    delay = 3 - response_time
                else:
                    delay = 0
            self.iam.printer(' done.')

    # wait until all images are no longer pending
        for image in response_list:
            image_list.append(image['ImageId'])

    # report outcome and return results
        if image_list:
            print_out = 'Found image'
            if len(image_list) > 1:
                print_out += 's'
            from labpack.parsing.grammar import join_words
            print_out += ' %s.' % join_words(image_list)
            self.iam.printer(print_out)
        else:
            self.iam.printer('No images found.')

        return image_list

            a method to retrieve the list of images of account on AWS EC2

        :param tag_values: [optional] list of tag values
        :return: list of image AWS ids
        
a method to retrieve the list of images of account on AWS EC2
a method to retrieve the list of images of account on AWS EC2
def list_images(self, tag_values=None):
        title = '%s.list_images' % self.__class__.__name__
        input_fields = {
            'tag_values': tag_values
        }
        for key, value in input_fields.items():
            if value:
                object_title = '%s(%s=%s)' % (title, key, str(value))
                self.fields.validate(value, '.%s' % key, object_title)
        self._validate_tags(tag_values, title)
        kw_args = { 'Owners': [ self.iam.owner_id ] }
        tag_text = ''
        if tag_values:
            kw_args = {
                'Filters': []
            }
            tag_words = []
            for key, value in tag_values.items():
                kw_args['Filters'].append({ 'Name': 'tag:%s' % key, 'Values': [value] })
            from labpack.parsing.grammar import join_words
            plural_value = ''
            if len(tag_values) > 1:
                plural_value = 's'
            tag_text = ' with tag value%s %s' % (plural_value, join_words(tag_words))
        self.iam.printer('Querying AWS region %s for images%s.' % (self.iam.region_name, tag_text))
        image_list = []
        try:
            response = self.connection.describe_images(**kw_args)
        except:
            raise AWSConnectionError(title)
        response_list = response['Images']
        if not response_list:
            from time import sleep
            from timeit import default_timer as timer
            self.iam.printer('No images found initially. Checking again', flush=True)
            state_timeout = 0
            delay = 3
            while not response_list and state_timeout < 12:
                self.iam.printer('.', flush=True)
                sleep(delay)
                t3 = timer()
                try:
                    response = self.connection.describe_images(**kw_args)
                except:
                    raise AWSConnectionError(title)
                response_list = response['Images']
                t4 = timer()
                state_timeout += 1
                response_time = t4 - t3
                if 3 - response_time > 0:
                    delay = 3 - response_time
                else:
                    delay = 0
            self.iam.printer(' done.')
        for image in response_list:
            image_list.append(image['ImageId'])
        if image_list:
            print_out = 'Found image'
            if len(image_list) > 1:
                print_out += 's'
            from labpack.parsing.grammar import join_words
            print_out += ' %s.' % join_words(image_list)
            self.iam.printer(print_out)
        else:
            self.iam.printer('No images found.')
        return image_list
def list_images ( self , tag_values = None ) : title = '%s.list_images' % self . __class__ . __name__ input_fields = { 'tag_values' : tag_values } for key , value in input_fields . items ( ) : if value : object_title = '%s(%s=%s)' % ( title , key , str ( value ) ) self . fields . validate ( value , '.%s' % key , object_title ) self . _validate_tags ( tag_values , title ) kw_args = { 'Owners' : [ self . iam . owner_id ] } tag_text = '' if tag_values : kw_args = { 'Filters' : [ ] } tag_words = [ ] for key , value in tag_values . items ( ) : kw_args [ 'Filters' ] . append ( { 'Name' : 'tag:%s' % key , 'Values' : [ value ] } ) from labpack . parsing . grammar import join_words plural_value = '' if len ( tag_values ) > 1 : plural_value = 's' tag_text = ' with tag value%s %s' % ( plural_value , join_words ( tag_words ) ) self . iam . printer ( 'Querying AWS region %s for images%s.' % ( self . iam . region_name , tag_text ) ) image_list = [ ] try : response = self . connection . describe_images ( ** kw_args ) except : raise AWSConnectionError ( title ) response_list = response [ 'Images' ] if not response_list : from time import sleep from timeit import default_timer as timer self . iam . printer ( 'No images found initially. Checking again' , flush = True ) state_timeout = 0 delay = 3 while not response_list and state_timeout < 12 : self . iam . printer ( '.' , flush = True ) sleep ( delay ) t3 = timer ( ) try : response = self . connection . describe_images ( ** kw_args ) except : raise AWSConnectionError ( title ) response_list = response [ 'Images' ] t4 = timer ( ) state_timeout += 1 response_time = t4 - t3 if 3 - response_time > 0 : delay = 3 - response_time else : delay = 0 self . iam . printer ( ' done.' ) for image in response_list : image_list . append ( image [ 'ImageId' ] ) if image_list : print_out = 'Found image' if len ( image_list ) > 1 : print_out += 's' from labpack . parsing . grammar import join_words print_out += ' %s.' % join_words ( image_list ) self . iam . printer ( print_out ) else : self . iam . printer ( 'No images found.' ) return image_list
a method to retrieve the list of images of account on AWS EC2
a method to retrieve the list of images of account on AWS EC2
'''
            a method to retrieve the list of images of account on AWS EC2

        :param tag_values: [optional] list of tag values
        :return: list of image AWS ids
        ''' # validate inputs # add tags to method arguments # request image details from AWS # repeat request # wait until all images are no longer pending # report outcome and return results
list of image AWS ids
list of image AWS ids
self
tag_values
[optional] list of tag values
[ optional ] list of tag values