summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@vyos.io>2024-06-28 18:17:31 +0200
committerGitHub <noreply@github.com>2024-06-28 18:17:31 +0200
commit690f570d36d2267343fbfb50ac89e8c6e400086a (patch)
treed2e3150fcc12551254af1684d2bf29b1d63ed44d
parentf36271bd2f91aa6cf0bc0176160d3a2abfb9a21f (diff)
parente62bac46a13cdf8eb205bf80d21c84d0370bfc30 (diff)
downloadvyos-1x-690f570d36d2267343fbfb50ac89e8c6e400086a.tar.gz
vyos-1x-690f570d36d2267343fbfb50ac89e8c6e400086a.zip
Merge pull request #3737 from dmbaturin/T6530-iproute2-helper
utils: T6530: add a helper for easily calling iproute2 commands
-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