From 11273157f6511d49c24d14516a44d581e9f3c126 Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Sun, 20 Nov 2022 14:52:25 -0600 Subject: IPsec: T4829: add missing import TimeoutExpired --- src/op_mode/ipsec.py | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/op_mode/ipsec.py b/src/op_mode/ipsec.py index afe006834..3389254e3 100755 --- a/src/op_mode/ipsec.py +++ b/src/op_mode/ipsec.py @@ -22,6 +22,7 @@ from collections import OrderedDict from hurry import filesize from re import split as re_split from tabulate import tabulate +from subprocess import TimeoutExpired from vyos.util import call from vyos.util import convert_data -- cgit v1.2.3 From 97771d427c1660f16122da1260bf28e22e12612d Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Sun, 20 Nov 2022 15:00:22 -0600 Subject: IPsec: T4829: use type hint Optional for arg tunnel in reset_peer --- src/op_mode/ipsec.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/op_mode/ipsec.py b/src/op_mode/ipsec.py index 3389254e3..e0d204a0a 100755 --- a/src/op_mode/ipsec.py +++ b/src/op_mode/ipsec.py @@ -17,6 +17,7 @@ import os import re import sys +import typing from collections import OrderedDict from hurry import filesize @@ -403,23 +404,27 @@ def _get_formatted_output_conections(data): # Connections block end -def get_peer_connections(peer, tunnel, return_all = False): +def get_peer_connections(peer, tunnel): search = rf'^[\s]*({peer}-(tunnel-[\d]+|vti)).*' matches = [] if not os.path.exists(SWANCTL_CONF): raise vyos.opmode.UnconfiguredSubsystem("IPsec not initialized") + suffix = None if tunnel is None else (f'tunnel-{tunnel}' if + tunnel.isnumeric() else tunnel) with open(SWANCTL_CONF, 'r') as f: for line in f.readlines(): result = re.match(search, line) if result: - suffix = f'tunnel-{tunnel}' if tunnel.isnumeric() else tunnel - if return_all or (result[2] == suffix): + if tunnel is None: matches.append(result[1]) + else: + if result[2] == suffix: + matches.append(result[1]) return matches -def reset_peer(peer: str, tunnel:str): - conns = get_peer_connections(peer, tunnel, return_all = (not tunnel or tunnel == 'all')) +def reset_peer(peer: str, tunnel:typing.Optional[str]): + conns = get_peer_connections(peer, tunnel) if not conns: raise vyos.opmode.IncorrectValue('Peer or tunnel(s) not found, aborting') -- cgit v1.2.3