summaryrefslogtreecommitdiff
path: root/bin
diff options
authorJonathan Cave <jonathan.cave@canonical.com>2019-05-30 10:59:01 +0100
committerJonathan Cave <jonathan.cave@canonical.com>2019-05-30 10:59:01 +0100
commit031f705cdc8c54bfe6f8fed80b0110a72ff1ccbc (patch)
tree75a8cf60fbe418d598bce988baa4941a091a89a3 /bin
parentf6c2e95152a8ad2fd77b68a8b1d7946be056fbaf (diff)
network_device_info: handle missing udev attrs
Diffstat (limited to 'bin')
-rwxr-xr-xbin/network_device_info.py26
1 files changed, 14 insertions, 12 deletions
diff --git a/bin/network_device_info.py b/bin/network_device_info.py
index e36c201..4a827de 100755
--- a/bin/network_device_info.py
+++ b/bin/network_device_info.py
@@ -307,18 +307,20 @@ class UdevDevices():
"""Convert to list of NetworkDevice with UDev derived attrs set"""
for device in self._devices:
nd = NetworkDeviceInfo()
- nd.category = getattr(device, 'category')
- nd.interface = getattr(device, 'interface')
- nd.product = getattr(device, 'product')
- nd.vendor = getattr(device, 'vendor')
- nd.driver = getattr(device, 'driver')
- nd.path = getattr(device, 'path')
- nd.id = '[{0:04x}:{1:04x}]'.format(
- getattr(device, 'vendor_id'),
- getattr(device, 'product_id'))
- nd.subsystem_id = '[{0:04x}:{1:04x}]'.format(
- getattr(device, 'subvendor_id'),
- getattr(device, 'subproduct_id'))
+ nd.category = getattr(device, 'category', None)
+ nd.interface = getattr(device, 'interface', None)
+ nd.product = getattr(device, 'product', None)
+ nd.vendor = getattr(device, 'vendor', None)
+ nd.driver = getattr(device, 'driver', None)
+ nd.path = getattr(device, 'path', None)
+ vid = getattr(device, 'vendor_id', None)
+ pid = getattr(device, 'product_id', None)
+ if vid and pid:
+ nd.id = '[{0:04x}:{1:04x}]'.format(vid, pid)
+ svid = getattr(device, 'subvendor_id', None)
+ spid = getattr(device, 'subproduct_id', None)
+ if svid and spid:
+ nd.subsystem_id = '[{0:04x}:{1:04x}]'.format(svid, spid)
yield nd