refs #4926 Merge branch '4926-getting-started'
[arvados.git] / services / api / app / models / node.rb
index 502ae26594042f8e56973897e1d5d093f2d05990..c38f6817dbc768f4b380c51b999d75c6526dff61 100644 (file)
@@ -137,6 +137,17 @@ class Node < ArvadosModel
 
   def dns_server_update
     if self.hostname_changed? or self.ip_address_changed?
+      if not self.ip_address.nil?
+        stale_conflicting_nodes = Node.where('id != ? and ip_address = ? and last_ping_at < ?',self.id,self.ip_address,10.minutes.ago)
+        if not stale_conflicting_nodes.empty?
+          # One or more stale compute node records have the same IP address as the new node.
+          # Clear the ip_address field on the stale nodes.
+          stale_conflicting_nodes.each do |stale_node|
+            stale_node.ip_address = nil
+            stale_node.save!
+          end
+        end
+      end
       if self.hostname and self.ip_address
         self.class.dns_server_update(self.hostname, self.ip_address)
       end