Files
decort-golang-sdk/pkg/cloudbroker/vgpu/list.go

85 lines
2.0 KiB
Go
Raw Normal View History

2023-04-20 11:17:35 +03:00
package vgpu
import (
"context"
"encoding/json"
"net/http"
2024-04-16 14:26:06 +03:00
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
2023-04-20 11:17:35 +03:00
)
2023-10-23 12:40:54 +03:00
// ListRequest struct to get list of VGPU
2023-04-20 11:17:35 +03:00
type ListRequest struct {
2023-07-13 15:28:07 +03:00
// Find by id
// Required: false
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
// Find by vgpu status
// Required: false
Status string `url:"status,omitempty" json:"status,omitempty"`
2026-08-21 17:52:28 +04:00
// Find by mode
2023-07-13 15:28:07 +03:00
// Required: false
2026-08-21 17:52:28 +04:00
SplitMode string `url:"split_mode,omitempty" json:"split_mode,omitempty"`
2023-07-13 15:28:07 +03:00
2024-12-27 11:35:22 +03:00
// Find by id node
// Required: false
2026-08-21 17:52:28 +04:00
NodeID uint64 `url:"node_id,omitempty" json:"node_id,omitempty"`
2024-12-27 11:35:22 +03:00
2023-07-13 15:28:07 +03:00
// Find by account id
// Required: false
2026-08-21 17:52:28 +04:00
AccountID uint64 `url:"account_id,omitempty" json:"account_id,omitempty"`
2023-07-13 15:28:07 +03:00
// Find by compute id
// Required: false
2026-08-21 17:52:28 +04:00
ComputeID uint64 `url:"compute_id,omitempty" json:"compute_id,omitempty"`
2023-07-13 15:28:07 +03:00
// Find by pgpu id
// Required: false
2026-08-21 17:52:28 +04:00
PGPUID uint64 `url:"pgpu_id,omitempty" json:"pgpu_id,omitempty"`
2023-07-13 15:28:07 +03:00
2024-04-16 14:26:06 +03:00
// Sort by one of supported fields, format +|-(field)
// Required: false
2026-08-21 17:52:28 +04:00
SortBy string `url:"sort_by,omitempty" json:"sort_by,omitempty" validate:"omitempty,sortBy"`
2024-04-16 14:26:06 +03:00
2023-04-20 11:17:35 +03:00
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
2023-10-23 12:40:54 +03:00
// List gets list of all VGPU as a ListVGPU struct
2023-07-13 15:28:07 +03:00
func (v VGPU) List(ctx context.Context, req ListRequest) (*ListVGPU, error) {
2024-04-16 14:26:06 +03:00
2023-10-23 12:40:54 +03:00
res, err := v.ListRaw(ctx, req)
2023-04-20 11:17:35 +03:00
if err != nil {
return nil, err
}
list := ListVGPU{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
2023-07-13 15:28:07 +03:00
return &list, nil
2023-04-20 11:17:35 +03:00
}
2023-10-23 12:40:54 +03:00
// ListRaw gets list of all VGPU as an array of bytes
func (v VGPU) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
2024-04-16 14:26:06 +03:00
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
2023-10-23 12:40:54 +03:00
url := "/cloudbroker/vgpu/list"
2026-08-21 17:52:28 +04:00
res, err := v.client.DecortApiCall(ctx, http.MethodGet, url, req)
2023-10-23 12:40:54 +03:00
return res, err
}