-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDHCPListener.js
37 lines (29 loc) · 1.16 KB
/
DHCPListener.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function DHCPListener(inventory){
this.inventory = inventory;
}
DHCPListener.prototype.init = function init(){
return this.inventory.open();
};
DHCPListener.prototype.add = function add(args, env){
var mac = args.shift();
var ip = args.shift();
var hostname = args.shift();
return this.inventory.addLease(mac, ip, hostname);
};
DHCPListener.prototype.del = function del(args, env){
var mac = args.shift();
return this.inventory.deleteLease(mac);
};
DHCPListener.prototype.old = function old(args, env){
var mac = args.shift();
var ip = args.shift();
var hostname = args.shift();
return this.inventory.addLease(mac, ip, hostname).catch(function verifyError(error){
return error && error.message && /SQLITE_CONSTRAINT/.test(error.message);
}, function(error){
// Do nothing, since the lease was already in the inventory. It is assumed that we had placed it there.
// Note that, in case we missed some updates, we could choose to update the lease.
//TODO: Implement lease updates when a collision occurs, to make sure that we are restart-safe even in case of dnsmasq config weirdness (i.e. missed updates).
});
};
module.exports.DHCPListener = DHCPListener;