+ def assign_hostname
+ if self.hostname.nil? and Rails.configuration.Containers.SLURM.Managed.AssignNodeHostname
+ self.hostname = self.class.hostname_for_slot(self.slot_number)
+ end
+ end
+
+ def self.available_slot_number
+ # Join the sequence 1..max with the nodes table. Return the first
+ # (i.e., smallest) value that doesn't match the slot_number of any
+ # existing node.
+ connection.exec_query('SELECT n FROM generate_series(1, $1) AS slot(n)
+ LEFT JOIN nodes ON n=slot_number
+ WHERE slot_number IS NULL
+ LIMIT 1',
+ # query label:
+ 'Node.available_slot_number',
+ # [col_id, val] for $1 vars:
+ [[nil, Rails.configuration.Containers.MaxComputeVMs]],
+ ).rows.first.andand.first
+ end
+