OpenAPI Golang client library for Slurm REST API. A Slinky project.
This repository provides generated slurmrestd endpoints for Golang clients, and client wrapper library inspired by the controller-runtime client for Kubernetes.
- Multiple Slurm Versions: can interact with multiple versions of Slurm.
- Caching: client-side caching mechanism to reduce number of server calls.
Currently, the client wrapper implements a limited amount of Slurm endpoints, specifically only Node and Job endpoints. The number of implemented endpoints may expand in the future, by request or community efforts.
- Slurm Version: >= 24.05
go get -v github.com/SlinkyProject/slurm-client
Create a Slurm client handle.
config := &client.Config{
Server: "http://<host>:6820",
AuthToken: "<`auth/jwt` token>",
}
slurmClient, err := client.NewClient(config)
if err != nil {
return err
}
Start Slurm client cache.
ctx := context.Background()
go slurmClient.Start(ctx)
Create Slurm resources via client handle.
// Create job via V0042 endpoint
jobInfo := &types.V0042JobInfo{}
req := v0042.V0042JobSubmitReq{
Job: &v0042.V0042JobDescMsg{
CurrentWorkingDirectory: ptr.To("/tmp"),
Environment: &v0042.V0042StringArray{
"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin",
},
Script: ptr.To("#!/usr/bin/env bash\nsleep 30"),
},
}
if err := slurmClient.Create(ctx, jobInfo, req); err != nil {
return err
}
// Create job via V0041 endpoint
jobInfo := &types.V0041JobInfo{}
req := v0041.V0041JobSubmitReq{
Job: &v0041.V0041JobDescMsg{
CurrentWorkingDirectory: ptr.To("/tmp"),
Environment: &v0041.V0041StringArray{
"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin",
},
Script: ptr.To("#!/usr/bin/env bash\nsleep 30"),
},
}
if err := slurmClient.Create(ctx, jobInfo, req); err != nil {
return err
}
// Create job via V0040 endpoint
jobInfo := &types.V0040JobInfo{}
req := v0040.V0040JobSubmitReq{
Job: &v0040.V0040JobDescMsg{
CurrentWorkingDirectory: ptr.To("/tmp"),
Environment: &v0040.V0040StringArray{
"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin",
},
Script: ptr.To("#!/usr/bin/env bash\nsleep 30"),
},
}
if err := slurmClient.Create(ctx, jobInfo, req); err != nil {
return err
}
Delete Slurm resource via client handle.
// Delete job via V0042 endpoint
jobInfo := &types.V0042JobInfo{
V0042JobInfo: v0042.V0042JobInfo{
JobId: ptr.To("1"),
},
}
if err := slurmClient.Delete(ctx, jobInfo); err != nil {
return err
}
// Delete job via V0041 endpoint
jobInfo := &types.V0041JobInfo{
V0041JobInfo: v0041.V0041JobInfo{
JobId: ptr.To("1"),
},
}
if err := slurmClient.Delete(ctx, jobInfo); err != nil {
return err
}
// Delete job via V0040 endpoint
jobInfo := &types.V0040JobInfo{
V0040JobInfo: v0040.V0040JobInfo{
JobId: ptr.To("1"),
},
}
if err := slurmClient.Delete(ctx, jobInfo); err != nil {
return err
}
Get Slurm resource via client handle.
// Fetch node via V0042 endpoint
node := &types.V0042Node{}
key := object.ObjectKey("node-0")
if err := slurmClient.Get(ctx, key, node); err != nil {
return err
}
// Fetch node via V0041 endpoint
node := &types.V0041Node{}
key := object.ObjectKey("node-0")
if err := slurmClient.Get(ctx, key, node); err != nil {
return err
}
// Fetch node via V0040 endpoint
node := &types.V0040Node{}
key := object.ObjectKey("node-0")
if err := slurmClient.Get(ctx, key, node); err != nil {
return err
}
List Slurm resources via client handle.
// Fetch list of nodes via V0042 endpoint
nodeList := &types.V0042NodeList{}
if err := slurmClient.List(ctx, nodeList); err != nil {
return err
}
// Fetch list of nodes via V0041 endpoint
nodeList := &types.V0041NodeList{}
if err := slurmClient.List(ctx, nodeList); err != nil {
return err
}
// Fetch list of nodes via V0040 endpoint
nodeList := &types.V0040NodeList{}
if err := slurmClient.List(ctx, nodeList); err != nil {
return err
}
Update Slurm resource via client handle.
// Update job via V0042 endpoint
jobInfo := &types.V0042JobInfo{}
req := &v0042.V0042JobDescMsg{
Comment: ptr.To("updated comment")
}
if err := slurmClient.Update(ctx, jobInfo, req); err != nil {
return err
}
// Update job via V0041 endpoint
jobInfo := &types.V0041JobInfo{}
req := &v0041.V0041JobDescMsg{
Comment: ptr.To("updated comment")
}
if err := slurmClient.Update(ctx, jobInfo, req); err != nil {
return err
}
// Update job via V0040 endpoint
jobInfo := &types.V0040JobInfo{}
req := &v0040.V0040JobDescMsg{
Comment: ptr.To("updated comment")
}
if err := slurmClient.Update(ctx, jobInfo, req); err != nil {
return err
}
go get -u github.com/SlinkyProject/slurm-client
The source tree may evolve more aggressively during these release versions, so upgrades may require updated paths in addition to the version.
Copyright (C) SchedMD LLC.
Licensed under the Apache License, Version 2.0 you may not use project except in compliance with the license.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.