summaryrefslogtreecommitdiff
path: root/src/op_mode
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@vyos.io>2023-04-10 14:23:36 +0100
committerGitHub <noreply@github.com>2023-04-10 14:23:36 +0100
commit28c01a860582e24aeb0433ca87397542d0dc5f02 (patch)
tree48b430faa88b78b3bb4a1e48ff7d9b46ba9cb817 /src/op_mode
parent14cbda871f7eec20013b6b851316dcec70d2f6d7 (diff)
parent4fac9c122887c91af4e6d51b4e2eb01977196852 (diff)
downloadvyos-1x-28c01a860582e24aeb0433ca87397542d0dc5f02.tar.gz
vyos-1x-28c01a860582e24aeb0433ca87397542d0dc5f02.zip
Merge pull request #1942 from sever-sever/T4770
T4770: Ability to get OpenVPN iface state and description for raw
Diffstat (limited to 'src/op_mode')
-rwxr-xr-xsrc/op_mode/openvpn.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/op_mode/openvpn.py b/src/op_mode/openvpn.py
index 5a1a4914d..d9ae965c5 100755
--- a/src/op_mode/openvpn.py
+++ b/src/op_mode/openvpn.py
@@ -16,6 +16,7 @@
#
#
+import json
import os
import sys
import typing
@@ -25,6 +26,7 @@ import vyos.opmode
from vyos.util import bytes_to_human
from vyos.util import commit_in_progress
from vyos.util import call
+from vyos.util import rc_cmd
from vyos.config import Config
ArgMode = typing.Literal['client', 'server', 'site_to_site']
@@ -142,6 +144,25 @@ def _get_interface_status(mode: str, interface: str) -> dict:
return data
+
+def _get_interface_state(iface):
+ rc, out = rc_cmd(f'ip --json link show dev {iface}')
+ try:
+ data = json.loads(out)
+ except:
+ return 'DOWN'
+ return data[0].get('operstate', 'DOWN')
+
+
+def _get_interface_description(iface):
+ rc, out = rc_cmd(f'ip --json link show dev {iface}')
+ try:
+ data = json.loads(out)
+ except:
+ return ''
+ return data[0].get('ifalias', '')
+
+
def _get_raw_data(mode: str) -> list:
data: list = []
conf = Config()
@@ -154,6 +175,8 @@ def _get_raw_data(mode: str) -> list:
conf_dict[x]['mode'].replace('-', '_') == mode]
for intf in interfaces:
d = _get_interface_status(mode, intf)
+ d['state'] = _get_interface_state(intf)
+ d['description'] = _get_interface_description(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'):