This repository has been archived on 2023-10-10. You can view files and clone it, but cannot push or open issues or pull requests.
khepri-tftpy/run.py

54 lines
1.3 KiB
Python
Raw Normal View History

2012-11-14 11:57:41 +00:00
#!/usr/bin/env python
import sys, logging
import tftpy
2012-11-14 13:21:50 +00:00
import re
import cStringIO
import time
file_hooks = {}
def hook_dispatcher(path):
for pattern, hook in file_hooks.iteritems():
match = re.match(pattern, path)
if match:
return hook(path, match)
return None
def hook(pattern):
def decorator(f):
file_hooks[pattern] = f
return f
return decorator
@hook(r"^pxelinux.cfg/default$")
def pxelinux_default(path, match):
s = """default menu.c32
prompt 0
menu title "Khepri Boot Menu generated at %s"
menu INCLUDE pxelinux.cfg/graphics.conf
MENU AUTOBOOT Starting Xen Node in # seconds
label xen
menu label ^Xen Node
menu default
timeout 80
kernel xen/vmlinuz
append rootfstype=nfs root=/dev/nfs nfsroot=10.8.1.1:/var/khepri/nfs/xen,v4,rsize=16384,wsize=16384 ip=:::::eth0:dhcp
""" % time.strftime("%d/%m/%Y at %H:%M:%S")
return cStringIO.StringIO(s)
2012-11-14 11:57:41 +00:00
def main():
2012-11-14 13:21:50 +00:00
server = tftpy.TftpServer("/var/khepri/tftp-root/", dyn_file_func=hook_dispatcher)
2012-11-14 11:57:41 +00:00
try:
server.listen("10.8.1.1", 5000)
except tftpy.TftpException, err:
sys.stderr.write("%s\n" % str(err))
sys.exit(1)
except KeyboardInterrupt:
pass
if __name__ == '__main__':
main()