diff options
author | zsdc <taras@vyos.io> | 2021-08-26 23:18:29 +0300 |
---|---|---|
committer | zsdc <taras@vyos.io> | 2021-08-26 23:18:29 +0300 |
commit | eb11d4b688d883d0c1d150b00eee40b54df42b32 (patch) | |
tree | 271446b3fbedca66da86afc42fc1d2d03d04dfb1 /src/conf_mode/interfaces-wireguard.py | |
parent | 4523e9c897b3fa8d12c1b16c830c01820fee5583 (diff) | |
download | vyos-1x-eb11d4b688d883d0c1d150b00eee40b54df42b32.tar.gz vyos-1x-eb11d4b688d883d0c1d150b00eee40b54df42b32.zip |
vyos.util: T3763: Optimized the check_port_availability function
`print` was removed or replaced to `ValueError`, where possible.
Diffstat (limited to 'src/conf_mode/interfaces-wireguard.py')
-rwxr-xr-x | src/conf_mode/interfaces-wireguard.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/conf_mode/interfaces-wireguard.py b/src/conf_mode/interfaces-wireguard.py index ad3ddcba2..68181465e 100755 --- a/src/conf_mode/interfaces-wireguard.py +++ b/src/conf_mode/interfaces-wireguard.py @@ -74,9 +74,12 @@ def verify(wireguard): if 'peer' not in wireguard: raise ConfigError('At least one Wireguard peer is required!') - if 'port' in wireguard and check_port_availability( - '0.0.0.0', int(wireguard['port']), 'udp') is not True: - raise ConfigError('The port cannot be used for the interface') + listen_port = int(wireguard['port']) + if 'port' in wireguard and check_port_availability('0.0.0.0', listen_port, + 'udp') is not True: + raise ConfigError( + f'The UDP port {listen_port} is busy or unavailable and cannot be used for the interface' + ) # run checks on individual configured WireGuard peer for tmp in wireguard['peer']: |