def handle(self, method, packet, mac, client_ip): """ Processes a dynamic request, returning a synthesised lease, if possible. `method`, `packet`, `mac`, and `client_ip` are all passed through from `handleUnknownMAC()` directly. The value returned is either a Definition or None, depending on success. """ mac = str(mac) self._logger.info("Dynamic %(method)s from %(mac)s%(ip)s in pool '%(name)s'" % { 'method': method, 'mac': mac, 'ip': client_ip and (' for %(ip)s' % {'ip': client_ip,}) or '', 'name': self._hostname_prefix, }) if method == 'DISCOVER' or method.startswith('REQUEST:'): definition = self._allocate(mac, client_ip) if definition and self._discourage_renewals: target_time = int(definition.lease_time * 0.975) self._logger.debug("Setting T1 and T2 to 97.5%% of lease-time=%(lease)i: %(target)i seconds" % { 'lease': definition.lease_time, 'target': target_time, }) packet.setOption('renewal_time_value', longToList(target_time)) packet.setOption('rebinding_time_value', longToList(target_time)) return definition if method == 'RELEASE' or method == 'DECLINE': return self._reclaim(mac, client_ip) if method == 'INFORM': return self._inform(client_ip) self._logger.info("%(method)s is unknown to the dynamic provisioning engine" % { 'method': method, }) return None