Class: Blondy::DHCPD::Pool

Inherits:
Object
  • Object
show all
Defined in:
lib/blondy/dhcpd/pool.rb

Class Method Summary collapse

Class Method Details

.query(hwaddr, type) ⇒ Object



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.response_header.status != 200
	Logger.error "Remote server reply with #{http.response_header.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