pvl.hosts-dhcp: omit ethernet-less hosts, change owner comment
authorTero Marttila <terom@paivola.fi>
Sun, 22 Dec 2013 19:24:36 +0200
changeset 338 9198e2da360e
parent 337 23b3c0661189
child 339 5c3359ce44e1
child 341 82905d6bfb7a
pvl.hosts-dhcp: omit ethernet-less hosts, change owner comment
bin/pvl.hosts-dhcp
--- a/bin/pvl.hosts-dhcp	Sun Dec 22 19:21:00 2013 +0200
+++ b/bin/pvl.hosts-dhcp	Sun Dec 22 19:24:36 2013 +0200
@@ -25,39 +25,42 @@
         return '"{value}"'.format(value=value)
 
 def process_host (options, host) :
-        if host.owner :
-            yield u"# {host.owner}".format(host=host)
-
-        if host.boot :
-            if ':' in host.boot :
-                next_server, filename = host.boot.split(':', 1)
-            elif host.boot.startswith('/') :
-                next_server = None
-                filename = host.boot
-            elif host.boot.endswith(':') :
-                next_server = host.boot
-                filename = None
-            else :
-                log.error("%s: invalid boot: %s", host, host.boot)
+    if host.boot :
+        if ':' in host.boot :
+            next_server, filename = host.boot.split(':', 1)
+        elif host.boot.startswith('/') :
+            next_server = None
+            filename = host.boot
+        elif host.boot.endswith(':') :
+            next_server = host.boot
+            filename = None
         else :
-            next_server = filename = None
-
-        if set(host.ethernet) == set([0]) :
-            host_fmt = "{host}"
-        else :
-            host_fmt = "{host}-{index}"
+            log.error("%s: invalid boot: %s", host, host.boot)
+    else :
+        next_server = filename = None
 
-        for index, ethernet in host.ethernet.iteritems() :
-            for line in build_host(host_fmt.format(host=host, index=index),
-                    { 'option host-name':   dhcp_quote(host) },
-                    { 'hardware ethernet':  ethernet },
-                    { 'fixed-address':      host.ip },
-                    { 'next-server':        next_server },
-                    { 'filename':           dhcp_quote(filename) },
-            ) :
-                yield line
+    if set(host.ethernet) == set([0]) :
+        host_fmt = "{host}"
+    elif host.ethernet :
+        host_fmt = "{host}-{index}"
+    else :
+        # nothing there
+        return
 
-        yield ""
+    if host.owner :
+        yield u"# Owner: {host.owner}".format(host=host)
+
+    for index, ethernet in host.ethernet.iteritems() :
+        for line in build_host(host_fmt.format(host=host, index=index),
+                { 'option host-name':   dhcp_quote(host) },
+                { 'hardware ethernet':  ethernet },
+                { 'fixed-address':      host.ip },
+                { 'next-server':        next_server },
+                { 'filename':           dhcp_quote(filename) },
+        ) :
+            yield line
+
+    yield ""
     
 def process_hosts (options, hosts) :
     for host in hosts :