v1.9.0
This commit is contained in:
@@ -15,6 +15,7 @@ type Interface struct {
|
||||
// - VINS
|
||||
// - EXTNET
|
||||
// - VFNIC
|
||||
// - DPDK
|
||||
NetType string `url:"netType" json:"netType" validate:"required,kvmx86NetType"`
|
||||
|
||||
// Network ID for connect to,
|
||||
@@ -154,14 +155,14 @@ type CreateRequest struct {
|
||||
// Default: false
|
||||
CPUPin bool `url:"cpupin" json:"cpupin"`
|
||||
|
||||
// Type of the emulated system, Q35 or i440fx
|
||||
// Required: false
|
||||
Chipset string `url:"chipset,omitempty" json:"chipset,omitempty"`
|
||||
|
||||
// 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"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
|
||||
}
|
||||
|
||||
// GetRAM returns RAM field values
|
||||
|
||||
@@ -64,6 +64,10 @@ type CreateBlankRequest struct {
|
||||
//Type of compute Stateful (KVM_X86) or Stateless (SVA_KVM_X86)
|
||||
// Required: false
|
||||
Driver string `url:"driver,omitempty" json:"driver,omitempty"`
|
||||
|
||||
// Type of the emulated system, Q35 or i440fx
|
||||
// Required: false
|
||||
Chipset string `url:"chipset,omitempty" json:"chipset,omitempty"`
|
||||
}
|
||||
|
||||
// GetRAM returns RAM field values
|
||||
|
||||
@@ -76,9 +76,14 @@ type MassCreateRequest struct {
|
||||
// Required: false
|
||||
Start bool `url:"start" json:"start"`
|
||||
|
||||
// Reason to action
|
||||
// Type of the emulated system, Q35 or i440fx
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
|
||||
Chipset string `url:"chipset,omitempty" json:"chipset,omitempty"`
|
||||
}
|
||||
|
||||
type asyncWrapperMassCreateRequest struct {
|
||||
wrapperMassCreateRequest
|
||||
AsyncMode bool `url:"asyncMode"`
|
||||
}
|
||||
|
||||
// GetRAM returns RAM field values
|
||||
@@ -142,9 +147,11 @@ func (k KVMX86) MassCreate(ctx context.Context, req MassCreateRequest) ([]uint64
|
||||
DataDisks: dataDisks,
|
||||
}
|
||||
|
||||
finalReq := asyncWrapperMassCreateRequest{wrapperMassCreateRequest: reqWrapped, AsyncMode: false}
|
||||
|
||||
url := "/cloudbroker/kvmx86/massCreate"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, finalReq)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -158,3 +165,67 @@ func (k KVMX86) MassCreate(ctx context.Context, req MassCreateRequest) ([]uint64
|
||||
|
||||
return computes, nil
|
||||
}
|
||||
|
||||
// MassCreate creates KVM x86 computes based on specified OS image in async mode
|
||||
func (k KVMX86) MassCreateAsync(ctx context.Context, req MassCreateRequest) (string, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
var interfaces []string
|
||||
|
||||
if req.Interfaces != nil && len(req.Interfaces) != 0 {
|
||||
interfaces = make([]string, 0, len(req.Interfaces))
|
||||
|
||||
for i := range req.Interfaces {
|
||||
b, err := json.Marshal(req.Interfaces[i])
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
interfaces = append(interfaces, string(b))
|
||||
}
|
||||
} else if req.Interfaces != nil && len(req.Interfaces) == 0 {
|
||||
interfaces = []string{"[]"}
|
||||
}
|
||||
|
||||
var dataDisks []string
|
||||
|
||||
if req.DataDisks != nil && len(req.DataDisks) != 0 {
|
||||
dataDisks = make([]string, 0, len(req.DataDisks))
|
||||
|
||||
for i := range req.DataDisks {
|
||||
b, err := json.Marshal(req.DataDisks[i])
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
dataDisks = append(dataDisks, string(b))
|
||||
}
|
||||
}
|
||||
|
||||
reqWrapped := wrapperMassCreateRequest{
|
||||
MassCreateRequest: req,
|
||||
Interfaces: interfaces,
|
||||
DataDisks: dataDisks,
|
||||
}
|
||||
|
||||
finalReq := asyncWrapperMassCreateRequest{wrapperMassCreateRequest: reqWrapped, AsyncMode: true}
|
||||
|
||||
url := "/cloudbroker/kvmx86/massCreate"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, finalReq)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
var computes string
|
||||
|
||||
err = json.Unmarshal(res, &computes)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return computes, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user