summaryrefslogtreecommitdiff
path: root/cloudinit/netinfo.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2012-01-20 08:44:45 -0500
committerScott Moser <smoser@ubuntu.com>2012-01-20 08:44:45 -0500
commit3e323d8ee067c418c592ebd5e3a6271d18422296 (patch)
tree927139947e1916e525b42f27ff8fef939b8d8bdf /cloudinit/netinfo.py
parent2465470c9133041a3b7f5963c579a0f680390ffb (diff)
downloadvyos-cloud-init-3e323d8ee067c418c592ebd5e3a6271d18422296.tar.gz
vyos-cloud-init-3e323d8ee067c418c592ebd5e3a6271d18422296.zip
in netinfo output (ci-info:), fill in empty fields with a "."
If you were trying to parse this output with something, an empty field would be difficult to handle, as you'd have to know the expected lengths of each field. The '.' means empty, but then all fields are non-whitespace delimited by one or more whitespace.
Diffstat (limited to 'cloudinit/netinfo.py')
-rw-r--r--cloudinit/netinfo.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/cloudinit/netinfo.py b/cloudinit/netinfo.py
index be7ed3a9..80223256 100644
--- a/cloudinit/netinfo.py
+++ b/cloudinit/netinfo.py
@@ -22,7 +22,7 @@
import subprocess
-def netdev_info():
+def netdev_info(empty=""):
fields = ("hwaddr", "addr", "bcast", "mask")
ifcfg_out = str(subprocess.check_output(["ifconfig", "-a"]))
devs = {}
@@ -59,6 +59,13 @@ def netdev_info():
pass
elif toks[i].startswith("%s:" % field):
devs[curdev][target] = toks[i][len(field) + 1:]
+
+ if empty != "":
+ for (devname, dev) in devs.iteritems():
+ for field in dev:
+ if dev[field] == "":
+ dev[field] = empty
+
return(devs)
@@ -85,7 +92,7 @@ def getgateway():
def debug_info(pre="ci-info: "):
lines = []
try:
- netdev = netdev_info()
+ netdev = netdev_info(empty=".")
except Exception:
lines.append("netdev_info failed!")
netdev = {}