A Python toolkit to interact with slurmrestd on an HPC cluster via SSH.
- Send raw HTTP requests to
slurmrestdover SSH - High-level client (
Restd) withget,post,put,delete, etc. - Single-shot and shared connection modes
- Extensible backend system (start with
NetSSHBackend)
pip install .from hpckit import Restd, NetSSHBackend
import json
import os
allocation = "plgallocation-name-cpu"
plgrid_user = "plgusername"
job_desc = {"job": {
"environment": ["VAR1=VALUE1","VAR2=VALUE2"],
"account": allocation,
"partition":"plgrid",
"nodes":"1",
"tasks_per_node":1,
"memory_per_node":"512M",
"name":"py-hpckit",
"time_limit":{"set":True,"infinite":False,"number":1},
"current_working_directory":f'/net/people/plgrid/{user}'
},
"script":"#!/bin/bash\nhostname\n"
}
backend = NetSSHBackend("ares.cyfronet.pl", user=plgrid_user, key_filename=f'/home/{os.environ.get("USER")}/.ssh/id_ed25519')
client = Restd(backend)
response = client.post( "/slurm/v0.0.39/job/submit", json.dumps(job_desc), headers={"Content-Type": "application/json"})
if response.status == 200:
job_details = json.loads(response.read())
print(f"Job submitted with ID: {job_details['job_id']}")
update=client.get(f'/slurm/v0.0.39/job/{job_details['job_id']}')
print(update.read())
else:
print(f"Job submission failed: {response.status} {response.reason}")