Add persistent/cache switch to collections index page.
[arvados.git] / services / api / app / controllers / nodes_controller.rb
1 class NodesController < ApplicationController
2   def index
3     @objects = model_class.order("created_at desc")
4
5     @slurm_state = {}
6     IO.popen('sinfo --noheader --Node || echo "compute[1-3] foo bar DOWN"').readlines.each do |line|
7       tokens = line.strip.split
8       nodestate = tokens.last
9       nodenames = []
10       if (re = tokens.first.match /^([^\[]*)\[([-\d,]+)\]$/)
11         nodeprefix = re[1]
12         re[2].split(',').each do |number_range|
13           if number_range.index('-')
14             range = number_range.split('-').collect(&:to_i)
15             (range[0]..range[1]).each do |n|
16               nodenames << "#{nodeprefix}#{n}"
17             end
18           else
19             nodenames << "#{nodeprefix}#{number_range}"
20           end
21         end
22       else
23         nodenames << tokens.first
24       end
25       nodenames.each do |nodename|
26         @slurm_state[nodename] = nodestate.downcase
27       end
28     end
29   end
30 end