Skip to content

Instantly share code, notes, and snippets.

@treydock
Created February 26, 2014 00:23
Show Gist options
  • Save treydock/9220870 to your computer and use it in GitHub Desktop.
Save treydock/9220870 to your computer and use it in GitHub Desktop.
#!/usr/share/foreman/script/rails runner -e production
Host.all.each do |host|
next unless host.dhcp?
print "#{host}..."
dhcp_record = host.dhcp_record
print "#{dhcp_record}..."
if dhcp_record.valid?
puts "VALID"
elsif dhcp_record.conflicting?
puts "CONFLICT"
warn "not going to do anything as we found conflicting dhcp records"
warn "we wanted #{dhcp_record.attrs.inspect} but found: #{dhcp_record.conflicts.map{|c| c.attrs.inspect}.join(', ')}"
else
print "missing..recreating.."
dhcp_record.create
puts "DONE"
end
host.interfaces.each do |interface|
next unless interface.dhcp?
print "#{interface}..."
dhcp_record = interface.dhcp_record
print "#{dhcp_record}..."
if dhcp_record.valid?
puts "VALID"
elsif dhcp_record.conflicting?
puts "CONFLICT"
warn "not going to do anything as we found conflicting dhcp records"
warn "we wanted #{dhcp_record.attrs.inspect} but found: #{dhcp_record.conflicts.map{|c| c.attrs.inspect}.join(', ')}"
else
print "missing..recreating.."
dhcp_record.create
puts "DONE"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment