Run predown before starting services
This commit is contained in:
parent
bd76f6f6fa
commit
17d3fca3b3
14
woven.py
14
woven.py
|
@ -98,13 +98,15 @@ def generate_wg_configs(config: WovenConfig):
|
||||||
name_a = f"{id_a}-{id_b}-loop"
|
name_a = f"{id_a}-{id_b}-loop"
|
||||||
name_b = f"{id_b}-{id_a}-loop"
|
name_b = f"{id_b}-{id_a}-loop"
|
||||||
|
|
||||||
|
predown_a = [f"ip ro del {node_b.listen_address}/32 dev {node_a.interface_name} via {node_a.listen_gateway} metric 10 src {node_a.listen_address}"]
|
||||||
|
|
||||||
config_a = WireguardConfig(
|
config_a = WireguardConfig(
|
||||||
addresses = [IPv4Interface(f"{ipv4_a}/{ptp_ipv4_network.prefixlen}"), IPv6Interface(f"{ipv6_a}/{ptp_ipv6_network.prefixlen}")],
|
addresses = [IPv4Interface(f"{ipv4_a}/{ptp_ipv4_network.prefixlen}"), IPv6Interface(f"{ipv6_a}/{ptp_ipv6_network.prefixlen}")],
|
||||||
listen_port = port,
|
listen_port = port,
|
||||||
private_key = key_a,
|
private_key = key_a,
|
||||||
table = False,
|
table = False,
|
||||||
preup = [f"ip ro add {node_b.listen_address}/32 dev {node_a.interface_name} via {node_a.listen_gateway} metric 10 src {node_a.listen_address}"],
|
preup = [f"ip ro add {node_b.listen_address}/32 dev {node_a.interface_name} via {node_a.listen_gateway} metric 10 src {node_a.listen_address}"],
|
||||||
predown = [f"ip ro del {node_b.listen_address}/32 dev {node_a.interface_name} via {node_a.listen_gateway} metric 10 src {node_a.listen_address}"],
|
predown = predown_a,
|
||||||
postup = [f"ip ro add {sn} dev {name_a} via {ipv4_b} metric 10" for sn in node_b.routed_ipv4_subnets] +
|
postup = [f"ip ro add {sn} dev {name_a} via {ipv4_b} metric 10" for sn in node_b.routed_ipv4_subnets] +
|
||||||
[f"ip -6 ro add {sn} dev {name_a} via {ipv6_b} metric 10" for sn in node_b.routed_ipv6_subnets],
|
[f"ip -6 ro add {sn} dev {name_a} via {ipv6_b} metric 10" for sn in node_b.routed_ipv6_subnets],
|
||||||
postdown = [f"ip ro del {sn} dev {name_a} via {ipv4_b} metric 10" for sn in node_b.routed_ipv4_subnets] +
|
postdown = [f"ip ro del {sn} dev {name_a} via {ipv4_b} metric 10" for sn in node_b.routed_ipv4_subnets] +
|
||||||
|
@ -120,13 +122,15 @@ def generate_wg_configs(config: WovenConfig):
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
predown_b = [f"ip ro del {node_a.listen_address}/32 dev {node_b.interface_name} via {node_b.listen_gateway} metric 10 src {node_b.listen_address}"]
|
||||||
|
|
||||||
config_b = WireguardConfig(
|
config_b = WireguardConfig(
|
||||||
addresses = [IPv4Interface(f"{ipv4_b}/{ptp_ipv4_network.prefixlen}"), IPv6Interface(f"{ipv6_b}/{ptp_ipv6_network.prefixlen}")],
|
addresses = [IPv4Interface(f"{ipv4_b}/{ptp_ipv4_network.prefixlen}"), IPv6Interface(f"{ipv6_b}/{ptp_ipv6_network.prefixlen}")],
|
||||||
listen_port = port,
|
listen_port = port,
|
||||||
private_key = key_b,
|
private_key = key_b,
|
||||||
table = False,
|
table = False,
|
||||||
preup=[f"ip ro add {node_a.listen_address}/32 dev {node_b.interface_name} via {node_b.listen_gateway} metric 10 src {node_b.listen_address}"],
|
preup = [f"ip ro add {node_a.listen_address}/32 dev {node_b.interface_name} via {node_b.listen_gateway} metric 10 src {node_b.listen_address}"],
|
||||||
predown=[f"ip ro del {node_a.listen_address}/32 dev {node_b.interface_name} via {node_b.listen_gateway} metric 10 src {node_b.listen_address}"],
|
predown = predown_b,
|
||||||
postup = [f"ip ro add {sn} dev {name_b} via {ipv4_a} metric 10" for sn in node_a.routed_ipv4_subnets] +
|
postup = [f"ip ro add {sn} dev {name_b} via {ipv4_a} metric 10" for sn in node_a.routed_ipv4_subnets] +
|
||||||
[f"ip -6 ro add {sn} dev {name_b} via {ipv6_a} metric 10" for sn in node_a.routed_ipv6_subnets],
|
[f"ip -6 ro add {sn} dev {name_b} via {ipv6_a} metric 10" for sn in node_a.routed_ipv6_subnets],
|
||||||
postdown = [f"ip ro del {sn} dev {name_b} via {ipv4_a} metric 10" for sn in node_a.routed_ipv4_subnets] +
|
postdown = [f"ip ro del {sn} dev {name_b} via {ipv4_a} metric 10" for sn in node_a.routed_ipv4_subnets] +
|
||||||
|
@ -144,9 +148,13 @@ def generate_wg_configs(config: WovenConfig):
|
||||||
|
|
||||||
|
|
||||||
cs[id_a].put(StringIO(config_a.to_wgconfig(wgquick_format = True)), f"/etc/wireguard/{name_a}.conf")
|
cs[id_a].put(StringIO(config_a.to_wgconfig(wgquick_format = True)), f"/etc/wireguard/{name_a}.conf")
|
||||||
|
for p in predown_a:
|
||||||
|
cs[id_a].run(p)
|
||||||
cs[id_a].run(f"systemctl start wg-quick@{name_a}.service")
|
cs[id_a].run(f"systemctl start wg-quick@{name_a}.service")
|
||||||
|
|
||||||
cs[id_b].put(StringIO(config_b.to_wgconfig(wgquick_format = True)), f"/etc/wireguard/{name_b}.conf")
|
cs[id_b].put(StringIO(config_b.to_wgconfig(wgquick_format = True)), f"/etc/wireguard/{name_b}.conf")
|
||||||
|
for p in predown_b:
|
||||||
|
cs[id_b].run(p)
|
||||||
cs[id_b].run(f"systemctl start wg-quick@{name_b}.service")
|
cs[id_b].run(f"systemctl start wg-quick@{name_b}.service")
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue