<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 . cleanup import manager as resource_manager <EOL> from rally . plugins . openstack . scenarios . ec2 import utils as ec2_utils <EOL> from rally . task import context <EOL> from rally . task import types <EOL> LOG = logging . getLogger ( __name__ ) <EOL> @ context . configure ( name = "<STR_LIT>" , order = <NUM_LIT> ) <EOL> class EC2ServerGenerator ( 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:image>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT:object>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:name>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT:string>" <EOL> } <EOL> } <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT:object>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:name>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT:string>" <EOL> } <EOL> } <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:1> <EOL> } <EOL> } , <EOL> "<STR_LIT>" : [ "<STR_LIT:image>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> "<STR_LIT>" : False <EOL> } <EOL> @ logging . log_task_wrapper ( LOG . info , _ ( "<STR_LIT>" ) ) <EOL> def setup ( self ) : <EOL> image = self . config [ "<STR_LIT:image>" ] <EOL> flavor = self . config [ "<STR_LIT>" ] <EOL> clients = osclients . Clients ( self . context [ "<STR_LIT>" ] [ <NUM_LIT:0> ] [ "<STR_LIT>" ] ) <EOL> image_id = types . EC2ImageResourceType . transform ( clients = clients , <EOL> resource_config = image ) <EOL> for user , tenant_id in rutils . iterate_per_tenants ( <EOL> self . context [ "<STR_LIT>" ] ) : <EOL> LOG . debug ( "<STR_LIT>" <EOL> % ( user [ "<STR_LIT>" ] ) ) <EOL> user_clients = osclients . Clients ( user [ "<STR_LIT>" ] ) <EOL> ec2_scenario = ec2_utils . EC2Scenario ( clients = user_clients ) <EOL> LOG . debug ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" . format ( <EOL> image_id = image_id , flavor_name = flavor [ "<STR_LIT:name>" ] , <EOL> servers_per_tenant = self . config [ "<STR_LIT>" ] ) ) <EOL> servers = ec2_scenario . _boot_servers ( <EOL> image_id , flavor [ "<STR_LIT:name>" ] , self . config [ "<STR_LIT>" ] ) <EOL> current_servers = [ server . id for server in servers ] <EOL> self . context [ "<STR_LIT>" ] [ tenant_id ] [ "<STR_LIT>" ] = current_servers <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>
