From 5acc36948efd4d1dc3d6d33bf2fb67ac4ac80ef6 Mon Sep 17 00:00:00 2001 From: Scott Moser <smoser@ubuntu.com> Date: Wed, 26 Feb 2014 13:14:55 -0500 Subject: netinfo.py: fix regression causing ubuntu to show 'addr:v.x.y.z' after freebsd merge, ubuntu shows addr:v.x.y.z instead of v.x.y.z for the ipv4 address. This should fix that by just skipping the 'inet' (or inet6) token if the next token starts with 'addr:'. LP: #1285185 --- cloudinit/netinfo.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/cloudinit/netinfo.py b/cloudinit/netinfo.py index ac3c011f..30b6f3b3 100644 --- a/cloudinit/netinfo.py +++ b/cloudinit/netinfo.py @@ -52,18 +52,23 @@ def netdev_info(empty=""): fieldpost = "6" for i in range(len(toks)): - if toks[i] == "hwaddr" or toks[i] == "ether": - try: - devs[curdev]["hwaddr"] = toks[i + 1] - except IndexError: - pass + # older net-tools (ubuntu) show 'inet addr:xx.yy', + # newer (freebsd and fedora) show 'inet xx.yy' + # just skip this 'inet' entry. (LP: #1285185) + try: + if (toks[i] in ("inet", "inet6") and + toks[i + 1].startswith("addr:")): + continue + except IndexError: + pass # Couple the different items we're interested in with the correct # field since FreeBSD/CentOS/Fedora differ in the output. ifconfigfields = { "addr:": "addr", "inet": "addr", "bcast:": "bcast", "broadcast": "bcast", - "mask:": "mask", "netmask": "mask" + "mask:": "mask", "netmask": "mask", + "hwaddr": "hwaddr", "ether": "hwaddr", } for origfield, field in ifconfigfields.items(): target = "%s%s" % (field, fieldpost) -- cgit v1.2.3