labpack/platforms/aws/ec2.py
def tag_instance(self, instance_id, tag_list):

        '''
            a method for adding or updating tags on an AWS instance

        :param instance_id: string of instance id on AWS
        :param tag_list: list of single key-value pairs
        :return: dictionary with aws response info
        '''

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

    # validate inputs
        input_fields = {
            'instance_id': instance_id,
            'tag_list': tag_list
        }
        for key, value in input_fields.items():
            object_title = '%s(%s=%s)' % (title, key, str(value))
            self.fields.validate(value, '.%s' % key, object_title)
    
    # retrieve tag list of instance
        self.iam.printer_on = False
        instance_details = self.read_instance(instance_id)
        self.iam.printer_on = True
        old_tags = instance_details['tags']
    
    # determine tags to remove
        delete_list = []
        tag_map = {}
        for tag in tag_list:
            tag_map[tag['key']] = tag['value']
        for tag in old_tags:
            if tag['key'] not in tag_map.keys():
                delete_list.append(tag)
            elif tag['value'] != tag_map[tag['key']]:
                delete_list.append(tag)

    # convert tag list to camelcase
        delete_list = self.iam.prepare(delete_list)
        tag_list = self.iam.prepare(tag_list)
    
    # remove tags from instance
        if delete_list:
            try:
                delete_kwargs = {
                    'Resources': [ instance_id ],
                    'Tags': delete_list
                }
                self.connection.delete_tags(**delete_kwargs)
            except:
                AWSConnectionError(title)
            
    # tag instance with updated tags
        try:
            create_kwargs = {
                'Resources': [ instance_id ],
                'Tags': tag_list
            }
            response = self.connection.create_tags(**create_kwargs)
        except:
            raise AWSConnectionError(title)
        
        return response

            a method for adding or updating tags on an AWS instance

        :param instance_id: string of instance id on AWS
        :param tag_list: list of single key-value pairs
        :return: dictionary with aws response info
        
a method for adding or updating tags on an AWS instance
a method for adding or updating tags on an AWS instance
def tag_instance(self, instance_id, tag_list):
        title = '%s.tag_instance' % self.__class__.__name__
        input_fields = {
            'instance_id': instance_id,
            'tag_list': tag_list
        }
        for key, value in input_fields.items():
            object_title = '%s(%s=%s)' % (title, key, str(value))
            self.fields.validate(value, '.%s' % key, object_title)
        self.iam.printer_on = False
        instance_details = self.read_instance(instance_id)
        self.iam.printer_on = True
        old_tags = instance_details['tags']
        delete_list = []
        tag_map = {}
        for tag in tag_list:
            tag_map[tag['key']] = tag['value']
        for tag in old_tags:
            if tag['key'] not in tag_map.keys():
                delete_list.append(tag)
            elif tag['value'] != tag_map[tag['key']]:
                delete_list.append(tag)
        delete_list = self.iam.prepare(delete_list)
        tag_list = self.iam.prepare(tag_list)
        if delete_list:
            try:
                delete_kwargs = {
                    'Resources': [ instance_id ],
                    'Tags': delete_list
                }
                self.connection.delete_tags(**delete_kwargs)
            except:
                AWSConnectionError(title)
        try:
            create_kwargs = {
                'Resources': [ instance_id ],
                'Tags': tag_list
            }
            response = self.connection.create_tags(**create_kwargs)
        except:
            raise AWSConnectionError(title)
        return response
def tag_instance ( self , instance_id , tag_list ) : title = '%s.tag_instance' % self . __class__ . __name__ input_fields = { 'instance_id' : instance_id , 'tag_list' : tag_list } for key , value in input_fields . items ( ) : object_title = '%s(%s=%s)' % ( title , key , str ( value ) ) self . fields . validate ( value , '.%s' % key , object_title ) self . iam . printer_on = False instance_details = self . read_instance ( instance_id ) self . iam . printer_on = True old_tags = instance_details [ 'tags' ] delete_list = [ ] tag_map = { } for tag in tag_list : tag_map [ tag [ 'key' ] ] = tag [ 'value' ] for tag in old_tags : if tag [ 'key' ] not in tag_map . keys ( ) : delete_list . append ( tag ) elif tag [ 'value' ] != tag_map [ tag [ 'key' ] ] : delete_list . append ( tag ) delete_list = self . iam . prepare ( delete_list ) tag_list = self . iam . prepare ( tag_list ) if delete_list : try : delete_kwargs = { 'Resources' : [ instance_id ] , 'Tags' : delete_list } self . connection . delete_tags ( ** delete_kwargs ) except : AWSConnectionError ( title ) try : create_kwargs = { 'Resources' : [ instance_id ] , 'Tags' : tag_list } response = self . connection . create_tags ( ** create_kwargs ) except : raise AWSConnectionError ( title ) return response
a method for adding or updating tags on an AWS instance
a method for adding or updating tags on an AWS instance
'''
            a method for adding or updating tags on an AWS instance

        :param instance_id: string of instance id on AWS
        :param tag_list: list of single key-value pairs
        :return: dictionary with aws response info
        ''' # validate inputs # retrieve tag list of instance # determine tags to remove # convert tag list to camelcase # remove tags from instance # tag instance with updated tags
dictionary with aws response info
dictionary with aws response info
self
instance_id
string of instance id on AWS
string of instance id on AWS
tag_list
list of single key-value pairs
list of single key - value pairs