diff options
-rw-r--r-- | 6/bgp.pl | 13 | ||||
-rwxr-xr-x | 6/bgp.py | 23 | ||||
-rw-r--r-- | 6/group_vars/hash/bgp.yaml | 11 | ||||
-rw-r--r-- | 6/group_vars/knot/bgp.yaml | 11 | ||||
-rw-r--r-- | 6/group_vars/kv24ix/bgp.yaml | 8 | ||||
-rw-r--r-- | 6/group_vars/lhn2ix/bgp.yaml | 8 | ||||
-rw-r--r-- | requirements.txt | 2 |
7 files changed, 65 insertions, 11 deletions
@@ -84,15 +84,6 @@ to_dict(neighbor(_, Remote), Dict) :- host_config(Remote, RC), } }. -routers_entry(router(R), Dict) :- - D = to_dict(router(R)), - pairs_keys_values(Data, [R], [D]), - dict_create(Dict, _, Data). - -bird_config(Dict) :- +bird_config(RouterDicts) :- routers(Routers), - maplist(to_dict(), Routers, RouterDicts), -% maplist(routers_entry(), Routers, RouterDicts), - Dict = _{routers:RouterDicts}. -% findall(neighbor(H, R), (host(H), host(R), neighbor(H, R)), Routers), -% yaml_write(current_output, _{neighbors:BgpConnectionDicts}). + maplist(to_dict(), Routers, RouterDicts). diff --git a/6/bgp.py b/6/bgp.py new file mode 100755 index 0000000..5096b67 --- /dev/null +++ b/6/bgp.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 + +from swiplserver import PrologMQI, PrologThread +import yaml +import os + +def to_ansible(kind, objs): + for o in objs: + host = o['host'] + print(f"k={host}") + os.makedirs(f"group_vars/{host}", exist_ok=True) + with open(f"group_vars/{host}/{kind}.yaml", "w") as f: + f.write(yaml.dump(o)) + +with PrologMQI() as mqi: + with mqi.create_thread() as p: + result = p.query("consult(main)") + print(result) + + result = p.query("bgp:bird_config(BirdDict)") + r = result[0]["BirdDict"] + print(yaml.dump(r)) + to_ansible("bgp", r) diff --git a/6/group_vars/hash/bgp.yaml b/6/group_vars/hash/bgp.yaml new file mode 100644 index 0000000..e479515 --- /dev/null +++ b/6/group_vars/hash/bgp.yaml @@ -0,0 +1,11 @@ +host: hash +neighbors: +- neighbor: + hostname: fdf3:aad9:a885:0b3a::1 + name: knot +- neighbor: + hostname: fdf3:aad9:a885:0b3a::16 + name: kv24ix +- neighbor: + hostname: fdf3:aad9:a885:0b3a::15 + name: lhn2ix diff --git a/6/group_vars/knot/bgp.yaml b/6/group_vars/knot/bgp.yaml new file mode 100644 index 0000000..808e2cf --- /dev/null +++ b/6/group_vars/knot/bgp.yaml @@ -0,0 +1,11 @@ +host: knot +neighbors: +- neighbor: + hostname: fdf3:aad9:a885:0b3a::13 + name: hash +- neighbor: + hostname: fdf3:aad9:a885:0b3a::16 + name: kv24ix +- neighbor: + hostname: fdf3:aad9:a885:0b3a::15 + name: lhn2ix diff --git a/6/group_vars/kv24ix/bgp.yaml b/6/group_vars/kv24ix/bgp.yaml new file mode 100644 index 0000000..4f69f7c --- /dev/null +++ b/6/group_vars/kv24ix/bgp.yaml @@ -0,0 +1,8 @@ +host: kv24ix +neighbors: +- neighbor: + hostname: fdf3:aad9:a885:0b3a::13 + name: hash +- neighbor: + hostname: fdf3:aad9:a885:0b3a::1 + name: knot diff --git a/6/group_vars/lhn2ix/bgp.yaml b/6/group_vars/lhn2ix/bgp.yaml new file mode 100644 index 0000000..73732ae --- /dev/null +++ b/6/group_vars/lhn2ix/bgp.yaml @@ -0,0 +1,8 @@ +host: lhn2ix +neighbors: +- neighbor: + hostname: fdf3:aad9:a885:0b3a::13 + name: hash +- neighbor: + hostname: fdf3:aad9:a885:0b3a::1 + name: knot diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..ba12eb2 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +swiplserver==1.0.2 +pyyaml==6.0.1 |