-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess_partitions.rb
92 lines (80 loc) · 3.13 KB
/
process_partitions.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
def updatePartitions(cmd, username, partition_file)
public_partitions_first = []
public_partitions_last = []
hostname = %x(#{"hostname"})
if hostname.include? 'grace'
# partitions that will appear before the PI partitions
public_partitions_first = ["devel", "day", "week", "gpu", "gpu_devel", "mpi", "bigmem", "transfer"]
# partitions that will appear after the PI partitions
public_partitions_last = ["scavenge", "scavenge_gpu", "legacy", "future"]
elsif hostname.include? 'milgram'
public_partitions_first = ["interactive", "day", "week", "gpu"]
public_partitions_last = ["scavenge"]
elsif hostname.include? 'mccleary'
public_partitions_first = ["devel", "day", "week", "gpu", "gpu_devel", "bigmem", "ycga", "transfer"]
public_partitions_last = ["scavenge_gpu", "scavenge", "future"]
elsif hostname.include? 'bouchet'
public_partitions_first = ["devel", "mpi"]
end
run_cmd = cmd + " " + username
private_partitions = %x(#{run_cmd}).split("\n")
# array to store the partition with additional fields with the following format:
# partition;partition;max_walltime_in_hours;gpu
extended_partitions = Array.new
# add public partitions in the first list
public_partitions_first.each do |partition|
if partition.include? "gpu_devel"
extended_partitions << partition+";"+partition+";6;true"
elsif partition.include? "devel"
extended_partitions << partition+";"+partition+";6;false"
elsif partition.include? "gpu"
extended_partitions << partition+";"+partition+";24;true"
elsif partition.include? "week"
extended_partitions << partition+";"+partition+";48;false"
else
extended_partitions << partition+";"+partition+";24;false"
end
end
# add private partitions
private_partitions.each do |partition|
partition_name = partition[/PartitionName=(.*?) /m, 1]
if partition.include? "gpu"
extended_partitions << partition_name+";"+partition_name+";168;true"
else
extended_partitions << partition_name+";"+partition_name+";168;false"
end
end
# add public partitions in the last list
public_partitions_last.each do |partition|
if partition.include? "gpu"
extended_partitions << partition+";"+partition+";24;true"
else
extended_partitions << partition+";"+partition+";24;false"
end
end
# dump extended_partitions to partition_file
f = File.open(partition_file, "w")
extended_partitions.each do |partition|
f.write(partition+"\n")
end
f.close
end
def processPartitions(libpath)
cmd = libpath+"/partitions.sh"
username = ENV['USER']
partition_file = ENV['HOME'] + "/ondemand/.partitions"
age = 60 # in seconds = one day
# check if partitions exists
if (File.file?(partition_file)) then
# check the time stamp of partitions. Update if it is older than age
if (Time.now - age > File.ctime(partition_file)) then
updatePartitions(cmd, username, partition_file)
end
else
updatePartitions(cmd, username, partition_file)
end
if (File.file?(partition_file))
extended_partitions = File.read(partition_file).split()
end
return extended_partitions
end