For Robert Settlage from OOD Open Office Hours:
require 'json'
require 'open3' # Required for capture3 command line call
class CustomQueues ### GET PARTITIONS FOR THIS USER ###
def self.queues
@queues ||= begin
#puts("Grabbing partitions for user.")
sinfo_cmd = "/opt/apps/slurm/prod/bin/sinfo"
args = ["--noheader","-o=\"%R\""]
@partitions_available = []
o, e, s = Open3.capture3(sinfo_cmd , *args)
o.each_line do |v|
#v.gsub(/=\"(\S+)\"|=\"(\S+_p)\"/, '\1')
@partitions_available.append(v.gsub(/=\"(\S+)\"|=\"(\S+_p)\"/, '\1'))
end
@partitions_available
end
end
end
class LmodSpiderData ### GET LMOD Spider info for interactive apps ###
def self.spider_data
puts("Grabbing Spider Data.")
@spider_data ||= begin
spider_data_file = File.open "/opt/ood_data/daily-lmod.json"
@sd = JSON.load spider_data_file
spider_data_file.close
@sd
end
end
def self.returnAppVersions(app_name)
puts("Grabbed Versions for: " + app_name)
begin
_app_hash = spider_data[app_name]
_app_hash.map {|k,v| v["fullName"]}
end
end
end
# call these once during the initiazlier so that it'll be cached for later.
CustomQueues.queues
LmodSpiderData.spider_data
And here is the script that I run as a cronjob to generate the json data:
#!/bin/bash
# Runs LMOD Spider and generates the json file OOD needs to display modules in interactive apps.
/apps/lmod/lmod/libexec/spider -o spider-json /apps/mf/gb:/apps/mf/eb/all:/apps/easybuild/modules/all | python -mjson.tool > /opt/ood_data/daily-lmod.json