summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2021-11-18 17:56:57 +0100
committerChristian Poessinger <christian@poessinger.com>2021-11-18 18:00:30 +0100
commit676e0a7b282b6408f4e91fbdedab8b95c4a5f2af (patch)
tree10bf03900f9a1af4f75620af212013c32e71ceae /python
parentbe21deb31c3cdb9f221fb3765be13093e40407d8 (diff)
downloadvyos-1x-676e0a7b282b6408f4e91fbdedab8b95c4a5f2af.tar.gz
vyos-1x-676e0a7b282b6408f4e91fbdedab8b95c4a5f2af.zip
wwan: T3795: make connect and disconnect op-mode commands aware to WWAN interfaces
(cherry picked from commit a032d73f1d405f3bae269791e9064026faa491d9)
Diffstat (limited to 'python')
-rw-r--r--python/vyos/util.py16
1 files changed, 16 insertions, 0 deletions
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'