<s> '''<STR_LIT>''' <EOL> from cStringIO import StringIO <EOL> from configobj import ConfigObj <EOL> from provy . core import Role <EOL> from provy . more . debian . package . aptitude import AptitudeRole <EOL> class MongoDBRole ( Role ) : <EOL> '''<STR_LIT>''' <EOL> def provision ( self ) : <EOL> '''<STR_LIT>''' <EOL> distro_info = self . get_distro_info ( ) <EOL> self . log ( '<STR_LIT>' ) <EOL> if distro_info . distributor_id == '<STR_LIT>' : <EOL> self . provision_to_ubuntu ( ) <EOL> else : <EOL> self . provision_to_debian ( ) <EOL> self . log ( '<STR_LIT>' ) <EOL> def provision_to_debian ( self ) : <EOL> '''<STR_LIT>''' <EOL> initialization_type = '<STR_LIT>' <EOL> self . __provision_with_init_type ( initialization_type ) <EOL> def provision_to_ubuntu ( self ) : <EOL> '''<STR_LIT>''' <EOL> initialization_type = '<STR_LIT>' <EOL> self . __provision_with_init_type ( initialization_type ) <EOL> def __provision_with_init_type ( self , initialization_type ) : <EOL> with self . using ( AptitudeRole ) as aptitude : <EOL> aptitude . ensure_gpg_key ( '<STR_LIT>' ) <EOL> aptitude . ensure_aptitude_source ( '<STR_LIT>' % initialization_type ) <EOL> aptitude . force_update ( ) <EOL> aptitude . ensure_package_installed ( '<STR_LIT>' ) <EOL> def restart ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . execute ( '<STR_LIT>' , sudo = True ) <EOL> def configure ( self , configuration ) : <EOL> '''<STR_LIT>''' <EOL> mongodb_config_path = '<STR_LIT>' <EOL> config = self . __config_from_remote ( mongodb_config_path ) <EOL> self . __set_config_items ( configuration , config ) <EOL> tmp_file = self . __tmp_file_with_config ( config ) <EOL> self . put_file ( from_file = tmp_file , to_file = mongodb_config_path , sudo = True ) <EOL> def __tmp_file_with_config ( self , config ) : <EOL> output_buffer = StringIO ( ) <EOL> config . write ( output_buffer ) <EOL> tmp_file = self . write_to_temp_file ( output_buffer . getvalue ( ) ) <EOL> return tmp_file <EOL> def __config_from_remote ( self , mongodb_config_path ) : <EOL> config_content = self . read_remote_file ( mongodb_config_path , sudo = True ) <EOL> config_buffer = StringIO ( config_content ) <EOL> config = ConfigObj ( infile = config_buffer ) <EOL> return config <EOL> def __set_config_items ( self , configuration , config ) : <EOL> for key , value in configuration . items ( ) : <EOL> if isinstance ( value , bool ) : <EOL> value = str ( value ) . lower ( ) <EOL> config [ key ] = value </s>
