23 return None |
23 return None |
24 else : |
24 else : |
25 return '"{value}"'.format(value=value) |
25 return '"{value}"'.format(value=value) |
26 |
26 |
27 def process_host (options, host) : |
27 def process_host (options, host) : |
28 if host.owner : |
28 if host.boot : |
29 yield u"# {host.owner}".format(host=host) |
29 if ':' in host.boot : |
|
30 next_server, filename = host.boot.split(':', 1) |
|
31 elif host.boot.startswith('/') : |
|
32 next_server = None |
|
33 filename = host.boot |
|
34 elif host.boot.endswith(':') : |
|
35 next_server = host.boot |
|
36 filename = None |
|
37 else : |
|
38 log.error("%s: invalid boot: %s", host, host.boot) |
|
39 else : |
|
40 next_server = filename = None |
30 |
41 |
31 if host.boot : |
42 if set(host.ethernet) == set([0]) : |
32 if ':' in host.boot : |
43 host_fmt = "{host}" |
33 next_server, filename = host.boot.split(':', 1) |
44 elif host.ethernet : |
34 elif host.boot.startswith('/') : |
45 host_fmt = "{host}-{index}" |
35 next_server = None |
46 else : |
36 filename = host.boot |
47 # nothing there |
37 elif host.boot.endswith(':') : |
48 return |
38 next_server = host.boot |
|
39 filename = None |
|
40 else : |
|
41 log.error("%s: invalid boot: %s", host, host.boot) |
|
42 else : |
|
43 next_server = filename = None |
|
44 |
49 |
45 if set(host.ethernet) == set([0]) : |
50 if host.owner : |
46 host_fmt = "{host}" |
51 yield u"# Owner: {host.owner}".format(host=host) |
47 else : |
|
48 host_fmt = "{host}-{index}" |
|
49 |
52 |
50 for index, ethernet in host.ethernet.iteritems() : |
53 for index, ethernet in host.ethernet.iteritems() : |
51 for line in build_host(host_fmt.format(host=host, index=index), |
54 for line in build_host(host_fmt.format(host=host, index=index), |
52 { 'option host-name': dhcp_quote(host) }, |
55 { 'option host-name': dhcp_quote(host) }, |
53 { 'hardware ethernet': ethernet }, |
56 { 'hardware ethernet': ethernet }, |
54 { 'fixed-address': host.ip }, |
57 { 'fixed-address': host.ip }, |
55 { 'next-server': next_server }, |
58 { 'next-server': next_server }, |
56 { 'filename': dhcp_quote(filename) }, |
59 { 'filename': dhcp_quote(filename) }, |
57 ) : |
60 ) : |
58 yield line |
61 yield line |
59 |
62 |
60 yield "" |
63 yield "" |
61 |
64 |
62 def process_hosts (options, hosts) : |
65 def process_hosts (options, hosts) : |
63 for host in hosts : |
66 for host in hosts : |
64 for line in process_host(options, host) : |
67 for line in process_host(options, host) : |
65 yield line |
68 yield line |