--- a/bin/pvl.hosts-import Mon Dec 16 20:25:32 2013 +0200
+++ b/bin/pvl.hosts-import Mon Dec 16 20:32:16 2013 +0200
@@ -48,6 +48,9 @@
parser.add_option('--import-dhcp-hosts', metavar='FILE',
help="Load hosts from DHCP config")
+ parser.add_option('--import-dhcp-boot-server', metavar='NEXT-SERVER',
+ help="Default boot_server for dpc hosts")
+
parser.add_option('--zone-comments-default-owner', action='store_const',
dest='zone_comments_default', const='owner',
help="Import DNS zone comment as owner comment")
@@ -127,6 +130,9 @@
ethernet = []
fixed_address = None
+ boot_server = options.import_dhcp_boot_server
+ boot_filename = None
+
for item in items :
item, args = item[0], item[1:]
@@ -142,6 +148,10 @@
hostname, = args
else :
log.warn("host %s: ignore unknown option: %s", host, option)
+ elif item == 'next-sever' :
+ boot_server, = args
+ elif item == 'filename' :
+ boot_filename, = args
else :
log.warn("host %s: ignore unknown item: %s", host, item)
@@ -156,12 +166,21 @@
if fixed_address and not re.match(r'\d+\.\d+\.\d+.\d+', fixed_address) :
hostname, domain = fixed_address.split('.', 1)
+ if not (hostname or ethernet) :
+ log.warn("%s: no hostname/ethernet: %s/%s", host, hostname, ethernet)
+ return
+
+ yield hostname, 'ethernet', ethernet
#if suffix :
# yield hostname, ('ethernet', suffix), ethernet
- if hostname and ethernet :
- yield hostname, 'ethernet', ethernet
- else :
- log.warn("%s: no hostname/ethernet: %s/%s", host, hostname, ethernet)
+
+ if boot_server and boot_filename :
+ yield hostname, 'boot', "{server}:{filename}".format(
+ server = boot_server,
+ filename = boot_filename,
+ )
+ elif boot_filename :
+ yield hostname, 'boot', "{filename}".format(filename=boot_filename)
def import_dhcp_hosts (options, blocks) :
"""
@@ -183,7 +202,7 @@
for info in import_dhcp_host(options, host, items) :
yield info
except ValueError as error :
- log.warn("%s: invalid host: %s", host, error)
+ log.exception("%s: invalid host: %s", host, error)
else:
log.warn("ignore unknown block: %s", block)
@@ -443,6 +462,7 @@
('ethernet', None),
('owner', u"\t{field:15} = {value} # {fields[comment-owner][0]}"),
('alias', None),
+ ('boot', None),
) :
if not fmt :
fmt = u"\t{field:15} = {value}"