Auto Assign Slaves to limitgroups

Hello there

Running Deadline 7.1.2.1 (having most difficulties syncing work with the Linux team there so we can upgrade)

I’m having a lack of responde of both
RepositoryUtils.AddSlavesToLimitGroupList()
RepositoryUtils.RemoveSlavesFromLimitGroupList()
functions

The script is applied at OnSlaveStartedCallback event to include slaves in correct limit groups depending on which OS they are running (and we change default OS a lot depending on needs)

All other parts of the script run fine so I guess something is wrong in what I want to do, or in the way I write the function

Provided are the full script and a job log from a slave

Any idea welcome

This is the basis but it is also meant to add slaves to plugin/software based limitgroups

Script:

[code]
###############################################################

Imports

###############################################################
from Deadline.Events import *
from Deadline.Scripting import *

def GetDeadlineEventListener():
‘’’ Return an instance of the event listener ‘’’
return PluginListener()

def CleanupDeadlineEventListener(eventListener):
‘’’ Free items set by Python as they can leak with Python.net ‘’’
eventListener.Cleanup()

###############################################################

The event listener class.

###############################################################
class PluginListener (DeadlineEventListener):
def init(self):
self.OnSlaveStartedCallback += self.OnSlaveStarted

def Cleanup(self):
	del self.OnSlaveStartedCallback

# This is called every time the Slave starts
def OnSlaveStarted(self, slavename):
	print 'Slave-Setup.py started'
	slaveSettings = RepositoryUtils.GetSlaveSettings(slavename, True)
	slaveInfo = RepositoryUtils.GetSlaveInfo(slavename, True)
	if any ('windows' in s.lower() for s in slaveInfo.MachineOperatingSystem.split( )):
		print 'Windows running'
		slaveSettings.SlaveExtraInfo9 = 'Windows'
		RepositoryUtils.AddSlavesToLimitGroupList('_windows',slavename)
		RepositoryUtils.RemoveSlavesFromLimitGroupList('_linux',slavename)
	else:
		print 'Linux running'
		slaveSettings.SlaveExtraInfo9 = 'Linux'
		RepositoryUtils.AddSlavesToLimitGroupList('_linux',slavename)
		RepositoryUtils.RemoveSlavesFromLimitGroupList('_windows',slavename)
	RepositoryUtils.SaveSlaveSettings(slaveSettings)
	print 'Slave-Setup.py completed'[/code]

Log:

=======================================================
Log
=======================================================
2016-02-24 10:15:25:  BEGIN - WS040\jerome.du
2016-02-24 10:15:25:  PYTHON: Slave-Setup.py started
2016-02-24 10:15:25:  PYTHON: Windows running
2016-02-24 10:15:25:  PYTHON: Slave-Setup.py completed

=======================================================
Details
=======================================================
Date: 02/24/2016 10:15:25
Event Type: OnSlaveStarted

=======================================================
Slave Information
=======================================================
Slave Name: ws040
Version: v7.1.2.1 R  (53013d5bd)
Operating System: Windows 10 Pro
Running As Service: No
Machine User: jerome.du
IP Address: 10.200.31.25
MAC Address: 00:22:64:32:1F:12
CPU Architecture: x64
CPUs: 8
CPU Usage: 
Memory Usage: 
Free Disk Space: 
Video Card: NVIDIA Quadro FX 3800

I’ve got your script, and I’m working on replicating your issue.

I can’t manage to replicate your issue here, it actually fails with a python error. I’m sure its something on my end but I don’t have an answer for you for a little while. Figured you’d like to know that your issue is being looked at.

Hey

Thanks for taking a look at this

Any success in reproducing the bug ?

Hey Alcium,

It turns out there’s a bug in the API for this guy. Both of these functions are actually no-ops:

         RepositoryUtils.AddSlavesToLimitGroupList('_linux',slavename)
         RepositoryUtils.RemoveSlavesFromLimitGroupList('_windows',slavename)

So, it’s not your fault the script isn’t working.

I’ve been working with Justin to show him how to work around the problem, but he’s still ramping up on certain sections of the API and getting settled in with Deadline scripting. We’re working on implementing the workaround for you.

Alrighty,

I’ve got a script done up that does what you need it to do. It does look very different to your original one, as I had to work around those two functions. Be sure to look it over, but it’s worked correctly in all my tests.

Let me know if it works for you,
Justin

All that work and I forget to attach it!
Slave-Setup.zip (1 KB)

For what it’s worth, that new code is prone to race conditions if multiple slaves start at the same time.

Agreed. I honestly couldn’t figure out a better way while writing the code Justin based his fix off of.

Seems to be doing the trick

I had some small issues though where the group was removed but not added, I have changed the way to check the OS with an integrated script, maybe it will help down there, but obviously the way it’s built has a possibility of overlapping.
I’ll try to figure out how to run the script again if somehow the limitgroup is not applied as it should

Also, I figured out that if a slave started with the incorrect limitgroup after switching OS it could then immediately pick up a job in the ‘wrong’ limitgroup before changes are applied
I was thinking of disabling the slave immediately on startup of the script and enable at the end of script but it seems there’s no integrated scripting for that (or at least I could not find it in the doc). Any idea down there ?

I think I’ve found what you’re looking for with Deadline.Slaves.SlaveSettings.SlaveEnabled. Its inside the slave’s SlaveInfoSettings. I found it in the docs here, though I’m not totally sure how to use it. Hopefully its straightforward but I don’t have time today to make up a demo. If it isn’t simple let me know and I’ll get on figuring it out.

I actually missed this one, was searching on disable :slight_smile:

It has a get/set so I think that can do the trick

Thanks