# HG changeset patch # User Tero Marttila # Date 1387733076 -7200 # Node ID 9198e2da360e6ddd0f152e023396a2855802f891 # Parent 23b3c066118911fbab1e1442ca3b1f62f0025c19 pvl.hosts-dhcp: omit ethernet-less hosts, change owner comment diff -r 23b3c0661189 -r 9198e2da360e 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 :