diff options
author | kroy <kroy@kroy.io> | 2019-10-22 14:22:09 -0500 |
---|---|---|
committer | kroy <kroy@kroy.io> | 2019-10-22 14:22:09 -0500 |
commit | 091f68baec1b732bc28a203419be04b8e9b985e4 (patch) | |
tree | 65398648422bd3929552d1b63d51d835027769d9 /python/vyos/interfaces.py | |
parent | 4ed6e7bf28eb409228008eb6ea4adab7837c71cd (diff) | |
download | vyos-1x-091f68baec1b732bc28a203419be04b8e9b985e4.tar.gz vyos-1x-091f68baec1b732bc28a203419be04b8e9b985e4.zip |
T1759: Migrating interfaces
Diffstat (limited to 'python/vyos/interfaces.py')
-rw-r--r-- | python/vyos/interfaces.py | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/python/vyos/interfaces.py b/python/vyos/interfaces.py index d69ce9d04..ecf061d17 100644 --- a/python/vyos/interfaces.py +++ b/python/vyos/interfaces.py @@ -16,9 +16,9 @@ import re import json +import subprocess import netifaces - intf_type_data_file = '/usr/share/vyos/interface-types.json' def list_interfaces(): @@ -54,3 +54,46 @@ def get_type_of_interface(intf): return key raise ValueError("No type found for interface name: {0}".format(intf)) + +def wireguard_dump(): + """Dump wireguard data in a python friendly way.""" + last_device=None + output = {} + + # Dump wireguard connection data + _f = subprocess.check_output(["wg", "show", "all", "dump"]).decode() + for line in _f.split('\n'): + if not line: + # Skip empty lines and last line + continue + items = line.split('\t') + + if last_device != items[0]: + # We are currently entering a new node + device, private_key, public_key, listen_port, fw_mark = items + last_device = device + + output[device] = { + 'private_key': None if private_key == '(none)' else private_key, + 'public_key': None if public_key == '(none)' else public_key, + 'listen_port': int(listen_port), + 'fw_mark': None if fw_mark == 'off' else int(fw_mark), + 'peers': {}, + } + else: + # We are entering a peer + device, public_key, preshared_key, endpoint, allowed_ips, latest_handshake, transfer_rx, transfer_tx, persistent_keepalive = items + if allowed_ips == '(none)': + allowed_ips = [] + else: + allowed_ips = allowed_ips.split('\t') + output[device]['peers'][public_key] = { + 'preshared_key': None if preshared_key == '(none)' else preshared_key, + 'endpoint': None if endpoint == '(none)' else endpoint, + 'allowed_ips': allowed_ips, + 'latest_handshake': None if latest_handshake == '0' else int(latest_handshake), + 'transfer_rx': int(transfer_rx), + 'transfer_tx': int(transfer_tx), + 'persistent_keepalive': None if persistent_keepalive == 'off' else int(persistent_keepalive), + } + return output |