11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/blondy/dhcpd/pool.rb', line 11
def query(hwaddr, type)
reply = Cache.query(hwaddr,type)
if reply
reply[:data]
else
http = EM::HttpRequest.new(Blondy::DHCPD::CONFIG['master']).
get(head: {'x-blondy-key' => Blondy::DHCPD::CONFIG['client_key']}, query: {'type' => type.to_s, 'hwaddr' => hwaddr})
http.callback do
if http..status != 200
Logger.error "Remote server reply with #{http..status} error code."
else
data = transform(http.response, type)
Cache.add(hwaddr,type, data) if data
end
data
end
http.errback do
Logger.error 'Remote pool server is unavailable.'
end
false
end
end
|