feat(slurmdb): add QosService
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
117
internal/slurm/slurmdb_qos.go
Normal file
117
internal/slurm/slurmdb_qos.go
Normal file
@@ -0,0 +1,117 @@
|
||||
package slurm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
type GetQosOptions struct {
|
||||
Description *string `url:"description,omitempty"`
|
||||
ID *string `url:"id,omitempty"`
|
||||
Format *string `url:"format,omitempty"`
|
||||
Name *string `url:"name,omitempty"`
|
||||
PreemptMode *string `url:"preempt_mode,omitempty"`
|
||||
WithDeleted *string `url:"with_deleted,omitempty"`
|
||||
}
|
||||
|
||||
func (s *SlurmdbQosService) GetQosList(ctx context.Context, opts *GetQosOptions) (*OpenapiSlurmdbdQosResp, *Response, error) {
|
||||
path := "slurmdb/v0.0.40/qos"
|
||||
req, err := s.client.NewRequest("GET", path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
if opts != nil {
|
||||
u, parseErr := url.Parse(req.URL.String())
|
||||
if parseErr != nil {
|
||||
return nil, nil, parseErr
|
||||
}
|
||||
q := u.Query()
|
||||
if opts.Description != nil {
|
||||
q.Set("description", *opts.Description)
|
||||
}
|
||||
if opts.ID != nil {
|
||||
q.Set("id", *opts.ID)
|
||||
}
|
||||
if opts.Format != nil {
|
||||
q.Set("format", *opts.Format)
|
||||
}
|
||||
if opts.Name != nil {
|
||||
q.Set("name", *opts.Name)
|
||||
}
|
||||
if opts.PreemptMode != nil {
|
||||
q.Set("preempt_mode", *opts.PreemptMode)
|
||||
}
|
||||
if opts.WithDeleted != nil {
|
||||
q.Set("with_deleted", *opts.WithDeleted)
|
||||
}
|
||||
u.RawQuery = q.Encode()
|
||||
req.URL = u
|
||||
}
|
||||
|
||||
var result OpenapiSlurmdbdQosResp
|
||||
resp, err := s.client.Do(ctx, req, &result)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return &result, resp, nil
|
||||
}
|
||||
|
||||
func (s *SlurmdbQosService) GetQos(ctx context.Context, qosName string, opts *GetQosOptions) (*OpenapiSlurmdbdQosResp, *Response, error) {
|
||||
path := fmt.Sprintf("slurmdb/v0.0.40/qos/%s", qosName)
|
||||
req, err := s.client.NewRequest("GET", path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
if opts != nil {
|
||||
u, parseErr := url.Parse(req.URL.String())
|
||||
if parseErr != nil {
|
||||
return nil, nil, parseErr
|
||||
}
|
||||
q := u.Query()
|
||||
if opts.WithDeleted != nil {
|
||||
q.Set("with_deleted", *opts.WithDeleted)
|
||||
}
|
||||
u.RawQuery = q.Encode()
|
||||
req.URL = u
|
||||
}
|
||||
|
||||
var result OpenapiSlurmdbdQosResp
|
||||
resp, err := s.client.Do(ctx, req, &result)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return &result, resp, nil
|
||||
}
|
||||
|
||||
func (s *SlurmdbQosService) PostQos(ctx context.Context, body *OpenapiSlurmdbdQosResp) (*OpenapiSlurmdbdQosResp, *Response, error) {
|
||||
path := "slurmdb/v0.0.40/qos"
|
||||
req, err := s.client.NewRequest("POST", path, body)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
var result OpenapiSlurmdbdQosResp
|
||||
resp, err := s.client.Do(ctx, req, &result)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return &result, resp, nil
|
||||
}
|
||||
|
||||
func (s *SlurmdbQosService) DeleteQos(ctx context.Context, qosName string) (*OpenapiSlurmdbdQosRemovedResp, *Response, error) {
|
||||
path := fmt.Sprintf("slurmdb/v0.0.40/qos/%s", qosName)
|
||||
req, err := s.client.NewRequest("DELETE", path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
var result OpenapiSlurmdbdQosRemovedResp
|
||||
resp, err := s.client.Do(ctx, req, &result)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return &result, resp, nil
|
||||
}
|
||||
Reference in New Issue
Block a user