feat(slurmdb): add ClustersService
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
221
internal/slurm/slurmdb_clusters.go
Normal file
221
internal/slurm/slurmdb_clusters.go
Normal file
@@ -0,0 +1,221 @@
|
||||
package slurm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// Cluster classification constants for GetClustersOptions.Classification
|
||||
// and DeleteClusterOptions.Classification.
|
||||
const (
|
||||
ClusterClassificationUNCLASSIFIED = "UNCLASSIFIED"
|
||||
ClusterClassificationCapability = "CAPABILITY"
|
||||
ClusterClassificationCapacity = "CAPACITY"
|
||||
ClusterClassificationCapapacity = "CAPAPACITY"
|
||||
)
|
||||
|
||||
// Cluster flags constants for GetClustersOptions.Flags
|
||||
// and DeleteClusterOptions.Flags.
|
||||
const (
|
||||
ClusterFlagRegistering = "REGISTERING"
|
||||
ClusterFlagMultipleSlurmd = "MULTIPLE_SLURMD"
|
||||
ClusterFlagFrontEnd = "FRONT_END"
|
||||
ClusterFlagCrayNative = "CRAY_NATIVE"
|
||||
ClusterFlagFederation = "FEDERATION"
|
||||
ClusterFlagExternal = "EXTERNAL"
|
||||
)
|
||||
|
||||
// GetClustersOptions specifies optional query parameters for GetClusters and GetCluster.
|
||||
type GetClustersOptions struct {
|
||||
Classification *string `url:"classification,omitempty"`
|
||||
Cluster *string `url:"cluster,omitempty"` // CSV cluster list
|
||||
Federation *string `url:"federation,omitempty"` // CSV federation list
|
||||
Flags *string `url:"flags,omitempty"` // Use ClusterFlag* constants
|
||||
Format *string `url:"format,omitempty"` // CSV format list
|
||||
RpcVersion *string `url:"rpc_version,omitempty"` // CSV RPC version list
|
||||
UsageEnd *string `url:"usage_end,omitempty"` // Usage end UNIX timestamp (seconds)
|
||||
UsageStart *string `url:"usage_start,omitempty"` // Usage start UNIX timestamp (seconds)
|
||||
WithDeleted *string `url:"with_deleted,omitempty"` // Include deleted clusters
|
||||
WithUsage *string `url:"with_usage,omitempty"` // Query usage
|
||||
}
|
||||
|
||||
// DeleteClusterOptions specifies optional query parameters for DeleteCluster.
|
||||
type DeleteClusterOptions struct {
|
||||
Classification *string `url:"classification,omitempty"`
|
||||
Cluster *string `url:"cluster,omitempty"`
|
||||
Federation *string `url:"federation,omitempty"`
|
||||
Flags *string `url:"flags,omitempty"`
|
||||
Format *string `url:"format,omitempty"`
|
||||
RpcVersion *string `url:"rpc_version,omitempty"`
|
||||
UsageEnd *string `url:"usage_end,omitempty"`
|
||||
UsageStart *string `url:"usage_start,omitempty"`
|
||||
WithDeleted *string `url:"with_deleted,omitempty"`
|
||||
WithUsage *string `url:"with_usage,omitempty"`
|
||||
}
|
||||
|
||||
func addGetClustersQueryParams(req *http.Request, opts *GetClustersOptions) error {
|
||||
if opts == nil {
|
||||
return nil
|
||||
}
|
||||
u, err := url.Parse(req.URL.String())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
q := u.Query()
|
||||
if opts.Classification != nil {
|
||||
q.Set("classification", *opts.Classification)
|
||||
}
|
||||
if opts.Cluster != nil {
|
||||
q.Set("cluster", *opts.Cluster)
|
||||
}
|
||||
if opts.Federation != nil {
|
||||
q.Set("federation", *opts.Federation)
|
||||
}
|
||||
if opts.Flags != nil {
|
||||
q.Set("flags", *opts.Flags)
|
||||
}
|
||||
if opts.Format != nil {
|
||||
q.Set("format", *opts.Format)
|
||||
}
|
||||
if opts.RpcVersion != nil {
|
||||
q.Set("rpc_version", *opts.RpcVersion)
|
||||
}
|
||||
if opts.UsageEnd != nil {
|
||||
q.Set("usage_end", *opts.UsageEnd)
|
||||
}
|
||||
if opts.UsageStart != nil {
|
||||
q.Set("usage_start", *opts.UsageStart)
|
||||
}
|
||||
if opts.WithDeleted != nil {
|
||||
q.Set("with_deleted", *opts.WithDeleted)
|
||||
}
|
||||
if opts.WithUsage != nil {
|
||||
q.Set("with_usage", *opts.WithUsage)
|
||||
}
|
||||
u.RawQuery = q.Encode()
|
||||
req.URL = u
|
||||
return nil
|
||||
}
|
||||
|
||||
// addDeleteClusterQueryParams applies DeleteClusterOptions query params to the request URL.
|
||||
func addDeleteClusterQueryParams(req *http.Request, opts *DeleteClusterOptions) error {
|
||||
if opts == nil {
|
||||
return nil
|
||||
}
|
||||
u, err := url.Parse(req.URL.String())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
q := u.Query()
|
||||
if opts.Classification != nil {
|
||||
q.Set("classification", *opts.Classification)
|
||||
}
|
||||
if opts.Cluster != nil {
|
||||
q.Set("cluster", *opts.Cluster)
|
||||
}
|
||||
if opts.Federation != nil {
|
||||
q.Set("federation", *opts.Federation)
|
||||
}
|
||||
if opts.Flags != nil {
|
||||
q.Set("flags", *opts.Flags)
|
||||
}
|
||||
if opts.Format != nil {
|
||||
q.Set("format", *opts.Format)
|
||||
}
|
||||
if opts.RpcVersion != nil {
|
||||
q.Set("rpc_version", *opts.RpcVersion)
|
||||
}
|
||||
if opts.UsageEnd != nil {
|
||||
q.Set("usage_end", *opts.UsageEnd)
|
||||
}
|
||||
if opts.UsageStart != nil {
|
||||
q.Set("usage_start", *opts.UsageStart)
|
||||
}
|
||||
if opts.WithDeleted != nil {
|
||||
q.Set("with_deleted", *opts.WithDeleted)
|
||||
}
|
||||
if opts.WithUsage != nil {
|
||||
q.Set("with_usage", *opts.WithUsage)
|
||||
}
|
||||
u.RawQuery = q.Encode()
|
||||
req.URL = u
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetClusters lists all clusters.
|
||||
func (s *SlurmdbClustersService) GetClusters(ctx context.Context, opts *GetClustersOptions) (*OpenapiClustersResp, *Response, error) {
|
||||
path := "slurmdb/v0.0.40/clusters"
|
||||
req, err := s.client.NewRequest("GET", path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
if err := addGetClustersQueryParams(req, opts); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
var result OpenapiClustersResp
|
||||
resp, err := s.client.Do(ctx, req, &result)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return &result, resp, nil
|
||||
}
|
||||
|
||||
// GetCluster gets a single cluster by name.
|
||||
func (s *SlurmdbClustersService) GetCluster(ctx context.Context, clusterName string, opts *GetClustersOptions) (*OpenapiClustersResp, *Response, error) {
|
||||
path := fmt.Sprintf("slurmdb/v0.0.40/cluster/%s", clusterName)
|
||||
req, err := s.client.NewRequest("GET", path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
if err := addGetClustersQueryParams(req, opts); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
var result OpenapiClustersResp
|
||||
resp, err := s.client.Do(ctx, req, &result)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return &result, resp, nil
|
||||
}
|
||||
|
||||
// PostClusters creates or updates clusters.
|
||||
func (s *SlurmdbClustersService) PostClusters(ctx context.Context, body *OpenapiClustersResp) (*OpenapiResp, *Response, error) {
|
||||
path := "slurmdb/v0.0.40/clusters"
|
||||
req, err := s.client.NewRequest("POST", path, body)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
var result OpenapiResp
|
||||
resp, err := s.client.Do(ctx, req, &result)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return &result, resp, nil
|
||||
}
|
||||
|
||||
// DeleteCluster deletes a cluster by name.
|
||||
func (s *SlurmdbClustersService) DeleteCluster(ctx context.Context, clusterName string, opts *DeleteClusterOptions) (*OpenapiClustersRemovedResp, *Response, error) {
|
||||
path := fmt.Sprintf("slurmdb/v0.0.40/cluster/%s", clusterName)
|
||||
req, err := s.client.NewRequest("DELETE", path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
if err := addDeleteClusterQueryParams(req, opts); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
var result OpenapiClustersRemovedResp
|
||||
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