Skip to content
Snippets Groups Projects
job_submit.lua 1.73 KiB
Newer Older
--[[

 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 dump(o)
   if type(o) == 'table' then
      local s = '{ '
      for k,v in pairs(o) do
         if type(k) ~= 'number' then k = '"'..k..'"' end
         s = s .. '['..k..'] = ' .. dump(v) .. ','
      end
      return s .. '} '
   else
      return tostring(o)
   end
end
-- Load necessary library
local pwd = require("posix").pwd
local grp = require("posix").grp

function slurm_job_submit(job_desc, part_list, submit_uid)

   local target_group = "gpfs5"
   local username = pwd.getpwuid(submit_uid).pw_name
   local group_member = grp.getgrnam(target_group).gr_mem
   local found = false
   -- Checking if the user is in the target_group
   -- By compare group member and the username
   for i,member in ipairs(group_member) do
      if member == username then
         found = true
         job_desc.features = "gpfs5"
         break
      end
   end
   if not found then
      job_desc.features = "gpfs4"
   end
   slurm.log_info("username:" .. username)
   slurm.log_info("job_desc.features:" .. dump(job_desc.features))
   return slurm.SUCCESS
end

function slurm_job_modify(job_desc, job_rec, part_list, modify_uid)
   if job_desc.comment == nil then
      local comment = "***TEST_COMMENT***"
      slurm.log_info("slurm_job_modify: for job %u from uid %u, setting default comment value: %s",
            job_rec.job_id, modify_uid, comment)
      job_desc.comment = comment
   end
   return slurm.SUCCESS
end

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