Yep, that’s what we do for populating dropdowns of Slurm accounts, reservations, etc. Reference: # Suggestions on generating dynamic form data - #6 by Micket
Example from /etc/ood/config/apps/dashboard/initializers/ood.rb :
# Cache the data when possible, rather than running the same commands every
# time. Should be able to have the user restart their PUN if there's an
# immediate update.
class SlurmData
def self.accounts
username = Etc.getlogin
accounts = []
IO.popen 'sacctmgr --noheader --parsable show assoc format=account,user' do |io|
io.each do |line|
acc = line.split('|')
if acc[1] == username
accounts.append(acc[0])
end
end
end
return accounts
end
end
SlurmData.accounts
and the corresponding field in a form.yml:
bc_account2:
widget: "select"
label: "Job account"
options: [<%= SlurmData.accounts.sort.join(', ') %>]
help: |
Select the job account assigned to your class or research project.