Add postdown commands before systemctl start
This commit is contained in:
parent
676934c175
commit
c608379ec2
20
woven.py
20
woven.py
|
@ -99,6 +99,8 @@ def generate_wg_configs(config: WovenConfig):
|
|||
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}"]
|
||||
postup_a = [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]
|
||||
postdown_a = [f"ip ro del {sn} dev {name_a} via {ipv4_b} metric 10" for sn in node_b.routed_ipv4_subnets] + [f"ip -6 ro del {sn} dev {name_a} via {ipv6_b} metric 10" for sn in node_b.routed_ipv6_subnets]
|
||||
|
||||
config_a = WireguardConfig(
|
||||
addresses = [IPv4Interface(f"{ipv4_a}/{ptp_ipv4_network.prefixlen}"), IPv6Interface(f"{ipv6_a}/{ptp_ipv6_network.prefixlen}")],
|
||||
|
@ -107,10 +109,8 @@ def generate_wg_configs(config: WovenConfig):
|
|||
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}"],
|
||||
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] +
|
||||
[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] +
|
||||
[f"ip -6 ro del {sn} dev {name_a} via {ipv6_b} metric 10" for sn in node_b.routed_ipv6_subnets],
|
||||
postup = postup_a,
|
||||
postdown = postdown_a,
|
||||
peers = {
|
||||
key_b_pub: WireguardPeer(
|
||||
public_key = key_b_pub,
|
||||
|
@ -123,6 +123,8 @@ 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}"]
|
||||
postup_b = [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]
|
||||
postdown_b = [f"ip ro del {sn} dev {name_b} via {ipv4_a} metric 10" for sn in node_a.routed_ipv4_subnets] + [f"ip -6 ro del {sn} dev {name_b} via {ipv6_a} metric 10" for sn in node_a.routed_ipv6_subnets]
|
||||
|
||||
config_b = WireguardConfig(
|
||||
addresses = [IPv4Interface(f"{ipv4_b}/{ptp_ipv4_network.prefixlen}"), IPv6Interface(f"{ipv6_b}/{ptp_ipv6_network.prefixlen}")],
|
||||
|
@ -131,10 +133,8 @@ def generate_wg_configs(config: WovenConfig):
|
|||
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}"],
|
||||
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] +
|
||||
[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] +
|
||||
[f"ip -6 ro del {sn} dev {name_b} via {ipv6_a} metric 10" for sn in node_a.routed_ipv6_subnets],
|
||||
postup = postup_b,
|
||||
postdown = postdown_b,
|
||||
peers = {
|
||||
key_a_pub: WireguardPeer(
|
||||
public_key = key_a_pub,
|
||||
|
@ -148,7 +148,7 @@ def generate_wg_configs(config: WovenConfig):
|
|||
|
||||
|
||||
cs[id_a].put(StringIO(config_a.to_wgconfig(wgquick_format = True)), f"/etc/wireguard/{name_a}.conf")
|
||||
for p in predown_a:
|
||||
for p in predown_a + postdown_a:
|
||||
try:
|
||||
cs[id_a].run(p)
|
||||
except UnexpectedExit:
|
||||
|
@ -156,7 +156,7 @@ def generate_wg_configs(config: WovenConfig):
|
|||
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")
|
||||
for p in predown_b:
|
||||
for p in predown_b + postdown_b:
|
||||
try:
|
||||
cs[id_b].run(p)
|
||||
except UnexpectedExit:
|
||||
|
|
Loading…
Reference in New Issue