Commit 3f895c42 authored by Anders Blomdell's avatar Anders Blomdell
Browse files

PXE boot rework (IPv6 still not functional)

parent 68722756
......@@ -153,6 +153,7 @@ def generate(tree, options):
dhcp = set(filter(lambda d: options.host in d.name[0::1],
tree._host_._interface_._ip_._dhcpserver_))
assert dhcp, '%s is not a dhcp server' % options.host
pxeboot = get_pxeboot(dhcp)
result.append_lines("""
|ddns-update-style none;
......@@ -162,7 +163,7 @@ def generate(tree, options):
|option url-252 code 252 = text;
|option url-252 "\\n\\000";
""")
if get_pxeboot(dhcp) == 'only':
if pxeboot == 'only':
if not options.next_server:
raise util.HostinfoException('next_server not defined',
where=dhcp)
......@@ -179,7 +180,8 @@ def generate(tree, options):
pass
served_networks = map(lambda d: util.network(get_subnet(tree, d._parent)),
dhcp)
result += emit_hosts(tree, options, served_networks)
if pxeboot == 'no':
result += emit_hosts(tree, options, served_networks)
return str(result)
def emit_interface(tree, options, interface):
......
......@@ -29,11 +29,50 @@ subnet6 2001:ed8:77b5::/64 {
}
"""
PXE_ALLOW="""
option space PXE;
option PXE.mtftp-ip code 1 = ip-address;
option PXE.mtftp-cport code 2 = unsigned integer 16;
option PXE.mtftp-sport code 3 = unsigned integer 16;
option PXE.mtftp-tmout code 4 = unsigned integer 8;
option PXE.mtftp-delay code 5 = unsigned integer 8;
option arch code 93 = unsigned integer 16; # RFC4578
class "pxeclient" {
match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
next-server %(next_server)s;
if option arch = 00:06 {
filename "bootia32.efi";
} else if option arch = 00:07 {
filename "uefi/boot/grub2/bootx64.efi";
} else {
filename "pxelinux.0";
}
}
class "anaconda" {
match if substring (option vendor-class-identifier, 0, 14) = "anaconda-Linux";
next-server %(next_server)s;
}"""
PXE_DENY="""
authoritative;
# This is a (non-working) hack
option dhcp6.vendor-class code 16 = string;
class "pxeclient" {
log(error, concat("### Ignore ###", substring (option dhcp6.vendor-class, 6, 9)));
match if exists dhcp6.vendor-class and
substring (option dhcp6.vendor-class, 6, 9) = "PXEClient";
option dhcp6.bootfile-url "tftp://dist.control.lth.se/uefi/boot/grub2/bootx64.efi";
option dhcp6.bootfile-param "param1 param2"; ignore booting;
}"""
def generate(tree, options):
result = util.StringArray()
dhcp = set(filter(lambda d: options.host in d.name[0::1],
tree._host_._interface_._ipv6_._dhcpserver_))
assert dhcp, '%s is not a dhcp6 server' % options.host
pxeboot = get_pxeboot(dhcp)
result.append_lines("""
|ddns-update-style none;
......@@ -42,6 +81,15 @@ def generate(tree, options):
|use-host-decl-names on;
|allow leasequery;
""")
# if pxeboot == 'only':
# if not options.next_server:
# raise util.HostinfoException('next_server not defined',
# where=dhcp)
# result += PXE_ALLOW % dict(next_server=options.next_server)
# pass
# else:
# result += PXE_DENY
# pass
interface = set(map(lambda d: d._parent._parent, dhcp))
for i in interface:
result += emit_interface(tree, options, i)
......@@ -49,6 +97,8 @@ def generate(tree, options):
served_networks = map(lambda d: util.network(get_subnet(tree, d._parent)),
dhcp)
result += emit_hosts(tree, options, served_networks)
# if pxeboot == 'no':
# result += emit_hosts(tree, options, served_networks)
return str(result)
def emit_interface(tree, options, interface):
......@@ -65,6 +115,7 @@ def emit_interface(tree, options, interface):
def emit_network(tree, options, subnet, dhcp):
result = util.StringArray()
net = util.network(subnet)
pxeboot = get_pxeboot(dhcp)
result.append_lines("""
|subnet6 %(prefix)s {
| server-name "%(host)s";
......@@ -80,6 +131,18 @@ def emit_network(tree, options, subnet, dhcp):
assert first in net, '%s not part of %s' % (first, net)
assert last in net, '%s not part of %s' % (last, net)
result += " range6 %s %s;" % (first, last)
# if pxeboot == 'no':
# result += " range6 %(first)s %(last)s;" % dict(
# first=first, last=last)
# pass
# elif pxeboot == 'only':
# result.append_lines("""
# | pool6 {
# | allow members of "pxeclient";
# | allow members of "anaconda";
# | range6 %(first)s %(last)s;
# | }""" % dict(first=first, last=last))
# pass
pass
result += emit_subnet_info(subnet).indent()
result += '}'
......@@ -188,3 +251,18 @@ def get_subnet(tree, ip):
assert len(subnet) == 1, '%s matches multiple networks %s' % (a, subnet)
return subnet[0]
def get_pxeboot(dhcp):
try:
p = set(map(lambda d: d.pxeboot[0] or 'no', dhcp))
if len(p) != 1:
raise util.HostinfoException("Mixed pxeboot not allowed (%s)" %
','.join(p),
where=dhcp)
result = p.pop()
pass
except TypeError:
result = dhcp.pxeboot[0] or 'no'
pass
allowed = [ 'no', 'only' ]
assert result in allowed,"pxeboot ('%s') shold be in %s" % (result, allowed)
return result
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment