def handleImageSelect(ip, dpacket, bpacket): # # Find the boot image the user selected. # images = imageList(netbootimagepath) bootimage = None for image in images: if image['ID'] == bpacket.getSelectedBootImage(): bootimage = image if bootimage == None: return None # # Build the DHCP Ack packet. # dresponse = dpacket.newAckPacket() dresponse.sname = ip dresponse.bfile = '/nbi/' + bootimage['Path'] + '/i386/booter' dresponse.options[dhcp.OPTION_VENDOR_CLASS] = 'AAPLBSDPC' dresponse.options[dhcp.OPTION_SERVER_IDENTIFIER] = ip #dresponse.options[dhcp.OPTION_TFTP_SERVER_NAME] = ip #dresponse.options[dhcp.OPTION_BOOTFILE_NAME] = bootimage['Path'] + '/i386/booter' if image['Type'] == 'NFS': dresponse.options[ dhcp. OPTION_ROOT_PATH] = 'nfs:' + ip + ':' + netbootimagepath + ':' + bootimage[ 'Path'] + '/' + bootimage['RootPath'] else: dresponse.options[ dhcp.OPTION_ROOT_PATH] = 'http://' + ip + '/' + bootimage[ 'Path'].replace(' ', '%20') + '/' + bootimage['RootPath'].replace( ' ', '%20') # # Machine name will follow the pattern of: NetBootMAC # #name = 'NetBoot' + ''.join('{:02x}'.format(c) for c in dpacket.chaddr) bresponse = bsdp.BsdpPacket() bresponse.setType(2) #bresponse.setMachineName(name) # # If this is not an install image, we need to setup a shadow # path for them to use. # if bootimage['IsInstall'] == False: path = join(netbootclientpath, name) if isdir(path) == False: mkdir(path) chown(path, getpwnam(netbootuser).pw_uid, -1) bresponse.setShadowMountURL('afp://' + netbootuser + ':' + netbootpass + '@' + ip + '/NetBootClients') bresponse.setShadowFilePath(name + '/Shadow') bresponse.setSelectedBootImage(bpacket.getSelectedBootImage()) dresponse.options[dhcp.OPTION_VENDOR_INFORMATION] = bresponse.encode(True) return dresponse
def handleDhcpPacket(sock, ip, dpacket): if dpacket.options[dhcp.OPTION_MESSAGE_TYPE] == dhcp.MESSAGE_INFORM and dpacket.options[dhcp.OPTION_VENDOR_CLASS][0:9] == 'AAPLBSDPC': bpacket = bsdp.BsdpPacket() bpacket.decode(dpacket.options[dhcp.OPTION_VENDOR_INFORMATION]) if bpacket.getType() == bsdp.TYPE_LIST: response = handleImageList(ip, dpacket, bpacket) if response != None: sock.sendto(response.encode(), addr) elif bpacket.getType() == bsdp.TYPE_SELECT: response = handleImageSelect(ip, dpacket, bpacket) if response != None: sock.sendto(response.encode(), addr)
def handleImageList(ip, dpacket, bpacket): # # Build the basic packet. # bresponse = bsdp.BsdpPacket() bresponse.setType(bsdp.TYPE_LIST) bresponse.setServerID(ip) bresponse.setServerPriority(32768) # # Rerieve the list of NetBoot Images. # images = imageList(netbootimagepath) if len(images) == 0: return None # # Walk each image and add it to the list of images if needed. # for image in images: if image['IsEnabled'] == False: continue imageid = image['ID'] if image['IsDefault'] and bresponse.getDefaultBootImage() == None: bresponse.setDefaultBootImage(imageid) bresponse.appendBootImageList(imageid, image['Name']) # # If no default boot image was specified then set the last one to # be the default. # if bresponse.getDefaultBootImage() == None: bresponse.setDefaultBootImage(imageid) # # Build the response DHCP packet. # dresponse = dpacket.newAckPacket() dresponse.options[dhcp.OPTION_SERVER_IDENTIFIER] = ip dresponse.options[dhcp.OPTION_VENDOR_CLASS] = 'AAPLBSDPC' dresponse.options[dhcp.OPTION_VENDOR_INFORMATION] = bresponse.encode(True) return dresponse