summaryrefslogtreecommitdiff
path: root/cloudinit/netinfo.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2012-01-17 14:41:29 -0500
committerScott Moser <smoser@ubuntu.com>2012-01-17 14:41:29 -0500
commit15e3241ba725a21604e0f3570e755a91b5edba00 (patch)
treed84be61c3a56ddc03eb927d5de5433afacadf64b /cloudinit/netinfo.py
parent2f7227c7092ad873757167f62c2a82fb4ee69472 (diff)
downloadcloud-init-git-15e3241ba725a21604e0f3570e755a91b5edba00.tar.gz
[PATCH] PEP8 coding style fixes.
From: Juerg Haefliger <juerg.haefliger@hp.com> This pulls in the named patch for LP: #914739 with a few other changes.
Diffstat (limited to 'cloudinit/netinfo.py')
-rw-r--r--cloudinit/netinfo.py27
1 files changed, 16 insertions, 11 deletions
diff --git a/cloudinit/netinfo.py b/cloudinit/netinfo.py
index 9cfd5ba3..40bfa7ea 100644
--- a/cloudinit/netinfo.py
+++ b/cloudinit/netinfo.py
@@ -1,15 +1,16 @@
import subprocess
+
def netdev_info():
- fields = ( "hwaddr", "addr", "bcast", "mask" )
- ifcfg_out = subprocess.check_output(["ifconfig", "-a"])
- devs = { }
+ fields = ("hwaddr", "addr", "bcast", "mask")
+ ifcfg_out = str(subprocess.check_output(["ifconfig", "-a"]))
+ devs = {}
for line in ifcfg_out.splitlines():
if len(line) == 0:
continue
if line[0] not in ("\t", " "):
curdev = line.split()[0]
- devs[curdev] = { "up": False }
+ devs[curdev] = {"up": False}
for field in fields:
devs[curdev][field] = ""
toks = line.lower().strip().split()
@@ -23,7 +24,7 @@ def netdev_info():
for i in range(len(toks)):
if toks[i] == "hwaddr":
try:
- devs[curdev]["hwaddr"] = toks[i+1]
+ devs[curdev]["hwaddr"] = toks[i + 1]
except IndexError:
pass
for field in ("addr", "bcast", "mask"):
@@ -32,16 +33,17 @@ def netdev_info():
continue
if toks[i] == "%s:" % field:
try:
- devs[curdev][target] = toks[i+1]
+ devs[curdev][target] = toks[i + 1]
except IndexError:
pass
elif toks[i].startswith("%s:" % field):
- devs[curdev][target] = toks[i][len(field)+1:]
+ devs[curdev][target] = toks[i][len(field) + 1:]
return(devs)
+
def route_info():
- route_out = subprocess.check_output(["route", "-n"])
- routes = [ ]
+ route_out = str(subprocess.check_output(["route", "-n"]))
+ routes = []
for line in route_out.splitlines()[1:]:
if not line:
continue
@@ -51,14 +53,16 @@ def route_info():
routes.append(toks)
return(routes)
+
def getgateway():
for r in route_info():
if r[3].find("G") >= 0:
return("%s[%s]" % (r[1], r[7]))
return(None)
+
def debug_info(pre="ci-info: "):
- lines = [ ]
+ lines = []
try:
netdev = netdev_info()
except Exception:
@@ -76,8 +80,9 @@ def debug_info(pre="ci-info: "):
for r in routes:
lines.append("%sroute-%d: %-15s %-15s %-15s %-6s %s" %
(pre, n, r[0], r[1], r[2], r[7], r[3]))
- n = n+1
+ n = n + 1
return('\n'.join(lines))
+
if __name__ == '__main__':
print debug_info()