#NEWLINE# def present( name , character_set = None , collate = None , **connection_args ) : #NEWLINE# #INDENT# '\n    Ensure that the named database is present with the specified properties\n\n    name\n        The name of the database to manage\n    ' #NEWLINE# ret = { #NEWLINE# #INDENT# 'name' : name , #NEWLINE# 'changes' : { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , #NEWLINE# 'result' : True , #NEWLINE# 'comment' : 'Database {0} is already present' . format ( name ) , #NEWLINE# #UNINDENT# } #NEWLINE# existing = __salt__ [ 'mysql.db_get' ] ( name , ** connection_args ) #NEWLINE# if existing : #NEWLINE# #INDENT# alter = False #NEWLINE# if ( character_set and ( character_set != existing . get ( 'character_set' ) ) ) : #NEWLINE# #INDENT# LOG . debug ( 'character set differes from {0} : {1}' . format ( character_set , existing . get ( 'character_set' ) ) ) #NEWLINE# alter = True #NEWLINE# #UNINDENT# if ( collate and ( collate != existing . get ( 'collate' ) ) ) : #NEWLINE# #INDENT# LOG . debug ( 'collate set differes from {0} : {1}' . format ( collate , existing . get ( 'collate' ) ) ) #NEWLINE# alter = True #NEWLINE# #UNINDENT# if alter : #NEWLINE# #INDENT# __salt__ [ 'mysql.alter_db' ] ( name , character_set = character_set , collate = collate , ** connection_args ) #NEWLINE# #UNINDENT# current = __salt__ [ 'mysql.db_get' ] ( name , ** connection_args ) #NEWLINE# if ( existing . get ( 'collate' , None ) != current . get ( 'collate' , None ) ) : #NEWLINE# #INDENT# ret [ 'changes' ] . update ( { #NEWLINE# #INDENT# 'collate' : { #NEWLINE# #INDENT# 'before' : existing . get ( 'collate' , None ) , #NEWLINE# 'now' : current . get ( 'collate' , None ) , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# if ( existing . get ( 'character_set' , None ) != current . get ( 'character_set' , None ) ) : #NEWLINE# #INDENT# ret [ 'changes' ] . update ( { #NEWLINE# #INDENT# 'character_set' : { #NEWLINE# #INDENT# 'before' : existing . get ( 'character_set' , None ) , #NEWLINE# 'now' : current . get ( 'character_set' , None ) , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# return ret #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# err = _get_mysql_error ( ) #NEWLINE# if ( err is not None ) : #NEWLINE# #INDENT# ret [ 'comment' ] = err #NEWLINE# ret [ 'result' ] = False #NEWLINE# return ret #NEWLINE# #UNINDENT# #UNINDENT# if __opts__ [ 'test' ] : #NEWLINE# #INDENT# ret [ 'result' ] = None #NEWLINE# ret [ 'comment' ] = 'Database {0} is not present and needs to be created' . format ( name ) #NEWLINE# return ret #NEWLINE# #UNINDENT# if __salt__ [ 'mysql.db_create' ] ( name , character_set = character_set , collate = collate , ** connection_args ) : #NEWLINE# #INDENT# ret [ 'comment' ] = 'The database {0} has been created' . format ( name ) #NEWLINE# ret [ 'changes' ] [ name ] = 'Present' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ret [ 'comment' ] = 'Failed to create database {0}' . format ( name ) #NEWLINE# err = _get_mysql_error ( ) #NEWLINE# if ( err is not None ) : #NEWLINE# #INDENT# ret [ 'comment' ] += ' ({0})' . format ( err ) #NEWLINE# #UNINDENT# ret [ 'result' ] = False #NEWLINE# #UNINDENT# return ret