diff options
author | Christian Poessinger <christian@poessinger.com> | 2021-11-18 17:56:57 +0100 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2021-11-18 17:59:10 +0100 |
commit | a032d73f1d405f3bae269791e9064026faa491d9 (patch) | |
tree | afc5d75fc6bacbea16557c63cd1c7666ff1dff8f /python | |
parent | e1539b6fffaf10863e41a73a380f9de40f6aece6 (diff) | |
download | vyos-1x-a032d73f1d405f3bae269791e9064026faa491d9.tar.gz vyos-1x-a032d73f1d405f3bae269791e9064026faa491d9.zip |
wwan: T3795: make connect and disconnect op-mode commands aware to WWAN interfaces
Diffstat (limited to 'python')
-rw-r--r-- | python/vyos/util.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/python/vyos/util.py b/python/vyos/util.py index 9f01d504d..1834b78bd 100644 --- a/python/vyos/util.py +++ b/python/vyos/util.py @@ -717,3 +717,19 @@ 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 is_wwan_connected(interface): + """ Determine if a given WWAN interface, e.g. wwan0 is connected to the + carrier network or not """ + import json + + if not interface.startswith('wwan'): + raise ValueError(f'Specified interface "{interface}" is not a WWAN interface') + + modem = interface.lstrip('wwan') + + tmp = cmd(f'mmcli --modem {modem} --output-json') + tmp = json.loads(tmp) + + # return True/False if interface is in connected state + return dict_search('modem.generic.state', tmp) == 'connected' |