This commit is contained in:
2026-08-21 17:52:28 +04:00
parent d7b8f08b4d
commit eb195dd992
116 changed files with 2719 additions and 1973 deletions

View File

@@ -2,6 +2,7 @@ package kvmx86
import (
"context"
"encoding/json"
"net/http"
"strconv"
@@ -81,6 +82,10 @@ type Interface struct {
// Default: true
// Required: false
EnableDefaultGateway interface{} `url:"enable_default_gateway,omitempty" json:"enable_default_gateway,omitempty" validate:"omitempty,isBool"`
// List of QoS Policy IDs to apply to this interface (default: []), Allow used only with netType VINS, EXTNET and DPDK
// Required: false
QoSPolicies []uint64 `url:"qos_policies,omitempty" json:"qos_policies,omitempty"`
}
// DataDisk detailed struct for DataDisks field in CreateRequest and CreateBlankRequest
@@ -114,6 +119,11 @@ type DataDisk struct {
// Specify image id for create disk from template
// Required: false
ImageID uint64 `url:"imageId,omitempty" json:"imageId,omitempty"`
// Attach disk in read-only mode
// Required: false
// Default: false
ReadOnly bool `url:"read_only,omitempty" json:"read_only,omitempty"`
}
// CreateRequest struct to create KVM x86 VM
@@ -199,12 +209,12 @@ type CreateRequest struct {
// loose (use NUMA affinity if possible)
// Required: false
// Default: none
NumaAffinity string `url:"numaAffinity,omitempty" json:"numaAffinity,omitempty" validate:"omitempty,numaAffinity"`
NumaAffinity string `url:"numa_affinity,omitempty" json:"numa_affinity,omitempty" validate:"omitempty,numaAffinity"`
// Run VM on dedicated CPUs. To use this feature, the system must be pre-configured by allocating CPUs on the physical node
// Required: false
// Default: false
CPUPin bool `url:"cpupin" json:"cpupin"`
CPUPin bool `url:"cpu_pin" json:"cpu_pin"`
// Type of the emulated system, Q35 or i440fx
// Required: false
@@ -214,7 +224,7 @@ type CreateRequest struct {
// Use Huge Pages to allocate RAM of the virtual machine. The system must be pre-configured by allocating Huge Pages on the physical node
// Required: false
// Default: false
HPBacked bool `url:"hpBacked" json:"hpBacked"`
HPBacked bool `url:"hp_backed" json:"hp_backed"`
// Recommended isolated CPUs. Field is ignored if compute.cpupin=False or compute.pinned=False
// Required: false
@@ -232,6 +242,11 @@ type CreateRequest struct {
// Required: false
// Default: default
Clock string `url:"clock,omitempty" json:"clock,omitempty"`
// Watchdog action
// Required: false
// Default: reset
WatchdogAction string `url:"watchdog_action,omitempty" json:"watchdog_action,omitempty" validate:"omitempty,watchdogAction"`
}
// GetRAM returns RAM field values
@@ -243,6 +258,11 @@ func (r CreateRequest) GetRAM() map[string]uint64 {
return res
}
type wrapperCreateRequest struct {
CreateRequest
AsyncMode bool `json:"asyncMode"`
}
// Create creates KVM x86 VM based on specified OS image
func (k KVMX86) Create(ctx context.Context, req CreateRequest) (uint64, error) {
err := validators.ValidateRequest(req)
@@ -252,10 +272,40 @@ func (k KVMX86) Create(ctx context.Context, req CreateRequest) (uint64, error) {
url := "/cloudapi/kvmx86/create"
res, err := k.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
res, err := k.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, wrapperCreateRequest{
CreateRequest: req,
AsyncMode: false,
})
if err != nil {
return 0, err
}
return strconv.ParseUint(string(res), 10, 64)
}
// CreateAsync creates KVM x86 VM based on specified OS image in async mode
func (k KVMX86) CreateAsync(ctx context.Context, req CreateRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/kvmx86/create"
res, err := k.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, wrapperCreateRequest{
CreateRequest: req,
AsyncMode: true,
})
if err != nil {
return "", err
}
var taskID string
err = json.Unmarshal(res, &taskID)
if err != nil {
return "", err
}
return taskID, nil
}