Datasheet

API Ruby class
196
## for it to complete (either with a '!done' or '!trap' response) before
## executing the callback code block. The call will block (execution of
## this script halts) and wait for the command to finish. Don't use this
## method if you need to handle simultaneous commands to a single device
## over a single API connection. Use an asynchronous calls send_request()
## and wait_for_reply().
mt.get_reply(
'/ip/dns/set',
"=primary-dns=#{PRIMARYDNS}",
"=secondary-dns=#{SECONDARYDNS}"
) do |request, sentence|
trap = request.reply.find_sentence('!trap')
if trap.nil?
puts "#{host}: Update command was sent."
else
puts "#{host}: An error occurred while setting DNS servers: #{trap['message']}"
end
end
## Now let's double-check the settings:
mt.get_reply('/ip/dns/getall') do |request, sentence|
trap = request.reply.find_sentence('!trap')
if trap.nil?
re = request.reply.find_sentence('!re')
unless re.nil?
## Check DNS settings:
if re['primary-dns'] == PRIMARYDNS && re['secondary-dns'] == SECONDARYDNS
puts "#{host}: Successfully updated DNS servers."
else
puts "#{host}: WARNING: DNS servers DO NOT MATCH: primary-dns=" +
"'#{re['primary-dns']}', secondary-dns='#{re['secondary-dns']}'"
end
else
puts "#{host}: WARNING: '/ip/dns/getall' command did work to retrieve DNS settings!"
end
else
puts "#{host}: An error occurred while setting DNS servers: #{trap['message']}"
end
end
mt.close
end
children += 1
while children >= MAXFORK
Process.wait
children -= 1
end
end