From 676e0a7b282b6408f4e91fbdedab8b95c4a5f2af Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Thu, 18 Nov 2021 17:56:57 +0100 Subject: wwan: T3795: make connect and disconnect op-mode commands aware to WWAN interfaces (cherry picked from commit a032d73f1d405f3bae269791e9064026faa491d9) --- python/vyos/util.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'python/vyos/util.py') diff --git a/python/vyos/util.py b/python/vyos/util.py index 9c4c29322..9aa1f98d2 100644 --- a/python/vyos/util.py +++ b/python/vyos/util.py @@ -931,3 +931,19 @@ def install_into_config(conf, config_paths, override_prompt=True): if count > 0: print(f'{count} value(s) installed. Use "compare" to see the pending changes, and "commit" to apply.') + +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' -- cgit v1.2.3