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

99 lines
2.6 KiB
Go
Raw Normal View History

2022-10-03 16:56:47 +03:00
package disks
import (
"context"
"encoding/json"
"net/http"
2024-04-16 14:26:06 +03:00
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
2022-10-03 16:56:47 +03:00
)
2023-10-23 12:40:54 +03:00
// ListRequest struct to get list/list_deleted of disks
2022-10-03 16:56:47 +03:00
type ListRequest struct {
2023-07-07 12:40:03 +03:00
// Find by id
// Required: false
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
// Find by name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by account name
// Required: false
AccountName string `url:"accountName,omitempty" json:"accountName,omitempty"`
// Find by max size disk
// Required: false
DiskMaxSize int64 `url:"diskMaxSize,omitempty" json:"diskMaxSize,omitempty"`
// Find by status
// Required: false
Status string `url:"status,omitempty" json:"status,omitempty"`
// Find by shared, true or false
// Required: false
2024-05-31 13:35:39 +03:00
Shared interface{} `url:"shared,omitempty" json:"shared,omitempty" validate:"omitempty,isBool"`
2023-07-07 12:40:03 +03:00
2022-12-22 17:56:47 +03:00
// ID of the account the disks belong to
// Required: false
2023-03-01 19:05:53 +03:00
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
2022-12-22 17:56:47 +03:00
// Type of the disks
// Required: false
2023-03-01 19:05:53 +03:00
Type string `url:"type,omitempty" json:"type,omitempty"`
2022-12-22 17:56:47 +03:00
2023-08-09 19:33:50 +03:00
// Find by sep ID
// Required: false
SEPID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
2025-09-11 15:56:44 +03:00
// Find by storage policy id
// Required: false
StoragePolicyID uint64 `url:"storage_policy_id,omitempty" json:"storage_policy_id,omitempty"`
2023-08-09 19:33:50 +03:00
// Find by pool name
// Required: false
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
2024-04-16 14:26:06 +03:00
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
2022-12-22 17:56:47 +03:00
// Page number
// Required: false
2023-03-01 19:05:53 +03:00
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
2022-12-22 17:56:47 +03:00
// Page size
// Required: false
2023-03-01 19:05:53 +03:00
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
2022-10-03 16:56:47 +03:00
}
2023-10-23 12:40:54 +03:00
// List gets list of the created disks belonging to an account as a ListDisks struct
2023-07-07 12:40:03 +03:00
func (d Disks) List(ctx context.Context, req ListRequest) (*ListDisks, error) {
2023-10-23 12:40:54 +03:00
res, err := d.ListRaw(ctx, req)
2022-10-03 16:56:47 +03:00
if err != nil {
return nil, err
}
2022-12-22 17:56:47 +03:00
list := ListDisks{}
2022-10-03 16:56:47 +03:00
2022-12-22 17:56:47 +03:00
err = json.Unmarshal(res, &list)
2022-10-03 16:56:47 +03:00
if err != nil {
return nil, err
}
2023-07-07 12:40:03 +03:00
return &list, nil
2022-10-03 16:56:47 +03:00
}
2023-10-23 12:40:54 +03:00
// ListRaw gets list of the created disks belonging to an account as an array of bytes
func (d Disks) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
2024-04-16 14:26:06 +03:00
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
2023-10-23 12:40:54 +03:00
url := "/cloudbroker/disks/list"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}