forked from bharathi26/ExaBGPmon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.py
executable file
·79 lines (51 loc) · 1.87 KB
/
manage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python
from subprocess import check_output
import os
from app.app import app
from app.models import bgp_updates, adv_routes, bgp_peers, bgp_config
from app.tasks import build_config_file, build_env_file
from flask.ext.script import Manager, Shell, Command
# app = create_app(os.getenv('FLASK_CONFIG') or 'default')
manager = Manager(app)
def init_config():
python_path = check_output(['which', 'python']).strip()
root_path = os.path.abspath(os.curdir)
config_path = os.path.join(root_path, 'etc', 'conf.ini')
config = {
'local-as': 65000,
'router-id': '127.0.0.1',
'local-address': '127.0.0.1',
'state': 'stopped',
'last_start': None,
'last_stop': None,
'python-path': python_path,
'root-path': root_path,
'config-path': config_path
}
print 'Config Path: %s' % config_path
print 'Config: %s' % config # debug
bgp_config.remove()
bgp_config.insert_one(config)
if not bgp_config.find_one():
print 'No config found, initializing config file.'
init_config()
class InitConfig(Command):
"""Initializes default config settings"""
def run(self):
init_config()
manager.add_command("init_config", InitConfig())
def make_shell_context():
return dict(app=app, bgp_updates=bgp_updates, adv_routes=adv_routes, bgp_peers=bgp_peers, bgp_config=bgp_config)
manager.add_command("shell", Shell(make_context=make_shell_context))
class BuildConfig(Command):
"""Builds config file"""
def run(self):
build_config_file(bgp_config.find_one(), list(bgp_peers.find()))
manager.add_command("build_config", BuildConfig())
class BuildEnv(Command):
"""Builds an env file in the etc folder for exaBGP"""
def run(self):
build_env_file()
manager.add_command("build_env", BuildEnv())
if __name__ == '__main__':
manager.run()