def handle_config_request(client_ip, filename): m = re.search(MAC_FILE_REGEX, filename) machine = Machine.by_mac(m.group(1).replace('-', ':').lower()) if m else None use_def_config = any( re.search(regex, filename) for regex in DEFAULT_FILE_REGEXES) if machine or use_def_config: return render_config(is_pxelinux_path(filename), machine) else: return None
def index(): hwaddr = request.args.get('hwaddr') if not hwaddr: abort(400) machine = Machine.by_mac(hwaddr) if not machine: abort(404) interface = Interface.by_mac(hwaddr) if not interface: abort(404) # query param ?hwaddr= # response: # { # "ipv4": "", # "next-server": "", # "options": [ # { "option": number, "value": "" } # ] # } # option 67 is bootfile data = { 'options': [] } if machine.netboot_enabled: data['next-server'] = app.config['DHCP_TFTP_PROXY_HOST'] data['options'].append({'option': 67, 'value': app.config['DHCP_DEFAULT_BOOTFILE']}) use_static = True if interface.static_ipv4 else False if interface.reserved_ipv4 and not use_static: data['ipv4'] = interface.reserved_ipv4 return jsonify(data), 200