summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2023-11-23 22:57:55 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2023-11-23 22:57:55 +0100
commit8062753241f2c510c94b0fec6f2552950e0c8014 (patch)
tree6aeed21b783cf7d9f8bb377c44846d5c57dd4a26
parentba29b490ffddd28bb09235a1bd0e99df73bfa064 (diff)
downloadprolog-firewall-8062753241f2c510c94b0fec6f2552950e0c8014.tar.gz
prolog-firewall-8062753241f2c510c94b0fec6f2552950e0c8014.tar.bz2
prolog-firewall-8062753241f2c510c94b0fec6f2552950e0c8014.tar.xz
prolog-firewall-8062753241f2c510c94b0fec6f2552950e0c8014.zip
wip
-rw-r--r--7/bgp.pl7
-rw-r--r--7/firewall.pl23
-rw-r--r--7/main.pl12
3 files changed, 30 insertions, 12 deletions
diff --git a/7/bgp.pl b/7/bgp.pl
index d8c7ded..95b8f58 100644
--- a/7/bgp.pl
+++ b/7/bgp.pl
@@ -83,7 +83,7 @@ to_dict(router(R), Dict) :-
to_dict(neighbor(_, Remote), Dict) :-
host_config(Remote, RC),
- get_assoc("ip", RC, Ip),
+ get_assoc(ip, RC, Ip),
Dict = {
"neighbor":{
"name": Remote,
@@ -91,11 +91,6 @@ to_dict(neighbor(_, Remote), Dict) :-
}
}.
-bird_config(BirdConfig) :-
- routers(Routers),
- maplist(to_dict, Routers, RouterDicts),
- dict_pairs(BirdConfig, bird_config, RouterDicts).
-
create_firewall :-
firewall:retract_all_from(bgp),
findall(fw(Host, Attrs), fw(Host, Attrs), Goals),
diff --git a/7/firewall.pl b/7/firewall.pl
index 9bb0cc2..9e00afe 100644
--- a/7/firewall.pl
+++ b/7/firewall.pl
@@ -8,7 +8,11 @@
retract_all_from/1]).
:- use_module(library(assoc)).
+:- use_module(library(files)).
+:- use_module(library(format)).
:- use_module(library(dcgs)).
+:- use_module(library(lists)).
+:- use_module(library(serialization/json)).
:- use_module(hosts, [
router_link/3]).
@@ -35,3 +39,22 @@ retract_all_from(From) :-
retract_rules([R|Rules]) :- retract(R), retract_rules(Rules).
retract_rules([]).
+
+ansible(Basedir) :-
+ setof(Host, Attrs^fw_rule(Host, Attrs), Hosts),
+ ansible_host(Basedir, Hosts).
+
+ansible_host(Basedir, [Host|Hosts]) :-
+ atom_chars(Host, HostS),
+ append(Basedir, [HostS], DirPs),
+ path_segments(Dir, DirPs),
+ append(Basedir, [HostS, "firewall.yaml"], FilePs),
+ path_segments(File, FilePs),
+ format("mkdir ~s~n", [Dir]),
+ make_directory_path(Dir),
+ format("firewall: ~s~n", [File]),
+ ansible_firewall(File, Host),
+ ansible_host(Basedir, Hosts).
+
+ansible_firewall(File, Host) :-
+ true.
diff --git a/7/main.pl b/7/main.pl
index 684708f..393ad55 100644
--- a/7/main.pl
+++ b/7/main.pl
@@ -22,10 +22,10 @@ print_warnings :-
; format("No warnings!~n", [])
).
-rm_rf(Dir) :-
+rm_rf(Parents) :-
+ path_segments(Dir, Parents),
directory_files(Dir, Files),
- path_segments(Dir, Ps),
- rm_rf_files(Ps, Files).
+ rm_rf_files(Parents, Files).
rm_rf_files(_, []).
rm_rf_files(Parents, [D|Dir]) :-
@@ -47,6 +47,6 @@ rm_rf_files(Parents, [D|Dir]) :-
main :-
bgp:create_firewall,
print_warnings,
- bgp:bird_config(BirdDict),
- rm_rf("host_vars"),
- yaml_write(current_output, BirdDict).
+ path_segments("host_vars", Path),
+ rm_rf(Path),
+ firewall:write(Path).