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

56 lines
1.3 KiB
Go
Raw Normal View History

2023-04-20 11:17:35 +03:00
package pcidevice
import (
"context"
"net/http"
"strconv"
2025-12-08 16:16:35 +03: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 to creating PCI device
2023-04-20 11:17:35 +03:00
type CreateRequest struct {
2025-12-08 16:16:35 +03:00
// NodeID
2023-04-20 11:17:35 +03:00
// Required: true
2025-12-08 16:16:35 +03:00
NodeID uint64 `url:"node_id" json:"node_id" validate:"required"`
2023-04-20 11:17:35 +03:00
// Resource group ID
// Required: true
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
// Name of device
// Required: true
Name string `url:"name" json:"name" validate:"required"`
// PCI address of the device
// Must be in format 0000:1f:2b.0
// Required: true
HWPath string `url:"hwPath" json:"hwPath" validate:"required,hwPath"`
// Description, just for information
// Required: false
Description string `url:"description,omitempty" json:"description,omitempty"`
}
// Create creates PCI Device
func (p PCIDevice) 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/pcidevice/create"
res, err := p.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
}