45 parser.add_option('--import-zone-hosts', metavar='FILE', |
45 parser.add_option('--import-zone-hosts', metavar='FILE', |
46 help="Load hosts from DNS zone") |
46 help="Load hosts from DNS zone") |
47 |
47 |
48 parser.add_option('--import-dhcp-hosts', metavar='FILE', |
48 parser.add_option('--import-dhcp-hosts', metavar='FILE', |
49 help="Load hosts from DHCP config") |
49 help="Load hosts from DHCP config") |
|
50 |
|
51 parser.add_option('--import-dhcp-boot-server', metavar='NEXT-SERVER', |
|
52 help="Default boot_server for dpc hosts") |
50 |
53 |
51 parser.add_option('--zone-comments-default-owner', action='store_const', |
54 parser.add_option('--zone-comments-default-owner', action='store_const', |
52 dest='zone_comments_default', const='owner', |
55 dest='zone_comments_default', const='owner', |
53 help="Import DNS zone comment as owner comment") |
56 help="Import DNS zone comment as owner comment") |
54 |
57 |
140 |
146 |
141 if option == 'host-name' : |
147 if option == 'host-name' : |
142 hostname, = args |
148 hostname, = args |
143 else : |
149 else : |
144 log.warn("host %s: ignore unknown option: %s", host, option) |
150 log.warn("host %s: ignore unknown option: %s", host, option) |
|
151 elif item == 'next-sever' : |
|
152 boot_server, = args |
|
153 elif item == 'filename' : |
|
154 boot_filename, = args |
145 else : |
155 else : |
146 log.warn("host %s: ignore unknown item: %s", host, item) |
156 log.warn("host %s: ignore unknown item: %s", host, item) |
147 |
157 |
148 # determine hostname |
158 # determine hostname |
149 suffix = None |
159 suffix = None |
154 hostname = host |
164 hostname = host |
155 |
165 |
156 if fixed_address and not re.match(r'\d+\.\d+\.\d+.\d+', fixed_address) : |
166 if fixed_address and not re.match(r'\d+\.\d+\.\d+.\d+', fixed_address) : |
157 hostname, domain = fixed_address.split('.', 1) |
167 hostname, domain = fixed_address.split('.', 1) |
158 |
168 |
|
169 if not (hostname or ethernet) : |
|
170 log.warn("%s: no hostname/ethernet: %s/%s", host, hostname, ethernet) |
|
171 return |
|
172 |
|
173 yield hostname, 'ethernet', ethernet |
159 #if suffix : |
174 #if suffix : |
160 # yield hostname, ('ethernet', suffix), ethernet |
175 # yield hostname, ('ethernet', suffix), ethernet |
161 if hostname and ethernet : |
176 |
162 yield hostname, 'ethernet', ethernet |
177 if boot_server and boot_filename : |
163 else : |
178 yield hostname, 'boot', "{server}:{filename}".format( |
164 log.warn("%s: no hostname/ethernet: %s/%s", host, hostname, ethernet) |
179 server = boot_server, |
|
180 filename = boot_filename, |
|
181 ) |
|
182 elif boot_filename : |
|
183 yield hostname, 'boot', "{filename}".format(filename=boot_filename) |
165 |
184 |
166 def import_dhcp_hosts (options, blocks) : |
185 def import_dhcp_hosts (options, blocks) : |
167 """ |
186 """ |
168 Process hosts from a parsed block |
187 Process hosts from a parsed block |
169 """ |
188 """ |
181 |
200 |
182 try : |
201 try : |
183 for info in import_dhcp_host(options, host, items) : |
202 for info in import_dhcp_host(options, host, items) : |
184 yield info |
203 yield info |
185 except ValueError as error : |
204 except ValueError as error : |
186 log.warn("%s: invalid host: %s", host, error) |
205 log.exception("%s: invalid host: %s", host, error) |
187 else: |
206 else: |
188 log.warn("ignore unknown block: %s", block) |
207 log.warn("ignore unknown block: %s", block) |
189 |
208 |
190 def import_dhcp_conf (options, file) : |
209 def import_dhcp_conf (options, file) : |
191 items, blocks = pvl.dhcp.config.DHCPConfigParser().load(file) |
210 items, blocks = pvl.dhcp.config.DHCPConfigParser().load(file) |