use an after_update hook to keep DNS updated
authorTom Clegg <tom@clinicalfuture.com>
Thu, 10 Jan 2013 20:48:05 +0000 (12:48 -0800)
committerTom Clegg <tom@clinicalfuture.com>
Thu, 10 Jan 2013 20:48:05 +0000 (12:48 -0800)
app/models/node.rb

index 29233748dd1cf77cc61b77fc08b23130dee0102c..ab971ac3af533f85a163019448412998b0f9f92e 100644 (file)
@@ -2,6 +2,7 @@ class Node < ActiveRecord::Base
   include AssignUuid
   serialize :info, Hash
   before_validation :ensure_ping_secret
+  after_update :dnsmasq_update
 
   MAX_SLOTS = 64
 
@@ -47,7 +48,6 @@ class Node < ActiveRecord::Base
         raise "No available node slots" if try_slot == MAX_SLOTS
       end while true
       self.hostname = self.class.hostname_for_slot(self.slot_number)
-      self.class.dnsmasq_update(self.hostname, self.ip_address)
     end
 
     save
@@ -77,6 +77,12 @@ class Node < ActiveRecord::Base
     self.info[:ping_secret] ||= rand(2**256).to_s(36)
   end
 
+  def dnsmasq_update
+    if self.hostname_changed? or self.ip_address_changed?
+      self.class.dnsmasq_update(self.hostname, self.ip_address)
+    end
+  end
+
   def self.dnsmasq_update(hostname, ip_address)
     return unless @@confdir
     ptr_domain = ip_address.