summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--6/bgp.pl13
-rwxr-xr-x6/bgp.py23
-rw-r--r--6/group_vars/hash/bgp.yaml11
-rw-r--r--6/group_vars/knot/bgp.yaml11
-rw-r--r--6/group_vars/kv24ix/bgp.yaml8
-rw-r--r--6/group_vars/lhn2ix/bgp.yaml8
-rw-r--r--requirements.txt2
7 files changed, 65 insertions, 11 deletions
diff --git a/6/bgp.pl b/6/bgp.pl
index d9b448b..6d16500 100644
--- a/6/bgp.pl
+++ b/6/bgp.pl
@@ -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