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

63 lines
1.5 KiB
Go
Raw Normal View History

2022-10-03 16:56:47 +03:00
package disks
import (
"context"
"net/http"
"strconv"
2022-12-22 17:56:47 +03:00
2023-03-17 12:54:34 +03:00
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
2022-10-03 16:56:47 +03:00
)
2023-10-25 17:37:18 +03:00
// CreateRequest struct to create disk
2022-10-03 16:56:47 +03:00
type CreateRequest struct {
2022-12-22 17:56:47 +03:00
// ID of the account
// Required: true
2023-03-24 17:09:30 +03:00
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
2022-12-22 17:56:47 +03:00
// Name of disk
// Required: true
2023-03-24 17:09:30 +03:00
Name string `url:"name" json:"name" validate:"required"`
2022-12-22 17:56:47 +03:00
2025-08-29 12:51:25 +03:00
// ID of the storage policy under the disk will be created
// Required: true
StoragePolicyID uint64 `url:"storage_policy_id" json:"storage_policy_id" validate:"required"`
2022-12-22 17:56:47 +03:00
// Description of disk
// Required: false
2023-03-01 19:05:53 +03:00
Description string `url:"description,omitempty" json:"description,omitempty"`
2022-12-22 17:56:47 +03:00
// Size in GB, default is 0
// Required: false
2023-03-01 19:05:53 +03:00
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
2022-12-22 17:56:47 +03:00
// Storage endpoint provider ID to create disk
// Required: false
2023-03-01 19:05:53 +03:00
SEPID uint64 `url:"sep_id,omitempty" json:"sep_id,omitempty"`
2022-12-22 17:56:47 +03:00
// Pool name to create disk
// Required: false
2023-03-01 19:05:53 +03:00
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
2022-10-03 16:56:47 +03:00
}
2022-12-22 17:56:47 +03:00
// Create creates a disk
2022-10-03 16:56:47 +03:00
func (d Disks) Create(ctx context.Context, req CreateRequest) (uint64, error) {
2023-03-24 17:09:30 +03:00
err := validators.ValidateRequest(req)
2022-10-03 16:56:47 +03:00
if err != nil {
2023-10-25 17:37:18 +03:00
return 0, validators.ValidationErrors(validators.GetErrors(err))
2022-10-03 16:56:47 +03:00
}
url := "/cloudbroker/disks/create"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return 0, err
}
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
return 0, err
}
return result, nil
2022-12-22 17:56:47 +03:00
}