<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 . cleanup import resources as res_cleanup <EOL> from rally . plugins . openstack . scenarios . sahara import utils <EOL> from rally . plugins . openstack . scenarios . swift import utils as swift_utils <EOL> from rally . task import context <EOL> LOG = logging . getLogger ( __name__ ) <EOL> @ context . configure ( name = "<STR_LIT>" , order = <NUM_LIT> ) <EOL> class SaharaOutputDataSources ( 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>" : [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT:string>" , <EOL> } <EOL> } , <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> } <EOL> @ logging . log_task_wrapper ( LOG . info , <EOL> _ ( "<STR_LIT>" ) ) <EOL> def setup ( self ) : <EOL> utils . init_sahara_context ( self ) <EOL> for user , tenant_id in rutils . iterate_per_tenants ( <EOL> self . context [ "<STR_LIT>" ] ) : <EOL> clients = osclients . Clients ( user [ "<STR_LIT>" ] ) <EOL> sahara = clients . sahara ( ) <EOL> if self . config [ "<STR_LIT>" ] == "<STR_LIT>" : <EOL> swift = swift_utils . SwiftScenario ( clients = clients , <EOL> context = self . context ) <EOL> container_name = self . generate_random_name ( ) <EOL> self . context [ "<STR_LIT>" ] [ tenant_id ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] = { <EOL> "<STR_LIT:name>" : swift . _create_container ( <EOL> container_name = container_name ) , <EOL> "<STR_LIT>" : [ ] <EOL> } <EOL> self . setup_outputs_swift ( swift , sahara , tenant_id , <EOL> container_name , <EOL> user [ "<STR_LIT>" ] . username , <EOL> user [ "<STR_LIT>" ] . password ) <EOL> else : <EOL> self . setup_outputs_hdfs ( sahara , tenant_id , <EOL> self . config [ "<STR_LIT>" ] ) <EOL> def setup_outputs_hdfs ( self , sahara , tenant_id , output_url ) : <EOL> output_ds = sahara . data_sources . create ( <EOL> name = self . generate_random_name ( ) , <EOL> description = "<STR_LIT>" , <EOL> data_source_type = "<STR_LIT>" , <EOL> url = output_url ) <EOL> self . context [ "<STR_LIT>" ] [ tenant_id ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] = output_ds . id <EOL> def setup_outputs_swift ( self , swift , sahara , tenant_id , container_name , <EOL> username , password ) : <EOL> output_ds_swift = sahara . data_sources . create ( <EOL> name = self . generate_random_name ( ) , <EOL> description = "<STR_LIT>" , <EOL> data_source_type = "<STR_LIT>" , <EOL> url = "<STR_LIT>" + container_name + "<STR_LIT>" , <EOL> credential_user = username , <EOL> credential_pass = password ) <EOL> self . context [ "<STR_LIT>" ] [ tenant_id ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] = ( <EOL> output_ds_swift . id <EOL> ) <EOL> @ logging . log_task_wrapper ( LOG . info , <EOL> _ ( "<STR_LIT>" ) ) <EOL> def cleanup ( self ) : <EOL> for user , tenant_id in rutils . iterate_per_tenants ( <EOL> self . context [ "<STR_LIT>" ] ) : <EOL> if self . context [ "<STR_LIT>" ] [ tenant_id ] . get ( <EOL> "<STR_LIT>" , { } ) . get ( "<STR_LIT>" , { } ) . get ( "<STR_LIT:name>" ) is not None : <EOL> for swift_object in ( <EOL> self . context [ "<STR_LIT>" ] [ tenant_id ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ <EOL> "<STR_LIT>" ] ) : <EOL> res_cleanup . SwiftObject ( swift_object [ <NUM_LIT:1> ] ) <EOL> res_cleanup . SwiftContainer ( <EOL> self . context [ "<STR_LIT>" ] [ tenant_id ] . get ( <EOL> "<STR_LIT>" , { } ) . get ( "<STR_LIT>" , { } ) . get ( "<STR_LIT:name>" ) ) <EOL> resources = [ "<STR_LIT>" ] <EOL> resource_manager . cleanup ( <EOL> names = [ "<STR_LIT>" % res for res in resources ] , <EOL> users = self . context . get ( "<STR_LIT>" , [ ] ) ) </s>
