Skip to content

Commit 4a29478

Browse files
committed
kea: server-ids.json
1 parent d598d09 commit 4a29478

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

kea/choose_dhcp_server_id.rb

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
#!/usr/bin/env ruby
22
require 'ipaddr'
3+
require 'json'
34

45
dev = IO.popen(%w(ip -o route get 8.8.8.8), 'r', &:read).match(/dev ([^ ]+)/)[1].chomp
56
addr = IO.popen([*%w(ip -o address show dev), dev], 'r', &:read).match(/inet ([^ ]+)/)[1].chomp
6-
net = IPAddr.new(addr)
7+
#addr = '10.33.137.193'
8+
this = IPAddr.new(addr)
79

8-
candidates = ENV.fetch('DHCP_SERVER_IDS', '').split(',')
10+
#ENV['DHCP_SERVER_IDS'] = '10.33.136.67/21,10.33.152.67/21'
11+
candidates = ENV['DHCP_SERVER_IDS']&.then { _1.split(',') } || begin
12+
JSON.parse(File.read('/server-ids/server-ids.json')).fetch('server_ids')
13+
end
14+
warn(JSON.generate(this:, server_id_candidates: candidates))
915

1016
candidates.each do |candidate|
11-
if net.include?(IPAddr.new(candidate))
12-
puts candidate
17+
warn(JSON.generate(try: {candidate: candidate, this:}))
18+
if IPAddr.new(candidate).include?(this)
19+
warn(JSON.generate(server_id_chosen: candidate))
20+
puts candidate.split(?/)[0]
1321
exit
1422
end
1523
end
1624

25+
warn(JSON.generate(server_id_unchosen: addr, this:))
1726
puts addr.split(?/)[0]

0 commit comments

Comments
 (0)