package slurm import ( "context" "net/url" ) // GetAssocsOptions specifies optional query parameters for association endpoints. // Shared by GetAssociations, GetAssociation, DeleteAssociations, and DeleteAssociation. type GetAssocsOptions struct { Account *string `url:"account,omitempty"` Cluster *string `url:"cluster,omitempty"` DefaultQos *string `url:"default_qos,omitempty"` Format *string `url:"format,omitempty"` ID *string `url:"id,omitempty"` OnlyDefaults *string `url:"only_defaults,omitempty"` ParentAccount *string `url:"parent_account,omitempty"` Partition *string `url:"partition,omitempty"` Qos *string `url:"qos,omitempty"` UsageEnd *string `url:"usage_end,omitempty"` UsageStart *string `url:"usage_start,omitempty"` User *string `url:"user,omitempty"` WithUsage *string `url:"with_usage,omitempty"` WithDeleted *string `url:"with_deleted,omitempty"` WithRawQos *string `url:"with_raw_qos,omitempty"` WithSubAccts *string `url:"with_sub_accts,omitempty"` WithoutParentInfo *string `url:"without_parent_info,omitempty"` WithoutParentLimits *string `url:"without_parent_limits,omitempty"` } // setAssocsQueryParams applies GetAssocsOptions fields as query parameters on the request URL. func setAssocsQueryParams(reqURL *url.URL, opts *GetAssocsOptions) { if opts == nil { return } q := reqURL.Query() if opts.Account != nil { q.Set("account", *opts.Account) } if opts.Cluster != nil { q.Set("cluster", *opts.Cluster) } if opts.DefaultQos != nil { q.Set("default_qos", *opts.DefaultQos) } if opts.Format != nil { q.Set("format", *opts.Format) } if opts.ID != nil { q.Set("id", *opts.ID) } if opts.OnlyDefaults != nil { q.Set("only_defaults", *opts.OnlyDefaults) } if opts.ParentAccount != nil { q.Set("parent_account", *opts.ParentAccount) } if opts.Partition != nil { q.Set("partition", *opts.Partition) } if opts.Qos != nil { q.Set("qos", *opts.Qos) } if opts.UsageEnd != nil { q.Set("usage_end", *opts.UsageEnd) } if opts.UsageStart != nil { q.Set("usage_start", *opts.UsageStart) } if opts.User != nil { q.Set("user", *opts.User) } if opts.WithUsage != nil { q.Set("with_usage", *opts.WithUsage) } if opts.WithDeleted != nil { q.Set("with_deleted", *opts.WithDeleted) } if opts.WithRawQos != nil { q.Set("with_raw_qos", *opts.WithRawQos) } if opts.WithSubAccts != nil { q.Set("with_sub_accts", *opts.WithSubAccts) } if opts.WithoutParentInfo != nil { q.Set("without_parent_info", *opts.WithoutParentInfo) } if opts.WithoutParentLimits != nil { q.Set("without_parent_limits", *opts.WithoutParentLimits) } reqURL.RawQuery = q.Encode() } // GetAssociations lists all associations matching the given options. func (s *SlurmdbAssocsService) GetAssociations(ctx context.Context, opts *GetAssocsOptions) (*OpenapiAssocsResp, *Response, error) { path := "slurmdb/v0.0.40/associations" 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 } setAssocsQueryParams(u, opts) req.URL = u } var result OpenapiAssocsResp resp, err := s.client.Do(ctx, req, &result) if err != nil { return nil, resp, err } return &result, resp, nil } // GetAssociation gets a single association matching the given options. func (s *SlurmdbAssocsService) GetAssociation(ctx context.Context, opts *GetAssocsOptions) (*OpenapiAssocsResp, *Response, error) { path := "slurmdb/v0.0.40/association" 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 } setAssocsQueryParams(u, opts) req.URL = u } var result OpenapiAssocsResp resp, err := s.client.Do(ctx, req, &result) if err != nil { return nil, resp, err } return &result, resp, nil } // PostAssociations creates or updates associations. func (s *SlurmdbAssocsService) PostAssociations(ctx context.Context, body *OpenapiAssocsResp) (*OpenapiResp, *Response, error) { path := "slurmdb/v0.0.40/associations" 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 } // DeleteAssociations deletes associations matching the given options. func (s *SlurmdbAssocsService) DeleteAssociations(ctx context.Context, opts *GetAssocsOptions) (*OpenapiAssocsRemovedResp, *Response, error) { path := "slurmdb/v0.0.40/associations" req, err := s.client.NewRequest("DELETE", 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 } setAssocsQueryParams(u, opts) req.URL = u } var result OpenapiAssocsRemovedResp resp, err := s.client.Do(ctx, req, &result) if err != nil { return nil, resp, err } return &result, resp, nil } // DeleteAssociation deletes a single association matching the given options. func (s *SlurmdbAssocsService) DeleteAssociation(ctx context.Context, opts *GetAssocsOptions) (*OpenapiAssocsRemovedResp, *Response, error) { path := "slurmdb/v0.0.40/association" req, err := s.client.NewRequest("DELETE", 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 } setAssocsQueryParams(u, opts) req.URL = u } var result OpenapiAssocsRemovedResp resp, err := s.client.Do(ctx, req, &result) if err != nil { return nil, resp, err } return &result, resp, nil }