<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 . plugins . openstack . cleanup import manager as resource_manager <EOL> from rally . plugins . openstack . scenarios . heat import utils as heat_utils <EOL> from rally . task import context <EOL> LOG = logging . getLogger ( __name__ ) <EOL> @ context . configure ( name = "<STR_LIT>" , order = <NUM_LIT> ) <EOL> class StackGenerator ( 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>" , <EOL> "<STR_LIT>" : <NUM_LIT:1> <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:1> <EOL> } <EOL> } , <EOL> "<STR_LIT>" : False <EOL> } <EOL> DEFAULT_CONFIG = { <EOL> "<STR_LIT>" : <NUM_LIT:2> , <EOL> "<STR_LIT>" : <NUM_LIT:10> <EOL> } <EOL> @ staticmethod <EOL> def _prepare_stack_template ( res_num ) : <EOL> template = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:description>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { } <EOL> } <EOL> rand_string = { "<STR_LIT:type>" : "<STR_LIT>" } <EOL> for i in range ( res_num ) : <EOL> template [ "<STR_LIT>" ] [ "<STR_LIT>" % i ] = rand_string <EOL> return template <EOL> @ logging . log_task_wrapper ( LOG . info , _ ( "<STR_LIT>" ) ) <EOL> def setup ( self ) : <EOL> template = self . _prepare_stack_template ( <EOL> self . config [ "<STR_LIT>" ] ) <EOL> for user , tenant_id in rutils . iterate_per_tenants ( <EOL> self . context [ "<STR_LIT>" ] ) : <EOL> heat_scenario = heat_utils . HeatScenario ( <EOL> { "<STR_LIT:user>" : user , "<STR_LIT>" : self . context [ "<STR_LIT>" ] } ) <EOL> self . context [ "<STR_LIT>" ] [ tenant_id ] [ "<STR_LIT>" ] = [ ] <EOL> for i in range ( self . config [ "<STR_LIT>" ] ) : <EOL> stack = heat_scenario . _create_stack ( template ) <EOL> self . context [ "<STR_LIT>" ] [ tenant_id ] [ "<STR_LIT>" ] . append ( stack . id ) <EOL> @ logging . log_task_wrapper ( LOG . info , _ ( "<STR_LIT>" ) ) <EOL> def cleanup ( self ) : <EOL> resource_manager . cleanup ( names = [ "<STR_LIT>" ] , <EOL> users = self . context . get ( "<STR_LIT>" , [ ] ) ) </s>
