<s> from rally . common . i18n import _ <EOL> from rally . common import logging <EOL> from rally . common import utils as rutils <EOL> from rally import consts <EOL> from rally import osclients <EOL> from rally . plugins . openstack . wrappers import glance as glance_wrapper <EOL> from rally . task import context <EOL> LOG = logging . getLogger ( __name__ ) <EOL> @ context . configure ( name = "<STR_LIT>" , order = <NUM_LIT> ) <EOL> class ImageGenerator ( context . Context ) : <EOL> """<STR_LIT>""" <EOL> CONFIG_SCHEMA = { <EOL> "<STR_LIT:type>" : "<STR_LIT:object>" , <EOL> "<STR_LIT>" : consts . JSON_SCHEMA , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT:string>" , <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ] , <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT:string>" , <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT:string>" , <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:0> <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:0> <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:1> <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT:object>" , <EOL> "<STR_LIT>" : True <EOL> } <EOL> } , <EOL> "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" ] , <EOL> "<STR_LIT>" : False <EOL> } <EOL> @ logging . log_task_wrapper ( LOG . info , _ ( "<STR_LIT>" ) ) <EOL> def setup ( self ) : <EOL> image_url = self . config [ "<STR_LIT>" ] <EOL> image_type = self . config [ "<STR_LIT>" ] <EOL> image_container = self . config [ "<STR_LIT>" ] <EOL> images_per_tenant = self . config [ "<STR_LIT>" ] <EOL> image_name = self . config . get ( "<STR_LIT>" ) <EOL> for user , tenant_id in rutils . iterate_per_tenants ( <EOL> self . context [ "<STR_LIT>" ] ) : <EOL> current_images = [ ] <EOL> clients = osclients . Clients ( <EOL> user [ "<STR_LIT>" ] , <EOL> api_info = self . context [ "<STR_LIT>" ] . get ( "<STR_LIT>" ) ) <EOL> glance_wrap = glance_wrapper . wrap ( clients . glance , self ) <EOL> kwargs = self . config . get ( "<STR_LIT>" , { } ) <EOL> if self . config . get ( "<STR_LIT>" ) is not None : <EOL> LOG . warning ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> kwargs [ "<STR_LIT>" ] = self . config [ "<STR_LIT>" ] <EOL> if self . config . get ( "<STR_LIT>" ) is not None : <EOL> LOG . warning ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> kwargs [ "<STR_LIT>" ] = self . config [ "<STR_LIT>" ] <EOL> for i in range ( images_per_tenant ) : <EOL> if image_name and i > <NUM_LIT:0> : <EOL> cur_name = image_name + str ( i ) <EOL> elif image_name : <EOL> cur_name = image_name <EOL> else : <EOL> cur_name = self . generate_random_name ( ) <EOL> image = glance_wrap . create_image ( <EOL> image_container , image_url , image_type , <EOL> name = cur_name , ** kwargs ) <EOL> current_images . append ( image . id ) <EOL> self . context [ "<STR_LIT>" ] [ tenant_id ] [ "<STR_LIT>" ] = current_images <EOL> @ logging . log_task_wrapper ( LOG . info , _ ( "<STR_LIT>" ) ) <EOL> def cleanup ( self ) : <EOL> for user , tenant_id in rutils . iterate_per_tenants ( <EOL> self . context [ "<STR_LIT>" ] ) : <EOL> clients = osclients . Clients ( <EOL> user [ "<STR_LIT>" ] , <EOL> api_info = self . context [ "<STR_LIT>" ] . get ( "<STR_LIT>" ) ) <EOL> glance_wrap = glance_wrapper . wrap ( clients . glance , self ) <EOL> for image in self . context [ "<STR_LIT>" ] [ tenant_id ] . get ( "<STR_LIT>" , [ ] ) : <EOL> glance_wrap . delete_image ( clients . glance ( ) . images . get ( image ) ) </s>
