feat(slurmdb): add InstancesService
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
90
internal/slurm/slurmdb_instances.go
Normal file
90
internal/slurm/slurmdb_instances.go
Normal file
@@ -0,0 +1,90 @@
|
||||
package slurm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// GetInstancesOptions specifies optional parameters for GetInstances and GetInstance.
|
||||
type GetInstancesOptions struct {
|
||||
Cluster *string `url:"cluster,omitempty"`
|
||||
Extra *string `url:"extra,omitempty"`
|
||||
InstanceID *string `url:"instance_id,omitempty"`
|
||||
InstanceType *string `url:"instance_type,omitempty"`
|
||||
}
|
||||
|
||||
// GetInstances lists all instances.
|
||||
func (s *SlurmdbInstancesService) GetInstances(ctx context.Context, opts *GetInstancesOptions) (*OpenapiInstancesResp, *Response, error) {
|
||||
path := "slurmdb/v0.0.40/instances"
|
||||
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.Cluster != nil {
|
||||
q.Set("cluster", *opts.Cluster)
|
||||
}
|
||||
if opts.Extra != nil {
|
||||
q.Set("extra", *opts.Extra)
|
||||
}
|
||||
if opts.InstanceID != nil {
|
||||
q.Set("instance_id", *opts.InstanceID)
|
||||
}
|
||||
if opts.InstanceType != nil {
|
||||
q.Set("instance_type", *opts.InstanceType)
|
||||
}
|
||||
u.RawQuery = q.Encode()
|
||||
req.URL = u
|
||||
}
|
||||
|
||||
var result OpenapiInstancesResp
|
||||
resp, err := s.client.Do(ctx, req, &result)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return &result, resp, nil
|
||||
}
|
||||
|
||||
// GetInstance returns a single instance matching the query parameters.
|
||||
func (s *SlurmdbInstancesService) GetInstance(ctx context.Context, opts *GetInstancesOptions) (*OpenapiInstancesResp, *Response, error) {
|
||||
path := "slurmdb/v0.0.40/instance"
|
||||
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.Cluster != nil {
|
||||
q.Set("cluster", *opts.Cluster)
|
||||
}
|
||||
if opts.Extra != nil {
|
||||
q.Set("extra", *opts.Extra)
|
||||
}
|
||||
if opts.InstanceID != nil {
|
||||
q.Set("instance_id", *opts.InstanceID)
|
||||
}
|
||||
if opts.InstanceType != nil {
|
||||
q.Set("instance_type", *opts.InstanceType)
|
||||
}
|
||||
u.RawQuery = q.Encode()
|
||||
req.URL = u
|
||||
}
|
||||
|
||||
var result OpenapiInstancesResp
|
||||
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