Detect stale compute node records with the same IP address as the new
authorWard Vandewege <ward@curoverse.com>
Tue, 30 Dec 2014 19:31:53 +0000 (14:31 -0500)
committerWard Vandewege <ward@curoverse.com>
Tue, 30 Dec 2014 19:31:53 +0000 (14:31 -0500)
node on its first ping. Clear the ip_address field on the stale nodes.

Refs #4887

services/api/app/models/node.rb

index 502ae26594042f8e56973897e1d5d093f2d05990..3bc25863e2e1ce4ad8d6fab49f63a4bcc8969789 100644 (file)
@@ -137,6 +137,15 @@ class Node < ArvadosModel
 
   def dns_server_update
     if self.hostname_changed? or self.ip_address_changed?
+      @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
       if self.hostname and self.ip_address
         self.class.dns_server_update(self.hostname, self.ip_address)
       end