def init_database(args): """ Initialize the database. """ print "Initializing the database..." from freelan_server.database import DATABASE, User, Network DATABASE.create_all() if args.password: DATABASE.session.add(User("admin", "*****@*****.**", args.password, True)) print 'Added an "admin" account with the specified password.' else: DATABASE.session.add(User("admin", "*****@*****.**", "password", True)) print 'Added an "admin" account with the default password "password".' if args.add_test_data: alice = User("alice", "*****@*****.**", "password") bob = User("bob", "*****@*****.**", "password") chris = User("chris", "*****@*****.**", "password") denis = User("denis", "*****@*****.**", "password") eleanor = User("eleanor", "*****@*****.**", "password") DATABASE.session.add(alice) DATABASE.session.add(bob) DATABASE.session.add(chris) DATABASE.session.add(denis) DATABASE.session.add(eleanor) print 'Added some user accounts with default password "password".' my_network = Network("My network") foo_network = Network("Foo network") bar_network = Network("Bar network") virtual_network = Network("Virtual network") DATABASE.session.add(my_network) DATABASE.session.add(foo_network) DATABASE.session.add(bar_network) DATABASE.session.add(virtual_network) print "Added some networks." my_network.users.append(alice) my_network.users.append(bob) my_network.users.append(chris) foo_network.users.append(alice) foo_network.users.append(bob) bar_network.users.append(alice) virtual_network.users.append(chris) print "Added some users to the networks." DATABASE.session.commit() print "Database initialized."
def init_database(args): """ Initialize the database. """ print 'Initializing the database...' from freelan_server.database import DATABASE, User, Network, UserInNetwork DATABASE.create_all() if args.password: DATABASE.session.add(User(username='******', email='*****@*****.**', password=args.password, admin_flag=True)) print 'Added an "admin" account with the specified password.' else: DATABASE.session.add(User(username='******', email='*****@*****.**', password='******', admin_flag=True)) print 'Added an "admin" account with the default password "password".' if args.add_test_data: alice = User(username='******', email='*****@*****.**', password='******') bob = User(username='******', email='*****@*****.**', password='******') chris = User(username='******', email='*****@*****.**', password='******') denis = User(username='******', email='*****@*****.**', password='******') eleanor = User(username='******', email='*****@*****.**', password='******') DATABASE.session.add(alice) DATABASE.session.add(bob) DATABASE.session.add(chris) DATABASE.session.add(denis) DATABASE.session.add(eleanor) print 'Added some user accounts with default password "password".' my_network = Network(name='My network', ipv4_address='9.0.0.0/24') foo_network = Network(name='Foo network') bar_network = Network(name='Bar network') virtual_network = Network(name='Virtual network') DATABASE.session.add(my_network) DATABASE.session.add(foo_network) DATABASE.session.add(bar_network) DATABASE.session.add(virtual_network) print 'Added some networks.' DATABASE.session.add(UserInNetwork(user=alice, network=my_network, ipv4_address='9.0.0.1')) DATABASE.session.add(UserInNetwork(user=bob, network=my_network, ipv4_address='9.0.0.2')) DATABASE.session.add(UserInNetwork(user=chris, network=my_network, ipv4_address='9.0.0.3')) DATABASE.session.add(UserInNetwork(user=alice, network=foo_network)) DATABASE.session.add(UserInNetwork(user=bob, network=foo_network)) DATABASE.session.add(UserInNetwork(user=alice, network=bar_network)) DATABASE.session.add(UserInNetwork(user=chris, network=virtual_network)) print 'Added some users to the networks.' DATABASE.session.commit() print 'Database initialized.'
def clean_database(args): """ Clean the database. """ print 'Cleaning the database...' from freelan_server.database import DATABASE DATABASE.drop_all() print 'Database cleaned.'
def clean_database(args): """ Clean the database. """ print "Cleaning the database..." from freelan_server.database import DATABASE DATABASE.drop_all() print "Database cleaned."
def init_database(args): """ Initialize the database. """ print 'Initializing the database...' from freelan_server.database import DATABASE, User, Network, UserInNetwork DATABASE.create_all() if args.password: DATABASE.session.add( User(username='******', email='*****@*****.**', password=args.password, admin_flag=True)) print 'Added an "admin" account with the specified password.' else: DATABASE.session.add( User(username='******', email='*****@*****.**', password='******', admin_flag=True)) print 'Added an "admin" account with the default password "password".' if args.add_test_data: alice = User(username='******', email='*****@*****.**', password='******') bob = User(username='******', email='*****@*****.**', password='******') chris = User(username='******', email='*****@*****.**', password='******') denis = User(username='******', email='*****@*****.**', password='******') eleanor = User(username='******', email='*****@*****.**', password='******') DATABASE.session.add(alice) DATABASE.session.add(bob) DATABASE.session.add(chris) DATABASE.session.add(denis) DATABASE.session.add(eleanor) print 'Added some user accounts with default password "password".' my_network = Network(name='My network', ipv4_address='9.0.0.0/24') foo_network = Network(name='Foo network') bar_network = Network(name='Bar network') virtual_network = Network(name='Virtual network') DATABASE.session.add(my_network) DATABASE.session.add(foo_network) DATABASE.session.add(bar_network) DATABASE.session.add(virtual_network) print 'Added some networks.' DATABASE.session.add( UserInNetwork(user=alice, network=my_network, ipv4_address='9.0.0.1')) DATABASE.session.add( UserInNetwork(user=bob, network=my_network, ipv4_address='9.0.0.2')) DATABASE.session.add( UserInNetwork(user=chris, network=my_network, ipv4_address='9.0.0.3')) DATABASE.session.add(UserInNetwork(user=alice, network=foo_network)) DATABASE.session.add(UserInNetwork(user=bob, network=foo_network)) DATABASE.session.add(UserInNetwork(user=alice, network=bar_network)) DATABASE.session.add(UserInNetwork(user=chris, network=virtual_network)) print 'Added some users to the networks.' DATABASE.session.commit() print 'Database initialized.'