<s> import time <EOL> class TaggedResource ( ) : <EOL> def __init__ ( self ) : <EOL> pass <EOL> def create_tags ( self , tags , timeout = <NUM_LIT> ) : <EOL> self . tester . debug ( "<STR_LIT>" + str ( self . tags ) ) <EOL> self . tester . create_tags ( [ self . id ] , tags ) <EOL> self . wait_for_tags ( tags , timeout = timeout ) <EOL> def wait_for_tags ( self , tags , creation = True , timeout = <NUM_LIT> ) : <EOL> start = time . time ( ) <EOL> elapsed = <NUM_LIT:0> <EOL> while elapsed < timeout : <EOL> self . update ( ) <EOL> applied_tags = self . convert_tag_list_to_dict ( self . tester . ec2 . get_all_tags ( filters = { u'<STR_LIT>' : self . id } ) ) <EOL> self . tester . debug ( "<STR_LIT>" + str ( applied_tags ) ) <EOL> found_keys = <NUM_LIT:0> <EOL> for key , value in tags . iteritems ( ) : <EOL> if key in applied_tags : <EOL> found_keys += <NUM_LIT:1> <EOL> self . tester . debug ( "<STR_LIT>" + str ( found_keys ) + "<STR_LIT>" + str ( len ( tags ) ) + "<STR_LIT::>" + key ) <EOL> if creation : <EOL> if found_keys == len ( tags ) : <EOL> return True <EOL> else : <EOL> pass <EOL> else : <EOL> if found_keys == <NUM_LIT:0> : <EOL> return True <EOL> else : <EOL> pass <EOL> elapsed = int ( time . time ( ) - start ) <EOL> time . sleep ( <NUM_LIT:5> ) <EOL> raise Exception ( "<STR_LIT>" + str ( timeout ) + "<STR_LIT>" ) <EOL> def convert_tag_list_to_dict ( self , list ) : <EOL> new_dict = { } <EOL> for tag in list : <EOL> new_dict [ tag . name ] = tag . value <EOL> return new_dict <EOL> def delete_tags ( self , tags , timeout = <NUM_LIT> ) : <EOL> self . tester . debug ( "<STR_LIT>" + str ( self . tags ) ) <EOL> self . tester . delete_tags ( [ self . id ] , tags ) <EOL> self . wait_for_tags ( tags , creation = False , timeout = timeout ) </s>
