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

55 lines
1.2 KiB
Go
Raw Normal View History

2023-04-20 11:17:35 +03:00
package vgpu
import (
"context"
"net/http"
"strconv"
2026-08-21 17:52:28 +04:00
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
2023-04-20 11:17:35 +03:00
)
2023-10-25 17:37:18 +03:00
// CreateRequest struct for creating VGPU
2023-04-20 11:17:35 +03:00
type CreateRequest struct {
// ID of pGPU
// Required: true
2026-08-21 17:52:28 +04:00
PGPUID uint64 `url:"pgpu_id" json:"pgpu_id" validate:"required"`
2023-04-20 11:17:35 +03:00
// Virtual profile id
// Required: false
2026-08-21 17:52:28 +04:00
ProfileID string `url:"profile_id,omitempty" json:"profile_id,omitempty"`
// MDEV Type
// Required: false
MDEVType string `url:"mdev_type,omitempty" json:"mdev_type,omitempty"`
// PCI Address
// Required: false
PCIAddress string `url:"pci_address,omitempty" json:"pci_address,omitempty"`
2023-04-20 11:17:35 +03:00
2026-08-21 17:52:28 +04:00
// Account IDs
2023-04-20 11:17:35 +03:00
// Required: false
2026-08-21 17:52:28 +04:00
AccountIDs []uint64 `url:"account_ids,omitempty" json:"account_ids,omitempty"`
2023-04-20 11:17:35 +03:00
}
// Create creates VGPU
func (v VGPU) Create(ctx context.Context, req CreateRequest) (uint64, error) {
err := validators.ValidateRequest(req)
if err != nil {
2023-10-25 17:37:18 +03:00
return 0, validators.ValidationErrors(validators.GetErrors(err))
2023-04-20 11:17:35 +03:00
}
url := "/cloudbroker/vgpu/create"
res, err := v.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
}