From 6dca28918be80a3ef0c2959a99067337f59f5972 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Tue, 14 Nov 2023 14:14:44 +0100 Subject: wip --- 6/bgp.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 6/bgp.py (limited to '6/bgp.py') 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) -- cgit v1.2.3