Files
decort-golang-sdk/pkg/cloudapi/compute/disk_attach.go

55 lines
1.4 KiB
Go
Raw Normal View History

2022-10-03 16:56:47 +03:00
package compute
import (
"context"
"net/http"
"strconv"
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
// DiskAttachRequest struct to attach disk to compute
2022-10-03 16:56:47 +03:00
type DiskAttachRequest struct {
2022-12-22 17:56:47 +03:00
// ID of compute instance
// Required: true
2023-03-17 12:54:34 +03:00
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
2022-12-22 17:56:47 +03:00
// ID of the disk to attach
// Required: true
2023-03-17 12:54:34 +03:00
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
2023-04-28 11:46:58 +03:00
// Type of the disk B;D
// Required: false
DiskType string `url:"diskType,omitempty" json:"diskType,omitempty" validate:"omitempty,computeDiskType"`
2025-09-19 13:45:58 +03:00
// Desired PCI slot (hex string, e.g. "0x1A")
// Required: false
PCISlot string `url:"pci_slot,omitempty" json:"pci_slot,omitempty"`
// Desired bus number (hex string, e.g. "0x03")
// Required: false
BusNumber string `url:"bus_number,omitempty" json:"bus_number,omitempty"`
2022-10-03 16:56:47 +03:00
}
2022-12-22 17:56:47 +03:00
// DiskAttach attach disk to compute
2022-10-03 16:56:47 +03:00
func (c Compute) DiskAttach(ctx context.Context, req DiskAttachRequest) (bool, error) {
2023-03-17 12:54:34 +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 false, validators.ValidationErrors(validators.GetErrors(err))
2022-10-03 16:56:47 +03:00
}
url := "/cloudapi/compute/diskAttach"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}