18075: Kill off MaxComputeVMs properly.
[arvados.git] / services / api / app / models / node.rb
index 044d83c287969cbcc61f7cec7724b8be630037de..c8a606e2b808d63a714d41d362e11e34121eebac 100644 (file)
@@ -24,6 +24,7 @@ class Node < ArvadosModel
   attr_accessor :job_readable
 
   UNUSED_NODE_IP = '127.40.4.0'
+  MAX_VMS = 3
 
   api_accessible :user, :extend => :common do |t|
     t.add :hostname
@@ -39,7 +40,7 @@ class Node < ArvadosModel
   api_accessible :superuser, :extend => :user do |t|
     t.add :first_ping_at
     t.add :info
-    t.add lambda { |x| Rails.configuration.Containers.SLURM.Managed.ComputeNodeNameservers }, :as => :nameservers
+    t.add lambda { |x| Rails.configuration.Containers.SLURM.Managed.ComputeNodeNameservers.keys }, :as => :nameservers
   end
 
   after_initialize do
@@ -159,7 +160,7 @@ class Node < ArvadosModel
                           # query label:
                           'Node.available_slot_number',
                           # [col_id, val] for $1 vars:
-                          [[nil, Rails.configuration.Containers.MaxComputeVMs]],
+                          [[nil, MAX_VMS]],
                          ).rows.first.andand.first
   end
 
@@ -168,7 +169,7 @@ class Node < ArvadosModel
   end
 
   def dns_server_update
-    if ip_address_changed? && ip_address
+    if saved_change_to_ip_address? && ip_address
       Node.where('id != ? and ip_address = ?',
                  id, ip_address).each do |stale_node|
         # One or more(!) stale node records have the same IP address
@@ -178,10 +179,10 @@ class Node < ArvadosModel
         stale_node.update_attributes!(ip_address: nil)
       end
     end
-    if hostname_was && hostname_changed?
-      self.class.dns_server_update(hostname_was, UNUSED_NODE_IP)
+    if hostname_before_last_save && saved_change_to_hostname?
+      self.class.dns_server_update(hostname_before_last_save, UNUSED_NODE_IP)
     end
-    if hostname && (hostname_changed? || ip_address_changed?)
+    if hostname && (saved_change_to_hostname? || saved_change_to_ip_address?)
       self.class.dns_server_update(hostname, ip_address || UNUSED_NODE_IP)
     end
   end
@@ -267,7 +268,7 @@ class Node < ArvadosModel
       !Rails.configuration.Containers.SLURM.Managed.DNSServerConfTemplate.to_s.empty? and
       !Rails.configuration.Containers.SLURM.Managed.AssignNodeHostname.empty?)
 
-    (0..Rails.configuration.Containers.MaxComputeVMs-1).each do |slot_number|
+    (0..MAX_VMS-1).each do |slot_number|
       hostname = hostname_for_slot(slot_number)
       hostfile = File.join Rails.configuration.Containers.SLURM.Managed.DNSServerConfDir, "#{hostname}.conf"
       if !File.exist? hostfile