1
|
|
|
# encoding: utf-8 |
2
|
|
|
""" |
3
|
|
|
__main__.py |
4
|
|
|
|
5
|
|
|
Created by Thomas Mangin on 2010-01-15. |
6
|
|
|
Copyright (c) 2009-2017 Exa Networks. All rights reserved. |
7
|
|
|
License: 3-clause BSD. (See the COPYRIGHT file) |
8
|
|
|
""" |
9
|
|
|
|
10
|
|
|
import os |
11
|
|
|
import sys |
12
|
|
|
import argparse |
13
|
|
|
|
14
|
|
|
from exabgp.application import cli |
15
|
|
|
from exabgp.application import server |
16
|
|
|
from exabgp.application import decode |
17
|
|
|
from exabgp.application import environ |
18
|
|
|
from exabgp.application import version |
19
|
|
|
from exabgp.application import validate |
20
|
|
|
from exabgp.application import healthcheck |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
def main(): |
24
|
|
|
cli_named_pipe = os.environ.get('exabgp_cli_pipe', '') |
25
|
|
|
if cli_named_pipe: |
26
|
|
|
from exabgp.application.pipe import main |
27
|
|
|
|
28
|
|
|
main(cli_named_pipe) |
29
|
|
|
sys.exit(0) |
30
|
|
|
|
31
|
|
|
# compatibility with exabgp 4.x |
32
|
|
|
if len(sys.argv) > 1 and not ('-h' in sys.argv or '--help' in sys.argv): |
33
|
|
|
if sys.argv[1] not in ('version', 'cli', 'healthcheck', 'decode', 'server', 'env', 'validate'): |
34
|
|
|
sys.argv = sys.argv[0:1] + ['server'] + sys.argv[1:] |
35
|
|
|
|
36
|
|
|
formatter = argparse.RawDescriptionHelpFormatter |
37
|
|
|
parser = argparse.ArgumentParser(description='The BGP swiss army knife of networking') |
38
|
|
|
|
39
|
|
|
subparsers = parser.add_subparsers() |
40
|
|
|
|
41
|
|
|
sub = subparsers.add_parser('version', help='report exabgp version', description=version.__doc__) |
42
|
|
|
sub.set_defaults(func=version.cmdline) |
43
|
|
|
version.setargs(sub) |
44
|
|
|
|
45
|
|
|
sub = subparsers.add_parser('cli', help='control a running exabgp server instance', description=cli.__doc__) |
46
|
|
|
sub.set_defaults(func=cli.cmdline) |
47
|
|
|
cli.setargs(sub) |
48
|
|
|
|
49
|
|
|
sub = subparsers.add_parser( |
50
|
|
|
'healthcheck', |
51
|
|
|
help='monitor services and announce/withdraw routes', |
52
|
|
|
description=healthcheck.__doc__, |
53
|
|
|
formatter_class=formatter, |
54
|
|
|
) |
55
|
|
|
sub.set_defaults(func=healthcheck.cmdline) |
56
|
|
|
healthcheck.setargs(sub) |
57
|
|
|
|
58
|
|
|
sub = subparsers.add_parser('env', help='show exabgp configuration information', description=environ.__doc__) |
59
|
|
|
sub.set_defaults(func=environ.cmdline) |
60
|
|
|
environ.setargs(sub) |
61
|
|
|
|
62
|
|
|
sub = subparsers.add_parser('decode', help='decode hex-encoded bgp packets', description=decode.__doc__) |
63
|
|
|
sub.set_defaults(func=decode.cmdline) |
64
|
|
|
decode.setargs(sub) |
65
|
|
|
|
66
|
|
|
sub = subparsers.add_parser('server', help='start exabgp', description=server.__doc__) |
67
|
|
|
sub.set_defaults(func=server.cmdline) |
68
|
|
|
server.setargs(sub) |
69
|
|
|
|
70
|
|
|
sub = subparsers.add_parser('validate', help='validate configuration', description=validate.__doc__) |
71
|
|
|
sub.set_defaults(func=validate.cmdline) |
72
|
|
|
validate.setargs(sub) |
73
|
|
|
|
74
|
|
|
try: |
75
|
|
|
cmdarg = parser.parse_args() |
76
|
|
|
except Exception as exc: |
77
|
|
|
sys.exit(exc.args[-1]) |
78
|
|
|
|
79
|
|
|
options = vars(cmdarg) |
80
|
|
|
|
81
|
|
|
if 'func' in options: |
82
|
|
|
cmdarg.func(cmdarg) |
83
|
|
|
else: |
84
|
|
|
parser.print_help() |
85
|
|
|
environ.default() |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
if __name__ == '__main__': |
89
|
|
|
main() |
90
|
|
|
|