From e62bac46a13cdf8eb205bf80d21c84d0370bfc30 Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Fri, 28 Jun 2024 13:27:46 +0100 Subject: utils: T6530: add a helper for easily calling iproute2 commands --- python/vyos/utils/process.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'python') 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 -- cgit v1.2.3