02-24-2025 05:01 AM
We have a full CML cluster installed, and as an admin.. I am seeing users who leave their Labs on, even though they have logged off.
Is there anyway to A) see if the user is inactive, and has been offline for a while? Or B) have Labs STOP on their own after a certain amount of time being inactive?
The reason for this would be to save power, and return nodes back to the pool for others.
If nodes aren't released, others may find they don't have all the nodes available for their Labs.
02-24-2025 06:42 AM
Hi @paul-fletcher,
I run the following script from cron each night to shut down any running labs. It's not an ideal solution, but it works:
import requests, json
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
username = "your username"
password = "your password"
baseurl = "https://your.host.name/api/v0"
def authenticate(baseurl, username, password):
payload = {
"username": username,
"password": password
}
token = response = requests.post(url=f"{baseurl}/authenticate", data=json.dumps(payload), verify=False).json()
return(token)
def main():
token = authenticate(baseurl=baseurl, username=username, password=password)
lab_list = requests.get(
url=f"{baseurl}/labs",
headers={"Authorization": f"Bearer {token}"},
params={"show_all": True},
verify=False).json()
for lab in lab_list:
response = requests.put(url=f"{baseurl}/labs/{lab}/stop", headers={"Authorization": f"Bearer {token}"}, verify = False)
if response.status_code == 204:
print("Lab stopped successfully: " + str(lab))
if __name__ == "__main__":
main()
Add this to an appropriate folder, I have put it under "/home/sysadmin/stopall.py" on my CML server.
You can then add the following line to cron(cron can be edited by running "crontab -e"):
0 2 * * * python3 /home/sysadmin/stopall.py
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide