#NEWLINE# def main( ) : #NEWLINE# #INDENT# dbc = pymongo . Connection ( ) #NEWLINE# for db in s . MONGODB_DATABASE . keys ( ) : #NEWLINE# #INDENT# print ( ( "Dropping database '%s': %s" % ( db , s . MONGODB_DATABASE [ db ] ) ) ) #NEWLINE# dbc . drop_database ( s . MONGODB_DATABASE [ db ] ) #NEWLINE# #UNINDENT# roles = [ { #NEWLINE# #INDENT# 'name' : 'admin' , #NEWLINE# #UNINDENT# } ] #NEWLINE# import hashlib #NEWLINE# hasher1 = hashlib . sha512 ( ) #NEWLINE# hasher1 . update ( 'admin' ) #NEWLINE# admin_hash = hasher1 . hexdigest ( ) #NEWLINE# hasher2 = hashlib . sha512 ( ) #NEWLINE# hasher2 . update ( 'test1' ) #NEWLINE# test1_hash = hasher2 . hexdigest ( ) #NEWLINE# users = [ { #NEWLINE# #INDENT# 'username' : 'admin' , #NEWLINE# 'password' : admin_hash , #NEWLINE# 'email' : 'admin@local' , #NEWLINE# 'roles' : [ 'admin' ] , #NEWLINE# 'createdAt' : datetime . isoformat ( datetime . now ( ) ) , #NEWLINE# 'updatedAt' : datetime . isoformat ( datetime . now ( ) ) , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'username' : 'test1' , #NEWLINE# 'password' : db , #NEWLINE# 'email' : 'test1@local' , #NEWLINE# 'roles' : [ 'standard' ] , #NEWLINE# 'createdAt' : datetime . isoformat ( datetime . now ( ) ) , #NEWLINE# 'updatedAt' : datetime . isoformat ( datetime . now ( ) ) , #NEWLINE# #UNINDENT# } ] #NEWLINE# roles = [ { #NEWLINE# #INDENT# 'name' : 'admin' , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'name' : 'standard' , #NEWLINE# #UNINDENT# } ] #NEWLINE# for db in s . MONGODB_DATABASE . keys ( ) : #NEWLINE# #INDENT# current_db = dbc [ s . MONGODB_DATABASE [ db ] ] #NEWLINE# print ( ( "Creating users in db '%s': %s" % ( db , s . MONGODB_DATABASE [ db ] ) ) ) #NEWLINE# for user in users : #NEWLINE# #INDENT# current_db . hbuser . save ( user ) #NEWLINE# #UNINDENT# print ( ( "Creating roles in db '%s': %s" % ( db , s . MONGODB_DATABASE [ db ] ) ) ) #NEWLINE# for role in roles : #NEWLINE# #INDENT# current_db . role . save ( role ) #NEWLINE# #UNINDENT# print ( ( "Creating indexes in db '%s': %s" % ( db , s . MONGODB_DATABASE [ db ] ) ) ) #NEWLINE# current_db . hbuser . ensure_index ( 'username' , unique = True ) #NEWLINE# current_db . testplan . ensure_index ( 'name' , unique = True ) #NEWLINE# current_db . session . ensure_index ( 'name' , unique = True ) #NEWLINE# current_db . template . ensure_index ( 'name' , unique = True ) #NEWLINE# current_db . traffic . ensure_index ( 'recording_id' ) #NEWLINE# print ( ( "Creating capped collection 'log' in db '%s'" % s . MONGODB_DATABASE [ db ] ) ) #NEWLINE# current_db . create_collection ( 'log' , capped = True , size = 500000 ) #NEWLINE# print ( ( "Indexing log.timestamp in db '%s'" % s . MONGODB_DATABASE [ db ] ) ) #NEWLINE# current_db . log . ensure_index ( 'timestamp' )