diff options
author | Harm Weites <harm@weites.com> | 2014-01-23 16:35:33 -0500 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2014-01-23 16:35:33 -0500 |
commit | 8e035f857a06adb5493bbcd35bd427cf2a9e813b (patch) | |
tree | e2f5aa7d6df52b11c242f9e3e4ea2fbf3395de67 /cloudinit/netinfo.py | |
parent | c833a84f08019ba4413937f2f1b1f12a4ffe5632 (diff) | |
parent | 75d6f035bcd94e6420ba6de5a9d12c1f554771cf (diff) | |
download | vyos-cloud-init-8e035f857a06adb5493bbcd35bd427cf2a9e813b.tar.gz vyos-cloud-init-8e035f857a06adb5493bbcd35bd427cf2a9e813b.zip |
Initial Freebsd support
This gets initial support for freebsd.
Diffstat (limited to 'cloudinit/netinfo.py')
-rw-r--r-- | cloudinit/netinfo.py | 48 |
1 files changed, 42 insertions, 6 deletions
diff --git a/cloudinit/netinfo.py b/cloudinit/netinfo.py index feba5a62..63f720e4 100644 --- a/cloudinit/netinfo.py +++ b/cloudinit/netinfo.py @@ -21,6 +21,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. import cloudinit.util as util +import re from prettytable import PrettyTable @@ -40,27 +41,43 @@ def netdev_info(empty=""): toks = line.lower().strip().split() if toks[0] == "up": devs[curdev]['up'] = True + # If the output of ifconfig doesn't contain the required info in the + # obvious place, use a regex filter to be sure. + elif len(toks) > 1: + if re.search("flags=\d+<up,", toks[1]): + devs[curdev]['up'] = True fieldpost = "" if toks[0] == "inet6": fieldpost = "6" for i in range(len(toks)): - if toks[i] == "hwaddr": + if toks[i] == "hwaddr" or toks[i] == "ether": try: devs[curdev]["hwaddr"] = toks[i + 1] except IndexError: pass - for field in ("addr", "bcast", "mask"): + + """ + 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" + } + for origfield, field in ifconfigfields.items(): target = "%s%s" % (field, fieldpost) if devs[curdev].get(target, ""): continue - if toks[i] == "%s:" % field: + if toks[i] == "%s" % origfield: try: devs[curdev][target] = toks[i + 1] except IndexError: pass - elif toks[i].startswith("%s:" % field): + elif toks[i].startswith("%s" % origfield): devs[curdev][target] = toks[i][len(field) + 1:] if empty != "": @@ -73,15 +90,33 @@ def netdev_info(empty=""): def route_info(): - (route_out, _err) = util.subp(["route", "-n"]) + (route_out, _err) = util.subp(["netstat", "-rn"]) routes = [] entries = route_out.splitlines()[1:] for line in entries: if not line: continue toks = line.split() - if len(toks) < 8 or toks[0] == "Kernel" or toks[0] == "Destination": + + """ + FreeBSD shows 6 items in the routing table: + Destination Gateway Flags Refs Use Netif Expire + default 10.65.0.1 UGS 0 34920 vtnet0 + + Linux netstat shows 2 more: + Destination Gateway Genmask Flags MSS Window irtt Iface + 0.0.0.0 10.65.0.1 0.0.0.0 UG 0 0 0 eth0 + """ + + if len(toks) < 6 or toks[0] == "Kernel" or toks[0] == "Destination" or toks[0] == "Internet" or toks[0] == "Internet6" or toks[0] == "Routing": continue + + if len(toks) < 8: + toks.append("-") + toks.append("-") + toks[7] = toks[5] + toks[5] = "-" + entry = { 'destination': toks[0], 'gateway': toks[1], @@ -92,6 +127,7 @@ def route_info(): 'use': toks[6], 'iface': toks[7], } + routes.append(entry) return routes |