This commit is contained in:
2026-08-21 18:12:55 +04:00
parent f34fa6055c
commit 3c5157281e
1285 changed files with 4016 additions and 3302 deletions

View File

@@ -2,11 +2,12 @@ package kvmx86
import (
"context"
"encoding/json"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v15/internal/constants"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v15/internal/validators"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v16/internal/constants"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v16/internal/validators"
)
type Interface struct {
@@ -79,6 +80,10 @@ type Interface struct {
// SDN Logical Port Description
// Required: false
SDNLogicalPortDescription string `url:"sdn_logical_port_description,omitempty" json:"sdn_logical_port_description,omitempty"`
// 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, CreateBlankRequest and MassCreateRequest
@@ -120,6 +125,11 @@ type DataDisk struct {
// Discard
// Required: false
Discard string `url:"discard,omitempty" json:"discard,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
@@ -209,12 +219,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
@@ -224,7 +234,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
@@ -255,6 +265,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
@@ -266,6 +281,11 @@ func (r CreateRequest) GetRAM() map[string]uint64 {
return res
}
type wrapperCreateRequest struct {
CreateRequest
AsyncMode bool `json:"asyncMode"`
}
// Create creates KVM PowerPC VM based on specified OS image
func (k KVMX86) Create(ctx context.Context, req CreateRequest) (uint64, error) {
err := validators.ValidateRequest(req)
@@ -275,10 +295,40 @@ func (k KVMX86) Create(ctx context.Context, req CreateRequest) (uint64, error) {
url := "/cloudbroker/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 := "/cloudbroker/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
}