From 9af23d814aa37e90aca350375eeb7b9e83069eee Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Tue, 6 Dec 2022 14:10:21 -0600 Subject: openvpn: T4770: add reset function to openvpn.py --- src/op_mode/openvpn.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/op_mode') diff --git a/src/op_mode/openvpn.py b/src/op_mode/openvpn.py index d66fa08fe..3797a7153 100755 --- a/src/op_mode/openvpn.py +++ b/src/op_mode/openvpn.py @@ -22,6 +22,8 @@ from tabulate import tabulate import vyos.opmode from vyos.util import bytes_to_human +from vyos.util import commit_in_progress +from vyos.util import call from vyos.config import Config def _get_tunnel_address(peer_host, peer_port, status_file): @@ -200,6 +202,14 @@ def show(raw: bool, mode: str) -> str: return _format_openvpn(openvpn_data) +def reset(interface: str): + if os.path.isfile(f'/run/openvpn/{interface}.conf'): + if commit_in_progress(): + raise vyos.opmode.CommitInProgress('Retry OpenVPN reset: commit in progress.') + call(f'systemctl restart openvpn@{interface}.service') + else: + raise vyos.opmode.IncorrectValue(f'OpenVPN interface "{interface}" does not exist!') + if __name__ == '__main__': try: res = vyos.opmode.run(sys.modules[__name__]) -- cgit v1.2.3