summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--python/vyos/utils/process.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/python/vyos/utils/process.py b/python/vyos/utils/process.py
index bd0644bc0..60ef87a51 100644
--- a/python/vyos/utils/process.py
+++ b/python/vyos/utils/process.py
@@ -245,3 +245,18 @@ def is_systemd_service_running(service):
Copied from: https://unix.stackexchange.com/a/435317 """
tmp = cmd(f'systemctl show --value -p SubState {service}')
return bool((tmp == 'running'))
+
+def ip_cmd(args, json=True):
+ """ A helper for easily calling iproute2 commands """
+ if json:
+ from json import loads
+ res = cmd(f"ip --json {args}").strip()
+ if res:
+ return loads(res)
+ else:
+ # Many mutation commands like "ip link set"
+ # return an empty string
+ return None
+ else:
+ res = cmd(f"ip {args}")
+ return res