File: job_submit.license.lua

package info (click to toggle)
slurm-wlm 22.05.8-4%2Bdeb12u3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 48,492 kB
  • sloc: ansic: 475,246; exp: 69,020; sh: 8,862; javascript: 6,528; python: 6,444; makefile: 4,185; perl: 4,069; pascal: 131
file content (68 lines) | stat: -rw-r--r-- 2,142 bytes parent folder | download | duplicates (5)
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
--[[

 Example lua script demonstrating the Slurm job_submit/lua interface.
 This is only an example, not meant for use in its current form.

 For use, this script should be copied into a file name "job_submit.lua"
 in the same directory as the Slurm configuration file, slurm.conf.

--]]

function _limit_license_cnt(orig_string, license_name, max_count)
	local i = 0
	local j = 0
	local val = 0 

	if orig_string == nil then
		return 0
	end

	i, j, val = string.find(orig_string, license_name .. "%:(%d)")
	if val ~= nil then
		slurm.log_info("name:%s count:%s", license_name, val)
	end
	if val ~= nil and val + 0 > max_count then
		return 1
	end
	return 0
end

--########################################################################--
--
--  Slurm job_submit/lua interface:
--
--########################################################################--

function slurm_job_submit ( job_desc, part_list, submit_uid )
	local bad_license_count = 0

	bad_license_count = _limit_license_cnt(job_desc.licenses, "lscratcha", 1)
	bad_license_count = _limit_license_cnt(job_desc.licenses, "lscratchb", 1) + bad_license_count
	bad_license_count = _limit_license_cnt(job_desc.licenses, "lscratchc", 1) + bad_license_count
	if bad_license_count > 0 then
		slurm.log_info("slurm_job_submit: for user %u, invalid licenses value: %s",
				job_desc.user_id, job_desc.licenses)
		slurm.log_user("Invalid licenses value: %s", job_desc.licenses)
		return slurm.ESLURM_INVALID_LICENSES
	end

	return slurm.SUCCESS
end

function slurm_job_modify ( job_desc, job_rec, part_list, modify_uid )
	local bad_license_count = 0

	bad_license_count = _limit_license_cnt(job_desc.licenses, "lscratcha", 1)
	bad_license_count = _limit_license_cnt(job_desc.licenses, "lscratchb", 1) + bad_license_count
	bad_license_count = _limit_license_cnt(job_desc.licenses, "lscratchc", 1) + bad_license_count
	if bad_license_count > 0 then
		slurm.log_info("slurm_job_modify: for job %u, invalid licenses value: %s",
				job_rec.job_id, job_desc.licenses)
		return slurm.ESLURM_INVALID_LICENSES
	end

	return slurm.SUCCESS
end

slurm.log_info("initialized")
return slurm.SUCCESS