From a job script, I try to change the machine limit slave list. Therefor I use the following commands:
limit = 'myMachine,'
slaves = [str(s).lower() for s in limit.split(', ') if s]
RepositoryUtils.SetMachineLimitListedSlaves(job.JobId, slaves)
print "Limit Slaves: ", [str(s) for s in jobLimitGroup(job.JobId).LimitGroupListedSlaves]
RepositoryUtils.SetMachineLimitWhiteListFlag(job.JobId, True)
print "White Flagged:", jobLimitGroup(job.JobId).LimitGroupWhitelistFlag
No need to save the job here, as we are using “Set” methods. The syntax needs to be in a certain form. Here’s an example:
[code]from Deadline.Scripting import *
def main():
selectedJobs = MonitorUtils.GetSelectedJobs()
for job in selectedJobs:
# slaves = [str(s).lower() for s in limit.split(",") if s] #wrong syntax
slaves = [‘myMachine’,] #syntax must be in this form
RepositoryUtils.SetMachineLimitListedSlaves(job.JobId, slaves)
RepositoryUtils.SetMachineLimitWhiteListFlag(job.JobId, True)[/code]
I think I was overwriting the job settings as I was saving the job in the end of a loop to change multiple jobs.
Example:
for job in hobs:
job.SetJobEnvironmentKeyValue("myVar", "1")
# Save job changes, before doing further changes
# to avoid overwriting
RepositoryUtils.SaveJob(job)
slaves = [str(s).lower().strip() for s in limit.split(',')]
RepositoryUtils.SetMachineLimitListedSlaves(job.JobId, slaves)
RepositoryUtils.SetMachineLimitWhiteListFlag(job.JobId, status)