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

95 lines
3.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
// UpdateRequest struct to update compute
2022-10-03 16:56:47 +03:00
type UpdateRequest struct {
2022-12-22 17:56:47 +03:00
// ID of the compute
// 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
// New name
// Required: false
2023-03-01 19:05:53 +03:00
Name string `url:"name,omitempty" json:"name,omitempty"`
2022-12-22 17:56:47 +03:00
// New description
// Required: false
2023-03-01 19:05:53 +03:00
Description string `url:"desc,omitempty" json:"desc,omitempty"`
2024-05-31 13:35:39 +03:00
// Rule for VM placement with NUMA affinity.
// Possible values - none (placement without NUMA affinity),
// strict (strictly with NUMA affinity, if not possible - do not start VM),
// loose (use NUMA affinity if possible)
// Required: false
// Default: none
NumaAffinity string `url:"numaAffinity,omitempty" json:"numaAffinity,omitempty" validate:"omitempty,numaAffinity"`
2025-05-07 13:15:39 +03:00
// Run VM on dedicated CPUs. To use this feature, the system must be pre-configured by allocating CPUs on the physical node, true or false
2024-05-31 13:35:39 +03:00
// Required: false
2025-05-07 13:15:39 +03:00
CPUPin interface{} `url:"cpupin,omitempty" json:"cpupin,omitempty" validate:"omitempty,isBool"`
2024-05-31 13:35:39 +03:00
2024-11-12 12:51:21 +03:00
// Type of the emulated system, Q35 or i440fx
// Required: false
2024-11-22 12:09:50 +03:00
Chipset string `url:"chipset,omitempty" json:"chipset,omitempty" validate:"omitempty,chipset"`
2024-11-12 12:51:21 +03:00
2025-05-07 13:15:39 +03:00
// Use Huge Pages to allocate RAM of the virtual machine. The system must be pre-configured by allocating Huge Pages on the physical node, true or false
2024-05-31 13:35:39 +03:00
// Required: false
2025-05-07 13:15:39 +03:00
HPBacked interface{} `url:"hpBacked,omitempty" json:"hpBacked,omitempty" validate:"omitempty,isBool"`
2024-12-27 11:35:22 +03:00
2025-05-07 13:15:39 +03:00
// Auto start when node restarted, true or false
2024-12-27 11:35:22 +03:00
// Required: false
2025-05-07 13:15:39 +03:00
AutoStart interface{} `url:"autoStart,omitempty" json:"autoStart,omitempty" validate:"omitempty,isBool"`
2025-02-07 11:11:43 +03:00
// Recommended isolated CPUs. Field is ignored if compute.cpupin=False or compute.pinned=False
// Required: false
PreferredCPU []int64 `url:"preferredCpu,omitempty" json:"preferredCpu,omitempty" validate:"omitempty,preferredCPU"`
2025-04-09 11:21:07 +03:00
// VM type linux, windows or unknown
// Required: false
LoaderType string `url:"loaderType,omitempty" json:"loaderType,omitempty" validate:"omitempty,loaderType"`
// Boot type of image bios or uefi
// Required: false
BootType string `url:"bootType,omitempty" json:"bootType,omitempty" validate:"omitempty,imageBootType"`
// Select a network interface naming pattern for your Linux machine. eth - onboard, ens - pci slot naming.
// Required: false
NetworkInterfaceNaming string `url:"networkInterfaceNaming,omitempty" json:"networkInterfaceNaming,omitempty" validate:"omitempty,networkInterfaceNaming"`
2025-05-07 13:15:39 +03:00
// Does this machine supports hot resize, true or false
2025-04-09 11:21:07 +03:00
// Required: false
2025-05-07 13:15:39 +03:00
HotResize interface{} `url:"hotResize,omitempty" json:"hotResize,omitempty" validate:"omitempty,isBool"`
2025-09-11 15:56:44 +03:00
// The OS version that will be installed on the virtual machine
// Required: false
OSVersion string `url:"os_version,omitempty" json:"os_version,omitempty"`
2022-10-03 16:56:47 +03:00
}
2022-12-22 17:56:47 +03:00
// Update updates some properties of the compute
2022-10-03 16:56:47 +03:00
func (c Compute) Update(ctx context.Context, req UpdateRequest) (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/update"
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
}
2022-12-22 17:56:47 +03:00
2022-10-03 16:56:47 +03:00
return result, nil
}