On 02/24/2013 11:32 PM, David Gwynne wrote:
what are you using the rewrite stuff for?
netbooting.
pxeboot is unable to pick a kernel based on machine.
and as I run an oddball mix of current/stable
i386/amd64 (and sparc64 but it does not count as ofwboot.net does
specify kernel)
so I use tftpd rewrite rules to load the correct kernel.
I use my constantly growing collection of old machines sort of in the
manner you would use a vm.
copy tree, send wol, have new server.
In all honesty it is sort of stupid, but I am having fun setting it up.
And just for grins and giggles this is what I am using to rewrite
I am sure my inexperience shows but it is good to learn somthing new
#!/usr/local/bin/python
#rewrite tftp requests
import socket, os
tftpd_rewrite_address = '/var/run/tftpd.sock'
tftpd_rewrite_address = '/tmp/tftpd.sock'
tftpd_base = '/tftpboot'
if os.path.exists(tftpd_rewrite_address):
os.unlink(tftpd_rewrite_address)
listen_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
listen_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
listen_socket.bind(tftpd_rewrite_address)
listen_socket.listen(1)
tftpd_socket, addr = listen_socket.accept()
REQUEST_ADDR = 0
REQUEST_CMD = 1
REQUEST_FILE = 2
cmd_list = ['quit']
cmd = ''
while cmd != 'quit':
tftp_request = tftpd_socket.recv(1024)
for request in tftp_request.strip().split('\n'):
if request in cmd_list:
cmd = request
else:
request_data = request.split(' ', 3)
if len(request_data) == 3:
response = request_data[REQUEST_FILE] + '\n'
host_name = socket.gethostbyaddr(request_data[REQUEST_ADDR])
short_name = host_name[0].split('.')[0]
if os.path.isdir(os.path.join(tftpd_base, short_name)):
if os.path.isabs(response):
response = response[1:] #remove leading /
short_name = '/' + short_name
response = os.path.join(short_name, response)
send_size = tftpd_socket.send(response)
tftpd_socket.close()
listen_socket.close()