This commit is contained in:
2026-06-15 13:37:04 +03:00
parent af79f6ab3e
commit db8d13d403
40 changed files with 1892 additions and 1711 deletions

View File

@@ -17,8 +17,10 @@ func checkParamsExistence(ctx context.Context, d *schema.ResourceData, c *contro
errs = append(errs, err)
}
if err := ic.ExistImage(ctx, uint64(d.Get("image_id").(int)), c); err != nil {
errs = append(errs, err)
if !d.Get("create_blank").(bool) {
if err := ic.ExistImage(ctx, uint64(d.Get("image_id").(int)), c); err != nil {
errs = append(errs, err)
}
}
if netErrs := existNetworks(ctx, d, c); errs != nil {

View File

@@ -251,7 +251,32 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
}
log.Debugf("resourceComputeCreate: creating Compute of type KVM VM x86")
apiResp, err := c.CloudBroker().KVMX86().Create(ctx, createReqX86)
var apiResp uint64
var err error
if d.Get("create_blank").(bool) {
log.Debugf("resourceComputeCreate: using createBlank endpoint")
createBlankReq := kvmx86.CreateBlankRequest{
RGID: createReqX86.RGID,
Name: createReqX86.Name,
CPU: createReqX86.CPU,
RAM: createReqX86.RAM,
StoragePolicyID: createReqX86.StoragePolicyID,
WithoutBootDisk: createReqX86.WithoutBootDisk,
BootDisk: createReqX86.BootDisk,
SEPID: createReqX86.SEPID,
Pool: createReqX86.Pool,
DataDisks: createReqX86.DataDisks,
Interfaces: createReqX86.Interfaces,
Description: createReqX86.Description,
Chipset: createReqX86.Chipset,
PreferredCPU: createReqX86.PreferredCPU,
ZoneID: createReqX86.ZoneID,
OSVersion: createReqX86.OSVersion,
}
apiResp, err = c.CloudBroker().KVMX86().CreateBlank(ctx, createBlankReq)
} else {
apiResp, err = c.CloudBroker().KVMX86().Create(ctx, createReqX86)
}
if err != nil {
return diag.FromErr(err)
}
@@ -448,6 +473,9 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
if nodeID, ok := d.GetOk("node_id"); ok {
req.NodeID = uint64(nodeID.(int))
}
if altBootID, ok := d.Get("alt_boot_id").(int); ok {
req.AltBootID = uint64(altBootID)
}
log.Debugf("resourceComputeCreate: starting Compute ID %d after completing its resource configuration", computeId)
if _, err := c.CloudBroker().Compute().Start(ctx, req); err != nil {
warnings.Add(err)

View File

@@ -3409,6 +3409,12 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
Optional: true,
Default: false,
},
"create_blank": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "If True, the compute is created via kvmx86/createBlank endpoint (without OS image). The image_id field is not required in this case.",
},
"boot_disk_size": {
Type: schema.TypeInt,
Optional: true,
@@ -3531,22 +3537,22 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
DiffSuppressFunc: networkSubresIPAddreDiffSupperss,
Description: "unique_identifier of LogicalPort on SDN side",
},
"enabled": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "network enable flag",
},
"net_mask": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "Subnet mask, used only for DPDK and VFNIC network types",
"enabled": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "network enable flag",
},
"net_mask": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "Subnet mask, used only for DPDK and VFNIC network types",
},
},
},
Description: "Optional network connection(s) for this compute. You may specify several network blocks, one for each connection.",
},
Description: "Optional network connection(s) for this compute. You may specify several network blocks, one for each connection.",
},
"libvirt_settings": {
Type: schema.TypeSet,
@@ -3757,11 +3763,9 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
Description: "Storage endpoint provider ID; by default the same with boot disk",
},
"disk_type": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"B", "D"}, false),
Description: "The type of disk in terms of its role in compute: 'B=Boot, D=Data'",
Type: schema.TypeString,
Computed: true,
Description: "The type of disk in terms of its role in compute: 'B=Boot, D=Data'",
},
"pool": {
Type: schema.TypeString,

View File

@@ -209,7 +209,11 @@ func utilityComputeResize(ctx context.Context, d *schema.ResourceData, m interfa
}
if isStopRequired {
if _, err := c.CloudBroker().Compute().Start(ctx, compute.StartRequest{ComputeID: computeId}); err != nil {
req := compute.StartRequest{ComputeID: computeId}
if altBootID, ok := d.Get("alt_boot_id").(int); ok {
req.AltBootID = uint64(altBootID)
}
if _, err := c.CloudBroker().Compute().Start(ctx, req); err != nil {
return err
}
}
@@ -362,9 +366,6 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
if diskConv["sep_id"].(int) != 0 {
req.SepID = uint64(diskConv["sep_id"].(int))
}
if diskConv["disk_type"].(string) != "" {
req.DiskType = diskConv["disk_type"].(string)
}
if diskConv["pool"].(string) != "" {
req.Pool = diskConv["pool"].(string)
}
@@ -981,7 +982,13 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
if needStart {
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
if numErr, err := utilityComputeStart(ctx, computeId, m); err != nil {
var altBootID uint64
if altBootIDRaw, ok := d.Get("alt_boot_id").(int); ok {
altBootID = uint64(altBootIDRaw)
} else {
altBootID = 0
}
if numErr, err := utilityComputeStart(ctx, altBootID, computeId, m); err != nil {
apiErrCount += numErr
lastSavedError = err
}
@@ -1308,7 +1315,11 @@ func utilityComputeUpdate(ctx context.Context, d *schema.ResourceData, m interfa
// If used to be STARTED, we need to start it after update
if isStopRequired {
if _, err := c.CloudBroker().Compute().Start(ctx, compute.StartRequest{ComputeID: computeId}); err != nil {
req := compute.StartRequest{ComputeID: computeId}
if altBootID, ok := d.Get("alt_boot_id").(int); ok {
req.AltBootID = uint64(altBootID)
}
if _, err := c.CloudBroker().Compute().Start(ctx, req); err != nil {
return err
}
}
@@ -1779,6 +1790,9 @@ func utilityComputeRollback(ctx context.Context, d *schema.ResourceData, m inter
}
startReq := compute.StartRequest{ComputeID: computeId}
if altBootID, ok := d.Get("alt_boot_id").(int); ok {
startReq.AltBootID = uint64(altBootID)
}
log.Debugf("utilityComputeRollback: starting compute %d", computeId)
@@ -2036,10 +2050,14 @@ func utilityComputeStop(ctx context.Context, d *schema.ResourceData, m interface
return nil
}
func utilityComputeStart(ctx context.Context, computeID uint64, m interface{}) (int, error) {
func utilityComputeStart(ctx context.Context, computeID uint64, altBootID uint64, m interface{}) (int, error) {
c := m.(*controller.ControllerCfg)
startReq := compute.StartRequest{ComputeID: computeID}
if altBootID > 0 {
startReq.AltBootID = altBootID
}
log.Debugf("utilityComputeStart: starting compute %d", computeID)
_, err := c.CloudBroker().Compute().Start(ctx, startReq)
if err != nil {