diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2023-11-23 22:57:55 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2023-11-23 22:57:55 +0100 |
commit | 8062753241f2c510c94b0fec6f2552950e0c8014 (patch) | |
tree | 6aeed21b783cf7d9f8bb377c44846d5c57dd4a26 /7 | |
parent | ba29b490ffddd28bb09235a1bd0e99df73bfa064 (diff) | |
download | prolog-firewall-8062753241f2c510c94b0fec6f2552950e0c8014.tar.gz prolog-firewall-8062753241f2c510c94b0fec6f2552950e0c8014.tar.bz2 prolog-firewall-8062753241f2c510c94b0fec6f2552950e0c8014.tar.xz prolog-firewall-8062753241f2c510c94b0fec6f2552950e0c8014.zip |
wip
Diffstat (limited to '7')
-rw-r--r-- | 7/bgp.pl | 7 | ||||
-rw-r--r-- | 7/firewall.pl | 23 | ||||
-rw-r--r-- | 7/main.pl | 12 |
3 files changed, 30 insertions, 12 deletions
@@ -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. @@ -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). |