summaryrefslogtreecommitdiff
path: root/6/bgp.py
diff options
context:
space:
mode:
Diffstat (limited to '6/bgp.py')
-rwxr-xr-x6/bgp.py23
1 files changed, 23 insertions, 0 deletions
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)