diff options
author | Daniil Baturin <daniil@vyos.io> | 2023-03-20 14:04:50 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-20 14:04:50 +0000 |
commit | 71cea18861d05c146af77120c73d93ca95bfb5d1 (patch) | |
tree | dbcfca633890da7ba4badee68475e51624d861d7 /src/op_mode/openvpn.py | |
parent | c820be57b6c77cdb0a5055d0c3a77dc8d550e2d7 (diff) | |
parent | 15bf5d64440abaf50083ed5a4e1efdbf0d6cbad5 (diff) | |
download | vyos-1x-71cea18861d05c146af77120c73d93ca95bfb5d1.tar.gz vyos-1x-71cea18861d05c146af77120c73d93ca95bfb5d1.zip |
Merge pull request #1896 from jestabro/raw-list-openvpn
openvpn: T5095: raw output should return list instead of dict
Diffstat (limited to 'src/op_mode/openvpn.py')
-rwxr-xr-x | src/op_mode/openvpn.py | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/src/op_mode/openvpn.py b/src/op_mode/openvpn.py index 8f88ab422..7ae49472e 100755 --- a/src/op_mode/openvpn.py +++ b/src/op_mode/openvpn.py @@ -53,7 +53,7 @@ def _get_tunnel_address(peer_host, peer_port, status_file): def _get_interface_status(mode: str, interface: str) -> dict: status_file = f'/run/openvpn/{interface}.status' - data = { + data: dict = { 'mode': mode, 'intf': interface, 'local_host': '', @@ -142,8 +142,8 @@ def _get_interface_status(mode: str, interface: str) -> dict: return data -def _get_raw_data(mode: str) -> dict: - data = {} +def _get_raw_data(mode: str) -> list: + data: list = [] conf = Config() conf_dict = conf.get_config_dict(['interfaces', 'openvpn'], get_first_key=True) @@ -152,8 +152,7 @@ def _get_raw_data(mode: str) -> dict: interfaces = [x for x in list(conf_dict) if conf_dict[x]['mode'] == mode] for intf in interfaces: - data[intf] = _get_interface_status(mode, intf) - d = data[intf] + d = _get_interface_status(mode, intf) d['local_host'] = conf_dict[intf].get('local-host', '') d['local_port'] = conf_dict[intf].get('local-port', '') if conf.exists(f'interfaces openvpn {intf} server client'): @@ -164,10 +163,11 @@ def _get_raw_data(mode: str) -> dict: client['name'] = 'None (PSK)' client['remote_host'] = conf_dict[intf].get('remote-host', [''])[0] client['remote_port'] = conf_dict[intf].get('remote-port', '1194') + data.append(d) return data -def _format_openvpn(data: dict) -> str: +def _format_openvpn(data: list) -> str: if not data: out = 'No OpenVPN interfaces configured' return out @@ -176,11 +176,12 @@ def _format_openvpn(data: dict) -> str: 'TX bytes', 'RX bytes', 'Connected Since'] out = '' - for intf in list(data): + for d in data: data_out = [] - l_host = data[intf]['local_host'] - l_port = data[intf]['local_port'] - for client in list(data[intf]['clients']): + intf = d['intf'] + l_host = d['local_host'] + l_port = d['local_port'] + for client in d['clients']: r_host = client['remote_host'] r_port = client['remote_port'] @@ -201,7 +202,7 @@ def _format_openvpn(data: dict) -> str: return out -def show(raw: bool, mode: ArgMode) -> str: +def show(raw: bool, mode: ArgMode) -> typing.Union[list,str]: openvpn_data = _get_raw_data(mode) if raw: |