diff -ru cloud-init-0.7.6/cloudinit/netinfo.py cloud-init-0.7.6-modify/cloudinit/netinfo.py
--- cloud-init-0.7.6/cloudinit/netinfo.py 2014-10-10 08:26:25.000000000 -0700
+++ cloud-init-0.7.6-modify/cloudinit/netinfo.py 2015-09-17 15:05:41.299270875 -0700
@@ -93,49 +93,50 @@
return devs
-
def route_info():
- (route_out, _err) = util.subp(["netstat", "-rn"])
+ (route_out, _err) = util.subp(["ip", "route"])
routes = []
- entries = route_out.splitlines()[1:]
+ entries = route_out.splitlines()
for line in entries:
if not line:
continue
toks = line.split()
-
- # 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] = "-"
+ dest = toks[0].split('/')
+ listlen = len(dest)
+ if listlen == 1:
+ subnet = "32"
+ else:
+ subnet = dest[1]
+ if toks[0] == "default":
+ gat = toks[2]
+ mask = "0.0.0.0"
+ dest[0] = "0.0.0.0"
+ dev = toks[4]
+ df = "yes"
+ else:
+ gat = "0.0.0.0"
+ dev = toks[2]
+ df = "no"
+
+ if subnet == "32":
+ mask = "255.255.255.255"
+ if subnet == "24":
+ mask = "255.255.255.0"
+ if subnet == "16":
+ mask = "255.255.0.0"
+ if subnet == "8":
+ mask = "255.0.0.0"
entry = {
- 'destination': toks[0],
- 'gateway': toks[1],
- 'genmask': toks[2],
- 'flags': toks[3],
- 'metric': toks[4],
- 'ref': toks[5],
- 'use': toks[6],
- 'iface': toks[7],
+ 'destination': dest[0],
+ 'gateway': gat,
+ 'genmask': mask,
+ 'iface': dev,
+ 'DefGateway': df,
}
-
routes.append(entry)
return routes
-
def getgateway():
routes = []
try:
@@ -143,11 +144,10 @@
except:
pass
for r in routes:
- if r['flags'].find("G") >= 0:
+ if r['DefGateway'] == "yes":
return "%s[%s]" % (r['gateway'], r['iface'])
return None
-
def netdev_pformat():
lines = []
try:
@@ -177,13 +177,13 @@
routes = None
if routes is not None:
fields = ['Route', 'Destination', 'Gateway',
- 'Genmask', 'Interface', 'Flags']
+ 'Genmask', 'Interface', 'IsDefaultGateway']
tbl = PrettyTable(fields)
for (n, r) in enumerate(routes):
route_id = str(n)
tbl.add_row([route_id, r['destination'],
r['gateway'], r['genmask'],
- r['iface'], r['flags']])
+ r['iface'], r['DefGateway']])
route_s = tbl.get_string()
max_len = len(max(route_s.splitlines(), key=len))
header = util.center("Route info", "+", max_len)