+
+ def dnsmasq_update
+ if self.hostname_changed? or self.ip_address_changed?
+ if self.hostname and self.ip_address
+ self.class.dnsmasq_update(self.hostname, self.ip_address)
+ end
+ end
+ end
+
+ def self.dnsmasq_update(hostname, ip_address)
+ return unless @@confdir
+ ptr_domain = ip_address.
+ split('.').reverse.join('.').concat('.in-addr.arpa')
+ hostfile = File.join @@confdir, hostname
+ File.open hostfile, 'w' do |f|
+ f.puts "address=/#{hostname}/#{ip_address}"
+ f.puts "address=/#{hostname}.#{@@domain}/#{ip_address}" if @@domain
+ f.puts "ptr-record=#{ptr_domain},#{hostname}"
+ end
+ File.open(File.join(@@confdir, 'restart.txt'), 'w') do |f|
+ # this should trigger a dnsmasq restart
+ end
+ end
+
+ def self.hostname_for_slot(slot_number)
+ "compute#{slot_number}"
+ end
+
+ # At startup, make sure all DNS entries exist. Otherwise, slurmctld
+ # will refuse to start.
+ if @@confdir and
+ !File.exists? (File.join(@@confdir, hostname_for_slot(MAX_SLOTS-1)))
+ (0..MAX_SLOTS-1).each do |slot_number|
+ hostname = hostname_for_slot(slot_number)
+ hostfile = File.join @@confdir, hostname
+ if !File.exists? hostfile
+ dnsmasq_update(hostname, '127.40.4.0')
+ end
+ end
+ end
+
+ def permission_to_update
+ @bypass_orvos_authorization or super
+ end
+
+ def permission_to_create
+ current_user and current_user.is_admin
+ end