diff -r a720bcf96007 -r b41902b0b9cf bin/pvl.hosts-import --- a/bin/pvl.hosts-import Tue Dec 17 10:25:07 2013 +0200 +++ b/bin/pvl.hosts-import Tue Dec 17 10:25:44 2013 +0200 @@ -42,21 +42,21 @@ help="Encoding used for output files") # input - parser.add_option('--import-zone-hosts', metavar='FILE', + parser.add_option('--import-zone-hosts', metavar='FILE', action='append', help="Load hosts from DNS zone") - parser.add_option('--import-dhcp-hosts', metavar='FILE', + parser.add_option('--import-dhcp-hosts', metavar='FILE', action='append', 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', + parser.add_option('--import-zone-comments-owner', action='store_const', + dest='import_zone_comments', const='owner', help="Import DNS zone comment as owner comment") - parser.add_option('--zone-comments-default-host', action='store_const', - dest='zone_comments_default', const='host', + parser.add_option('--import-zone-comments-host', action='store_const', + dest='import_zone_comments', const='host', help="Import DNS zone comment as host comment") parser.add_option('--dump-host-comments', action='store_true', @@ -78,7 +78,8 @@ # defaults parser.set_defaults( - + import_zone_hosts = [], + import_dhcp_hosts = [], ) # parse @@ -120,6 +121,11 @@ host, = rr.data yield host, 'alias', rr.name + + elif rr.type == 'TXT' : + txt, = rr.data + + yield host, 'comment', txt else : log.warn("%s: unknown rr: %s", rr.name, rr) @@ -191,15 +197,17 @@ """ for block, items, blocks in blocks : - log.info("%s", block) block, args = block[0], block[1:] if block == 'group' : + log.info("group") for info in import_dhcp_hosts(options, blocks) : yield info elif block == 'host' : host, = args + + log.info("host: %s", host) try : for info in import_dhcp_host(options, host, items) : @@ -250,9 +258,9 @@ log.info("%s: matched comment: %s", hostname, comment) break else : - if options.zone_comments_default : + if options.import_zone_comments : log.info("%s: default comment: %s", hostname, comment) - matches = { options.zone_comments_default: comment } + matches = { options.import_zone_comments: comment } else : log.warn("%s: unknown comment: %s", hostname, comment) return @@ -395,14 +403,14 @@ Import host infos from given files. """ - if options.import_zone_hosts: - for info in import_zone_hosts(options, - pvl.args.apply_file(options.import_zone_hosts, 'r', options.input_charset)) : + for zone_file in options.import_zone_hosts: + file = pvl.args.apply_file(zone_file, 'r', options.input_charset) + for info in import_zone_hosts(options, file) : yield info - if options.import_dhcp_hosts: - for info in import_dhcp_conf(options, - pvl.args.apply_file(options.import_dhcp_hosts, 'r', options.input_charset)) : + for dhcp_file in options.import_dhcp_hosts: + file = pvl.args.apply_file(dhcp_file, 'r', options.input_charset) + for info in import_dhcp_conf(options, file) : yield info def import_hosts (options) :