summaryrefslogtreecommitdiff
diff options
authorJeff Lane <jeffrey.lane@canonical.com>2019-10-30 11:24:29 -0400
committerJeff Lane <jeffrey.lane@canonical.com>2019-10-30 11:24:29 -0400
commitedc6810d81e11e6d2759c4306595e16e0a695de3 (patch)
treefa0da3449ccd20511120a076826a9aafc99d58e8
parent6924462a362fd91cd0fb547d52ad411424b08613 (diff)
Fix bug that causes traceback in bin/network_device_info.py when ipv4 is not configured for an interface. LP: #1850652
-rwxr-xr-xbin/network_device_info.py18
1 files changed, 13 insertions, 5 deletions
diff --git a/bin/network_device_info.py b/bin/network_device_info.py
index 4a827def..18747721 100755
--- a/bin/network_device_info.py
+++ b/bin/network_device_info.py
@@ -49,11 +49,18 @@ class Utils():
@staticmethod
def get_ipv4_address(interface):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
- return socket.inet_ntoa(fcntl.ioctl(
- s.fileno(),
- 0x8915, # SIOCGIFADDR
- struct.pack('256s', interface[:15].encode())
- )[20:24])
+ try:
+ ipv4_addr = socket.inet_ntoa(fcntl.ioctl(
+ s.fileno(),
+ 0x8915, # SIOCGIFADDR
+ struct.pack('256s', interface[:15].encode())
+ )[20:24])
+ except Exception as e:
+ print("ERROR: getting the IPv4 address for %s: %s" %
+ (interface, repr(e)))
+ ipv4_addr = "***NOT CONFIGURED***"
+ finally:
+ return ipv4_addr
@staticmethod
def get_ipv6_address(interface):
@@ -362,6 +369,7 @@ if __name__ == "__main__":
# Report udev detected devices first
print("[ Devices found by udev ]".center(80, '-'))
+ print("DEBUG: %s" % udev.devices())
for device in udev.devices():
print(device)