diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2023-11-14 14:14:44 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2023-11-14 14:14:44 +0100 |
commit | 6dca28918be80a3ef0c2959a99067337f59f5972 (patch) | |
tree | e72273247504d89e0f462c7308e96a22bf17ee40 | |
parent | de3d2c7ed173d6a3478f2432dea441a7e2e1088a (diff) | |
download | prolog-firewall-6dca28918be80a3ef0c2959a99067337f59f5972.tar.gz prolog-firewall-6dca28918be80a3ef0c2959a99067337f59f5972.tar.bz2 prolog-firewall-6dca28918be80a3ef0c2959a99067337f59f5972.tar.xz prolog-firewall-6dca28918be80a3ef0c2959a99067337f59f5972.zip |
wip
-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 |