diff options
author | Christian Poessinger <christian@poessinger.com> | 2021-09-25 10:07:29 +0200 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2021-09-25 10:09:49 +0200 |
commit | da45720bf5d5f6165334c1aa3a57d2d31c77b8c7 (patch) | |
tree | 8ec2495f66eebfc88e7dda8f0f5d56d3ff8dd15b /src/etc/dhcp/dhclient-exit-hooks.d | |
parent | d1c58addd881e06b389799a9c14d8ebf5d03c567 (diff) | |
download | vyos-1x-da45720bf5d5f6165334c1aa3a57d2d31c77b8c7.tar.gz vyos-1x-da45720bf5d5f6165334c1aa3a57d2d31c77b8c7.zip |
ipsec: T2816: ipsec-dhclient-hook should use vyos.util.read_file() / write_file()
Diffstat (limited to 'src/etc/dhcp/dhclient-exit-hooks.d')
-rwxr-xr-x | src/etc/dhcp/dhclient-exit-hooks.d/ipsec-dhclient-hook | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/src/etc/dhcp/dhclient-exit-hooks.d/ipsec-dhclient-hook b/src/etc/dhcp/dhclient-exit-hooks.d/ipsec-dhclient-hook index a7a9a2ce6..5cd9321ef 100755 --- a/src/etc/dhcp/dhclient-exit-hooks.d/ipsec-dhclient-hook +++ b/src/etc/dhcp/dhclient-exit-hooks.d/ipsec-dhclient-hook @@ -35,19 +35,14 @@ fi python3 - <<PYEND import os import re + from vyos.util import call from vyos.util import cmd +from vyos.util import read_file +from vyos.util import write_file SWANCTL_CONF="/etc/swanctl/swanctl.conf" -def getlines(file): - with open(file, 'r') as f: - return f.readlines() - -def writelines(file, lines): - with open(file, 'w') as f: - f.writelines(lines) - def ipsec_down(ip_address): # This prevents the need to restart ipsec and kill all active connections, only the stale connection is closed status = cmd('sudo ipsec statusall') @@ -66,7 +61,7 @@ if __name__ == '__main__': new_ip = os.getenv('new_ip_address') old_ip = os.getenv('old_ip_address') - conf_lines = getlines(SWANCTL_CONF) + conf_lines = read_file(SWANCTL_CONF) found = False to_match = f'# dhcp:{interface}' @@ -80,7 +75,7 @@ if __name__ == '__main__': secrets_lines[i] = line.replace(old_ip, new_ip) if found: - writelines(SWANCTL_CONF, conf_lines) + write_file(SWANCTL_CONF, conf_lines) ipsec_down(old_ip) call('sudo ipsec rereadall') call('sudo ipsec reload') |