diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2023-11-23 10:49:21 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2023-11-23 10:49:21 +0100 |
commit | 2583897e4c5cbe56525365206c2a64bcd0c75e5f (patch) | |
tree | a98e8c51917e7690a79c939d16c46c9bf837cfb4 /7/bgp.py | |
parent | 3d1c40ea667a25c1dde11a44a9e2e87a8cf51112 (diff) | |
download | prolog-firewall-2583897e4c5cbe56525365206c2a64bcd0c75e5f.tar.gz prolog-firewall-2583897e4c5cbe56525365206c2a64bcd0c75e5f.tar.bz2 prolog-firewall-2583897e4c5cbe56525365206c2a64bcd0c75e5f.tar.xz prolog-firewall-2583897e4c5cbe56525365206c2a64bcd0c75e5f.zip |
wip
Diffstat (limited to '7/bgp.py')
-rwxr-xr-x | 7/bgp.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/7/bgp.py b/7/bgp.py new file mode 100755 index 0000000..d508762 --- /dev/null +++ b/7/bgp.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 + +from swiplserver import PrologMQI, PrologThread +import yaml +import os + +def to_ansible(kind, hosts): + for host, o in hosts.items(): + print(f"host={host}") + os.makedirs(f"host_vars/{host}", exist_ok=True) + with open(f"host_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), main.") + print(result) + + result = p.query("bgp:bird_config(BirdDict)") + r = result[0]["BirdDict"] + print(yaml.dump(r)) + to_ansible("bgp", r) + + hosts = {} + result = p.query("firewall:fw_rule(Host, Attrs).") +# print(yaml.dump(result)) + for r in result: + host = r["Host"] + if host not in hosts: + hosts[host] = h = {} + h["firewall_rules"] = rules = [] + rules.append(r["Attrs"]) + + to_ansible("firewall", hosts) |