-
Notifications
You must be signed in to change notification settings - Fork 6
/
configure.py
executable file
·57 lines (50 loc) · 1.54 KB
/
configure.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
#!/usr/bin/env python3
import argparse
import os
import sys
from routers.bird import Bird
from routers.frr import FRR
from routers.helpers import fetch_bgp
USE_METADATA = os.getenv("USE_METADATA", "yes")
API_TOKEN = os.getenv("API_TOKEN", None)
INSTANCE_ID = os.getenv("INSTANCE_ID", None)
if __name__ == "__main__": # noqa: C901
if USE_METADATA != "yes":
if not API_TOKEN:
sys.exit("Packet API token missing from environment")
if not INSTANCE_ID:
sys.exit("Instance ID missing from environment")
parser = argparse.ArgumentParser()
parser.add_argument(
"-r",
"--router",
help="the routing daemon to be configured",
action="store",
type=str,
choices=["bird", "bird6", "frr"],
required=True,
)
args = parser.parse_args()
headers = {}
if API_TOKEN:
headers["X-Auth-Token"] = API_TOKEN
bgp = fetch_bgp(
use_metadata=(USE_METADATA == "yes"), headers=headers, instance=INSTANCE_ID
)
if args.router == "bird":
bird = Bird(**bgp)
if bird.v4_peer_count > 0:
print(bird.config)
else:
sys.exit("BGP over IPv4 is not enabled")
elif args.router == "bird6":
bird6 = Bird(family=6, **bgp)
if bird6.v6_peer_count > 0:
print(bird6.config)
else:
sys.exit("BGP over IPv6 is not enabled")
elif args.router == "frr":
frr = FRR(**bgp)
print(frr.config)
else:
sys.exit("Unrecognized routing daemon specified")