diff options
author | Daniil Baturin <daniil@baturin.org> | 2024-06-28 13:27:46 +0100 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2024-06-28 13:34:13 +0100 |
commit | e62bac46a13cdf8eb205bf80d21c84d0370bfc30 (patch) | |
tree | a7cbeca166b86a268418c5b4438236c84b1a307d /python/vyos | |
parent | 57c24a8fd22929a7e38c3ada1d1db8863d6c38f6 (diff) | |
download | vyos-1x-e62bac46a13cdf8eb205bf80d21c84d0370bfc30.tar.gz vyos-1x-e62bac46a13cdf8eb205bf80d21c84d0370bfc30.zip |
utils: T6530: add a helper for easily calling iproute2 commands
Diffstat (limited to 'python/vyos')
-rw-r--r-- | python/vyos/utils/process.py | 15 |
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 |