def log_request(file_name, clock=reactor): """Log a TFTP request. This will be logged to the regular log, and also to the node event log at a later iteration of the `clock` so as to not delay the task currently in progress. """ # If the file name is a byte string, decode it as ASCII, replacing # non-ASCII characters, so that we have at least something to log. if isinstance(file_name, bytes): file_name = file_name.decode("ascii", "replace") # Log to the regular log. remote_host, _ = tftp.get_remote_address() log.info( "{file_name} requested by {remote_host}", file_name=file_name, remote_host=remote_host, ) # Log to the node event log. d = deferLater( clock, 0, send_node_event_ip_address, event_type=EVENT_TYPES.NODE_TFTP_REQUEST, ip_address=remote_host, description=file_name, ) d.addErrback(log.err, "Logging TFTP request failed.")
def get_remote_mac(): """Gets the requestors MAC address from arp cache. This is used, when the dhcp lease file is not up-to-date soon enough to extract the MAC address from the IP address assigned by dhcp. """ remote_host, remote_port = tftp.get_remote_address() return find_mac_via_arp(remote_host)
def handle_boot_method(self, file_name: TFTPPath, result): boot_method, params = result if boot_method is None: return super().get_reader(file_name) # Map pxe namespace architecture names to MAAS's. arch = params.get("arch") if arch is not None: maasarch = ArchitectureRegistry.get_by_pxealias(arch) if maasarch is not None: params["arch"] = maasarch.name.split("/")[0] # Send the local and remote endpoint addresses. local_host, local_port = tftp.get_local_address() params["local_ip"] = local_host remote_host, remote_port = tftp.get_remote_address() params["remote_ip"] = remote_host d = self.get_boot_method_reader(boot_method, params) return d