summaryrefslogtreecommitdiff
path: root/src/op_mode/ipsec.py
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@vyos.io>2022-11-21 14:01:01 +0000
committerGitHub <noreply@github.com>2022-11-21 14:01:01 +0000
commitdc9726636f18ba35b17c16786bc822aa73a878a6 (patch)
tree823ae5952786e3f5d7bdcd3f84b903b57d612f7d /src/op_mode/ipsec.py
parent2e011313a9b5fc1a263e11149f5dd4c904ee42df (diff)
parent97771d427c1660f16122da1260bf28e22e12612d (diff)
downloadvyos-1x-dc9726636f18ba35b17c16786bc822aa73a878a6.tar.gz
vyos-1x-dc9726636f18ba35b17c16786bc822aa73a878a6.zip
Merge pull request #1671 from jestabro/reset-tunnel-arg-optional
IPsec: T4829: tunnel argument to 'reset_peer' should have type hint Optional
Diffstat (limited to 'src/op_mode/ipsec.py')
-rwxr-xr-xsrc/op_mode/ipsec.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/op_mode/ipsec.py b/src/op_mode/ipsec.py
index afe006834..e0d204a0a 100755
--- a/src/op_mode/ipsec.py
+++ b/src/op_mode/ipsec.py
@@ -17,11 +17,13 @@
import os
import re
import sys
+import typing
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
@@ -402,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')