This commit is contained in:
2026-06-02 11:28:16 +03:00
parent af79f6ab3e
commit c734dcfff7
254 changed files with 10439 additions and 3751 deletions

View File

@@ -18,7 +18,7 @@ func flattenCompute(d *schema.ResourceData, computeRec *compute.RecordCompute, p
customFields, _ := json.Marshal(computeRec.CustomFields)
devices, _ := json.Marshal(computeRec.Devices)
userData, _ := json.Marshal(computeRec.Userdata)
bootDisk := findBootDisk(computeRec.Disks)
bootDisk := findBootDisk(computeRec.Disks, computeRec.Chipset)
if len(computeRec.Interfaces) > 0 {
log.Debugf("flattenCompute: calling parseComputeInterfacesToNetworks for %d interfaces", len(computeRec.Interfaces))
@@ -113,6 +113,7 @@ func flattenCompute(d *schema.ResourceData, computeRec *compute.RecordCompute, p
d.Set("cpu_pin", computeRec.CPUPin)
d.Set("numa_affinity", computeRec.NumaAffinity)
d.Set("hp_backed", computeRec.HPBacked)
d.Set("weight", computeRec.Weight)
return nil
}
@@ -269,10 +270,12 @@ func flattenComputeDisks(disksList compute.ListDisks, disksBlocks, extraDisks []
"node_ids": nodeIds,
"size": disk.SizeMax,
"sep_id": disk.SEPID,
"disk_type": disk.Type,
"pci_slot": disk.PCISlot,
"bus_number": disk.BusNumber,
"pool": disk.Pool,
"desc": disk.Description,
"image_id": disk.ImageID,
"independent": disk.Independent,
"disk_id": disk.ID,
"shareable": disk.Shareable,
"size_used": disk.SizeUsed,
@@ -289,6 +292,8 @@ func flattenComputeDisks(disksList compute.ListDisks, disksBlocks, extraDisks []
"update_time": disk.UpdatedTime,
"cache": disk.Cache,
"blk_discard": disk.BLKDiscard,
"block_size": disk.BlockSize,
"provision": disk.Provision,
"iotune": flattenIOTune(disk.IOTune),
}
res = append(res, temp)
@@ -408,6 +413,7 @@ func flattenComputeList(computes *compute.ListComputes) []map[string]interface{}
"hot_resize": computeItem.HotResize,
"network_interface_naming": computeItem.NetworkInterfaceNaming,
"zone_id": computeItem.ZoneID,
"weight": computeItem.Weight,
}
res = append(res, temp)
}
@@ -495,6 +501,7 @@ func flattenDeletedComputeList(computes *compute.ListDeletedComputes) []map[stri
"hot_resize": computeItem.HotResize,
"network_interface_naming": computeItem.NetworkInterfaceNaming,
"zone_id": computeItem.ZoneID,
"weight": computeItem.Weight,
}
res = append(res, temp)
}
@@ -842,8 +849,9 @@ func flattenDataCompute(d *schema.ResourceData, compFacts *compute.RecordCompute
d.Set("zone_id", compFacts.ZoneID)
d.Set("loader_meta_iso", flattenLoaderMetaIso(compFacts.LoaderMetaIso))
d.Set("os_version", compFacts.OSVersion)
d.Set("weight", compFacts.Weight)
//extra fields setting
bootDisk := findBootDisk(compFacts.Disks)
bootDisk := findBootDisk(compFacts.Disks, compFacts.Chipset)
if bootDisk != nil {
d.Set("boot_disk_size", bootDisk.SizeMax)
d.Set("boot_disk_id", bootDisk.ID) // we may need boot disk ID in resize operations
@@ -900,6 +908,7 @@ func flattenDisk(diskList compute.ListDisks) []map[string]interface{} {
"meta": flattens.FlattenMeta(disk.Meta),
"account_id": disk.AccountID,
"blk_discard": disk.BLKDiscard,
"block_size": disk.BlockSize,
"boot_partition": disk.BootPartition,
"bus_number": disk.BusNumber,
"created_time": disk.CreatedTime,
@@ -915,6 +924,7 @@ func flattenDisk(diskList compute.ListDisks) []map[string]interface{} {
"disk_id": disk.ID,
"image_id": disk.ImageID,
"images": disk.Images,
"independent": disk.Independent,
"iotune": flattenIOTune(disk.IOTune),
"iqn": disk.IQN,
"login": disk.Login,
@@ -945,6 +955,7 @@ func flattenDisk(diskList compute.ListDisks) []map[string]interface{} {
"tech_status": disk.TechStatus,
"type": disk.Type,
"to_clean": disk.ToClean,
"provision": disk.Provision,
"updated_time": disk.UpdatedTime,
}
res = append(res, temp)

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 {
@@ -26,7 +28,7 @@ func checkParamsExistence(ctx context.Context, d *schema.ResourceData, c *contro
}
if disks, ok := d.GetOk("disks"); ok {
if err := ic.IsMoreThanOneDisksTypeB(ctx, disks); err != nil {
if err := ic.IsMoreThanOneDisksTypeB(ctx, disks, d.Get("chipset").(string)); err != nil {
errs = append(errs, err)
}
}
@@ -37,8 +39,7 @@ func checkParamsExistence(ctx context.Context, d *schema.ResourceData, c *contro
func existNetworks(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg) []error {
var errs []error
var vinsIds, extNetIds, vfpoolIds, dpdkIds, trunkIds []uint64
//TODO
//var sdnIds []string
var sdnIds []string
networksIface, ok := d.GetOk("network")
if !ok {
@@ -60,10 +61,8 @@ func existNetworks(ctx context.Context, d *schema.ResourceData, c *controller.Co
dpdkIds = append(dpdkIds, uint64(network["net_id"].(int)))
case "TRUNK":
trunkIds = append(trunkIds, uint64(network["net_id"].(int)))
//TODO
//case "SDN": sdnIds = append(sdnIds, network["sdn_interface_id"].(string))
case "SDN":
sdnIds = append(sdnIds, network["sdn_interface_id"].(string))
default:
continue
}
@@ -89,10 +88,9 @@ func existNetworks(ctx context.Context, d *schema.ResourceData, c *controller.Co
errs = append(errs, trunkErrs...)
}
//TODO
//if sdnErrs := ic.ExistSDNNet(ctx, sdnIds, c); sdnErrs != nil {
// errs = append(errs, sdnErrs...)
//}
if sdnErrs := ic.ExistSDNNet(ctx, sdnIds, c); sdnErrs != nil {
errs = append(errs, sdnErrs...)
}
return errs
}

View File

@@ -77,10 +77,6 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
createReqX86.NodeID = uint64(nodeID.(int))
}
if ipaType, ok := d.GetOk("ipa_type"); ok {
createReqX86.IPAType = ipaType.(string)
}
if bootSize, ok := d.GetOk("boot_disk_size"); ok {
createReqX86.BootDisk = uint64(bootSize.(int))
}
@@ -89,10 +85,6 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
createReqX86.BootDiskCache = bootDiskCache.(string)
}
if IS, ok := d.GetOk("is"); ok {
createReqX86.IS = IS.(string)
}
if zoneID, ok := d.GetOk("zone_id"); ok {
createReqX86.ZoneID = uint64(zoneID.(int))
}
@@ -130,7 +122,7 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
reqInterface.Enabled = netInterfaceVal["enabled"].(bool)
}
if reqInterface.NetType == "DPDK" || reqInterface.NetType == "EXTNET" {
if reqInterface.NetType == "DPDK" || reqInterface.NetType == "EXTNET" || reqInterface.NetType == "TRUNK" {
reqInterface.MTU = uint64(netInterfaceVal["mtu"].(int))
}
@@ -251,7 +243,33 @@ 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)
}
@@ -291,6 +309,7 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
bootType, bootTypeOk := d.GetOk("boot_type")
hotResize, hotResizeOk := d.GetOkExists("hot_resize")
networkInterfaceNaming, networkInterfaceNamingOk := d.GetOk("network_interface_naming")
weight, weightOk := d.GetOk("weight")
if loaderTypeOk {
updateReq.LoaderType = loaderType.(string)
@@ -308,8 +327,12 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
updateReq.NetworkInterfaceNaming = networkInterfaceNaming.(string)
}
if loaderTypeOk || bootTypeOk || hotResizeOk || networkInterfaceNamingOk {
log.Debugf("resourceComputeCreate: change loaderType or bootType or hotResize or networkInterfaceNaming on ComputeID: %d", computeId)
if weightOk {
updateReq.Weight = uint64(weight.(int))
}
if loaderTypeOk || bootTypeOk || hotResizeOk || networkInterfaceNamingOk || weightOk {
log.Debugf("resourceComputeCreate: change loaderType or bootType or hotResize or networkInterfaceNaming or weight on ComputeID: %d", computeId)
updateReq.ComputeID = computeId
_, err := c.CloudBroker().Compute().Update(ctx, updateReq)
if err != nil {
@@ -381,7 +404,7 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
}
}
if mac == "" {
warnings.Add(errors.New(fmt.Sprintf("add libvirt virtio: Network with type %s and id %d is not connected to the compute %d", netType, netId, computeId)))
warnings.Add(fmt.Errorf("add libvirt virtio: Network with type %s and id %d is not connected to the compute %d", netType, netId, computeId))
continue
}
log.Debugf("resourceComputeCreate: Configure libvirt virtio interface parameters on Network with type %s and id %d", netType, netId)
@@ -420,7 +443,7 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
}
}
if mac == "" {
warnings.Add(errors.New(fmt.Sprintf("add security groups: Network with type %s and id %d is not connected to the compute %d", netType, netId, computeId)))
warnings.Add(fmt.Errorf("add security groups: Network with type %s and id %d is not connected to the compute %d", netType, netId, computeId))
continue
}
secGroupsIDs := make([]uint64, 0)
@@ -448,6 +471,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)
@@ -677,6 +703,9 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
if err != nil {
warnings.Add(err)
}
if err := utilityComputeCreateBlockSize(ctx, d, m); err != nil {
warnings.Add(err)
}
if err := utilityComputeCreateIOTune(ctx, d, m); err != nil {
warnings.Add(err)
}
@@ -874,7 +903,8 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
"boot_type",
"hot_resize",
"network_interface_naming",
"os_version") {
"os_version",
"weight") {
if err := utilityComputeUpdate(ctx, d, m); err != nil {
return diag.FromErr(err)
}

View File

@@ -232,6 +232,14 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeBool,
Computed: true,
},
"block_size": {
Type: schema.TypeString,
Computed: true,
},
"provision": {
Type: schema.TypeString,
Computed: true,
},
"boot_partition": {
Type: schema.TypeInt,
Computed: true,
@@ -287,6 +295,10 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
},
},
"independent": {
Type: schema.TypeBool,
Computed: true,
},
"iotune": {
Type: schema.TypeList,
Optional: true,
@@ -588,6 +600,10 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
},
},
"independent": {
Type: schema.TypeBool,
Computed: true,
},
"interfaces": {
Type: schema.TypeList,
Computed: true,
@@ -1150,6 +1166,10 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"weight": {
Type: schema.TypeInt,
Computed: true,
},
}
return res
}
@@ -1931,6 +1951,10 @@ func dataSourceComputeListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"weight": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
@@ -2221,6 +2245,10 @@ func dataSourceComputeListDeletedSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"sep_id": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
@@ -2639,6 +2667,10 @@ func dataSourceComputeListDeletedSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"weight": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
@@ -3409,6 +3441,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,
@@ -3463,16 +3501,6 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "ID of node to start compute",
},
"is": {
Type: schema.TypeString,
Optional: true,
Description: "system name",
},
"ipa_type": {
Type: schema.TypeString,
Optional: true,
Description: "compute purpose",
},
"custom_fields": {
Type: schema.TypeString,
Optional: true,
@@ -3521,8 +3549,8 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
Optional: true,
Computed: true,
//Default: 1500,
ValidateFunc: validation.IntBetween(1, 9216),
Description: "Maximum transmission unit, used only for DPDK type, must be 1-9216",
ValidateFunc: validation.IntBetween(1500, 9216),
Description: "Maximum transmission unit, used only for DPDK type, must be 1500-9216",
},
"sdn_interface_id": {
Type: schema.TypeString,
@@ -3531,22 +3559,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,
@@ -3609,7 +3637,7 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Required: true,
StateFunc: statefuncs.StateFuncToUpper,
ValidateFunc: validation.StringInSlice([]string{"VINS", "EXTNET", "VFNIC", "DPDK", "SDN", "TRUNK"}, false), // observe case while validating
ValidateFunc: validation.StringInSlice([]string{"VINS", "EXTNET", "DPDK"}, false), // observe case while validating
Description: "Type of the network",
},
"net_id": {
@@ -3750,18 +3778,31 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
Optional: true,
Default: false,
},
"block_size": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Disk block size",
},
"provision": {
Type: schema.TypeString,
Computed: true,
},
"sep_id": {
Type: schema.TypeInt,
Computed: true,
Optional: true,
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'",
"pci_slot": {
Type: schema.TypeInt,
Computed: true,
Description: "PCI slot number of the disk",
},
"bus_number": {
Type: schema.TypeInt,
Computed: true,
Description: "Bus number of the disk on virtual bus (6 = boot disk)",
},
"pool": {
Type: schema.TypeString,
@@ -3788,11 +3829,67 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
Optional: true,
Description: "Specify image id for create disk from template",
},
"independent": {
Type: schema.TypeBool,
Computed: true,
},
"permanently": {
Type: schema.TypeBool,
Optional: true,
Description: "Disk deletion status",
},
"disk_id": {
Type: schema.TypeInt,
Computed: true,
Description: "Disk ID",
},
"present_to": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"shareable": {
Type: schema.TypeBool,
Computed: true,
},
"size_max": {
Type: schema.TypeInt,
Computed: true,
},
"size_used": {
Type: schema.TypeInt,
Computed: true,
},
"to_clean": {
Type: schema.TypeBool,
Computed: true,
},
"devicename": {
Type: schema.TypeString,
Computed: true,
},
"create_by": {
Type: schema.TypeString,
Computed: true,
},
"create_time": {
Type: schema.TypeInt,
Computed: true,
},
"delete_by": {
Type: schema.TypeString,
Computed: true,
},
"delete_time": {
Type: schema.TypeInt,
Computed: true,
},
"update_time": {
Type: schema.TypeInt,
Computed: true,
},
"iotune": {
Type: schema.TypeList,
Optional: true,
@@ -3868,58 +3965,6 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
},
},
},
"disk_id": {
Type: schema.TypeInt,
Computed: true,
Description: "Disk ID",
},
"present_to": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"shareable": {
Type: schema.TypeBool,
Computed: true,
},
"size_max": {
Type: schema.TypeInt,
Computed: true,
},
"size_used": {
Type: schema.TypeInt,
Computed: true,
},
"to_clean": {
Type: schema.TypeBool,
Computed: true,
},
"devicename": {
Type: schema.TypeString,
Computed: true,
},
"create_by": {
Type: schema.TypeString,
Computed: true,
},
"create_time": {
Type: schema.TypeInt,
Computed: true,
},
"delete_by": {
Type: schema.TypeString,
Computed: true,
},
"delete_time": {
Type: schema.TypeInt,
Computed: true,
},
"update_time": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
@@ -4159,6 +4204,13 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "the OS version installed on the VM",
},
"weight": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ValidateFunc: validation.IntAtLeast(1),
Description: "Priority weight of the compute. Higher value means higher priority and later migration.",
},
// Computed properties
"account_id": {
Type: schema.TypeInt,

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
}
}
@@ -262,11 +266,14 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
changeStoragePolicyDisks := make([]interface{}, 0)
cacheUpdatedDisks := make([]interface{}, 0)
blkDiscardUpdatedDisks := make([]interface{}, 0)
blockSizeUpdatedDisks := make([]interface{}, 0)
iotuneUpdatedDisks := make([]interface{}, 0)
migratedDisks := make([]interface{}, 0)
presentNewDisks := make([]interface{}, 0)
presentOldDisks := make([]interface{}, 0)
chipset := d.Get("chipset").(string)
oldDisks, newDisks := d.GetChange("disks")
oldConv := oldDisks.([]interface{})
newConv := newDisks.([]interface{})
@@ -322,6 +329,10 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
blkDiscardUpdatedDisks = append(blkDiscardUpdatedDisks, el)
}
if isChangeBlockSizeDisk(oldConv, el) {
blockSizeUpdatedDisks = append(blockSizeUpdatedDisks, el)
}
if isChangeIOTuneDisk(oldConv, el) {
iotuneUpdatedDisks = append(iotuneUpdatedDisks, el)
}
@@ -330,7 +341,7 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
if len(deletedDisks) > 0 {
for _, disk := range deletedDisks {
diskConv := disk.(map[string]interface{})
if diskConv["disk_type"].(string) == "B" {
if isBootDisk(diskConv, chipset) {
continue
}
@@ -350,9 +361,6 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
if len(addedDisks) > 0 {
for _, disk := range addedDisks {
diskConv := disk.(map[string]interface{})
if diskConv["disk_type"].(string) == "B" {
continue
}
req := compute.DiskAddRequest{
ComputeID: computeId,
DiskName: diskConv["disk_name"].(string),
@@ -362,9 +370,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)
}
@@ -381,6 +386,16 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
if err != nil {
return err
}
if blockSize, ok := diskConv["block_size"].(string); ok && blockSize != "" {
updateReq := disks.UpdateRequest{
DiskID: diskID,
BlockSize: blockSize,
}
_, err := c.CloudBroker().Disks().Update(ctx, updateReq)
if err != nil {
return err
}
}
if nodeIDs, ok := diskConv["node_ids"]; ok {
presentIDs := nodeIDs.(*schema.Set).List()
if len(presentIDs) > 0 {
@@ -421,14 +436,16 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
return err
}
}
if err != nil {
return err
}
}
}
if len(resizedDisks) > 0 {
for _, disk := range resizedDisks {
diskConv := disk.(map[string]interface{})
if diskConv["disk_type"].(string) == "B" {
if isBootDisk(diskConv, chipset) {
continue
}
req := compute.DiskResizeRequest{
@@ -478,7 +495,7 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
if len(cacheUpdatedDisks) > 0 {
for _, disk := range cacheUpdatedDisks {
diskConv := disk.(map[string]interface{})
if diskConv["disk_type"].(string) == "B" {
if isBootDisk(diskConv, chipset) {
continue
}
@@ -501,7 +518,7 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
if len(blkDiscardUpdatedDisks) > 0 {
for _, disk := range blkDiscardUpdatedDisks {
diskConv := disk.(map[string]interface{})
if diskConv["disk_type"].(string) == "B" {
if isBootDisk(diskConv, chipset) {
continue
}
@@ -521,18 +538,43 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
}
}
if len(iotuneUpdatedDisks) > 0 {
for _, disk := range iotuneUpdatedDisks {
if len(blockSizeUpdatedDisks) > 0 {
for _, disk := range blockSizeUpdatedDisks {
diskConv := disk.(map[string]interface{})
if diskConv["disk_type"].(string) == "B" {
if isBootDisk(diskConv, chipset) {
continue
}
diskID := uint64(diskConv["disk_id"].(int))
if diskID == 0 {
continue
}
iotuneRaw, ok := diskConv["iotune"].([]interface{})
if !ok || len(iotuneRaw) == 0 {
req := disks.UpdateRequest{
DiskID: diskID,
BlockSize: diskConv["block_size"].(string),
}
_, err := c.CloudBroker().Disks().Update(ctx, req)
if err != nil {
return err
}
}
}
if len(iotuneUpdatedDisks) > 0 {
for _, disk := range iotuneUpdatedDisks {
diskConv := disk.(map[string]interface{})
if isBootDisk(diskConv, chipset) {
continue
}
diskID := uint64(diskConv["disk_id"].(int))
if diskID == 0 {
continue
}
iotuneRaw := diskConv["iotune"].([]interface{})
if len(iotuneRaw) == 0 {
continue
}
iotuneMap := iotuneRaw[0].(map[string]interface{})
@@ -778,10 +820,23 @@ func utilityComputePCIDevicesList(ctx context.Context, d *schema.ResourceData, m
return res, nil
}
func findBootDisk(disks compute.ListDisks) *compute.ItemDisk {
func isBootDisk(diskConv map[string]interface{}, chipset string) bool {
if chipset == "i440fx" {
return diskConv["pci_slot"].(int) == 6
}
return diskConv["bus_number"].(int) == 6
}
func findBootDisk(disks compute.ListDisks, chipset string) *compute.ItemDisk {
for _, disk := range disks {
if disk.Type == "B" {
return &disk
if chipset == "i440fx" {
if disk.PCISlot == 6 {
return &disk
}
} else {
if disk.BusNumber == 6 {
return &disk
}
}
}
return &compute.ItemDisk{}
@@ -981,7 +1036,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, computeId, altBootID, m); err != nil {
apiErrCount += numErr
lastSavedError = err
}
@@ -1264,6 +1325,10 @@ func utilityComputeUpdate(ctx context.Context, d *schema.ResourceData, m interfa
req.OSVersion = d.Get("os_version").(string)
}
if d.HasChange("weight") {
req.Weight = uint64(d.Get("weight").(int))
}
req.CPUPin = d.Get("cpu_pin").(bool)
req.HPBacked = d.Get("hp_backed").(bool)
req.AutoStart = d.Get("auto_start_w_node").(bool)
@@ -1308,7 +1373,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 +1848,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 +2108,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 {
@@ -2048,6 +2124,109 @@ func utilityComputeStart(ctx context.Context, computeID uint64, m interface{}) (
return 0, nil
}
func utilityComputeCreateBlockSize(ctx context.Context, d *schema.ResourceData, m interface{}) error {
c := m.(*controller.ControllerCfg)
diskList := d.Get("disks").([]interface{})
blockSizeArr := make([]string, 0, len(diskList))
hasAny := false
for _, elem := range diskList {
diskVal := elem.(map[string]interface{})
bs := diskVal["block_size"].(string)
blockSizeArr = append(blockSizeArr, bs)
if bs != "" {
hasAny = true
}
}
if !hasAny {
return nil
}
computeRec, err := utilityComputeCheckPresence(ctx, d, m)
if err != nil {
return err
}
bootDisk := findBootDisk(computeRec.Disks, computeRec.Chipset)
computeDisksIDs := getComputeDiskIDs(computeRec.Disks, diskList, d.Get("extra_disks").(*schema.Set).List(), bootDisk.ID)
for i, diskID := range computeDisksIDs {
if i >= len(blockSizeArr) || blockSizeArr[i] == "" {
continue
}
req := disks.UpdateRequest{
DiskID: diskID.(uint64),
BlockSize: blockSizeArr[i],
}
_, err := c.CloudBroker().Disks().Update(ctx, req)
if err != nil {
return err
}
}
return nil
}
func utilityComputeCreateIOTune(ctx context.Context, d *schema.ResourceData, m interface{}) error {
c := m.(*controller.ControllerCfg)
diskList := d.Get("disks").([]interface{})
iotuneArr := make([]interface{}, 0, len(diskList))
hasAny := false
for _, elem := range diskList {
diskVal := elem.(map[string]interface{})
iotune := diskVal["iotune"].([]interface{})
iotuneArr = append(iotuneArr, iotune)
if len(iotune) > 0 {
hasAny = true
}
}
if !hasAny {
return nil
}
computeRec, err := utilityComputeCheckPresence(ctx, d, m)
if err != nil {
return err
}
bootDisk := findBootDisk(computeRec.Disks, computeRec.Chipset)
computeDisksIDs := getComputeDiskIDs(computeRec.Disks, diskList, d.Get("extra_disks").(*schema.Set).List(), bootDisk.ID)
for i, diskID := range computeDisksIDs {
if i >= len(iotuneArr) {
continue
}
iotune, ok := iotuneArr[i].([]interface{})
if !ok || len(iotune) == 0 {
continue
}
iotuneMap := iotune[0].(map[string]interface{})
req := disks.LimitIORequest{
DiskID: diskID.(uint64),
ReadBytesSec: uint64(iotuneMap["read_bytes_sec"].(int)),
ReadBytesSecMax: uint64(iotuneMap["read_bytes_sec_max"].(int)),
ReadIOPSSec: uint64(iotuneMap["read_iops_sec"].(int)),
ReadIOPSSecMax: uint64(iotuneMap["read_iops_sec_max"].(int)),
SizeIOPSSec: uint64(iotuneMap["size_iops_sec"].(int)),
TotalBytesSec: uint64(iotuneMap["total_bytes_sec"].(int)),
TotalBytesSecMax: uint64(iotuneMap["total_bytes_sec_max"].(int)),
TotalIOPSSec: uint64(iotuneMap["total_iops_sec"].(int)),
TotalIOPSSecMax: uint64(iotuneMap["total_iops_sec_max"].(int)),
WriteBytesSec: uint64(iotuneMap["write_bytes_sec"].(int)),
WriteBytesSecMax: uint64(iotuneMap["write_bytes_sec_max"].(int)),
WriteIOPSSec: uint64(iotuneMap["write_iops_sec"].(int)),
WriteIOPSSecMax: uint64(iotuneMap["write_iops_sec_max"].(int)),
}
_, err := c.CloudBroker().Disks().LimitIO(ctx, req)
if err != nil {
return err
}
}
return nil
}
func utilityComputeCreatePresentDisk(ctx context.Context, d *schema.ResourceData, m interface{}) error {
c := m.(*controller.ControllerCfg)
var errs error
@@ -2059,7 +2238,7 @@ func utilityComputeCreatePresentDisk(ctx context.Context, d *schema.ResourceData
}
computeRec, err := utilityComputeCheckPresence(ctx, d, m)
bootDisk := findBootDisk(computeRec.Disks)
bootDisk := findBootDisk(computeRec.Disks, computeRec.Chipset)
if err != nil {
errs = errors.Join(err)
}
@@ -2141,6 +2320,18 @@ func isChangeBLKDiscardDisk(els []interface{}, el interface{}) bool {
return false
}
func isChangeBlockSizeDisk(els []interface{}, el interface{}) bool {
for _, elOld := range els {
elOldConv := elOld.(map[string]interface{})
elConv := el.(map[string]interface{})
if elOldConv["disk_id"].(int) == elConv["disk_id"].(int) &&
elOldConv["block_size"].(string) != elConv["block_size"].(string) {
return true
}
}
return false
}
func isChangeIOTuneDisk(els []interface{}, el interface{}) bool {
for _, elOld := range els {
elOldConv := elOld.(map[string]interface{})
@@ -2175,66 +2366,6 @@ func isChangeIOTuneDisk(els []interface{}, el interface{}) bool {
return false
}
func utilityComputeCreateIOTune(ctx context.Context, d *schema.ResourceData, m interface{}) error {
c := m.(*controller.ControllerCfg)
diskList := d.Get("disks").([]interface{})
iotuneArr := make([]interface{}, 0, len(diskList))
hasAny := false
for _, elem := range diskList {
diskVal := elem.(map[string]interface{})
iotune := diskVal["iotune"].([]interface{})
iotuneArr = append(iotuneArr, iotune)
if len(iotune) > 0 {
hasAny = true
}
}
if !hasAny {
return nil
}
computeRec, err := utilityComputeCheckPresence(ctx, d, m)
if err != nil {
return err
}
bootDisk := findBootDisk(computeRec.Disks)
computeDisksIDs := getComputeDiskIDs(computeRec.Disks, diskList, d.Get("extra_disks").(*schema.Set).List(), bootDisk.ID)
for i, diskID := range computeDisksIDs {
if i >= len(iotuneArr) {
continue
}
iotune, ok := iotuneArr[i].([]interface{})
if !ok || len(iotune) == 0 {
continue
}
iotuneMap := iotune[0].(map[string]interface{})
req := disks.LimitIORequest{
DiskID: diskID.(uint64),
ReadBytesSec: uint64(iotuneMap["read_bytes_sec"].(int)),
ReadBytesSecMax: uint64(iotuneMap["read_bytes_sec_max"].(int)),
ReadIOPSSec: uint64(iotuneMap["read_iops_sec"].(int)),
ReadIOPSSecMax: uint64(iotuneMap["read_iops_sec_max"].(int)),
SizeIOPSSec: uint64(iotuneMap["size_iops_sec"].(int)),
TotalBytesSec: uint64(iotuneMap["total_bytes_sec"].(int)),
TotalBytesSecMax: uint64(iotuneMap["total_bytes_sec_max"].(int)),
TotalIOPSSec: uint64(iotuneMap["total_iops_sec"].(int)),
TotalIOPSSecMax: uint64(iotuneMap["total_iops_sec_max"].(int)),
WriteBytesSec: uint64(iotuneMap["write_bytes_sec"].(int)),
WriteBytesSecMax: uint64(iotuneMap["write_bytes_sec_max"].(int)),
WriteIOPSSec: uint64(iotuneMap["write_iops_sec"].(int)),
WriteIOPSSecMax: uint64(iotuneMap["write_iops_sec_max"].(int)),
}
_, err := c.CloudBroker().Disks().LimitIO(ctx, req)
if err != nil {
return err
}
}
return nil
}
func isChangeStoragePolicy(els []interface{}, el interface{}) bool {
for _, elOld := range els {
elOldConv := elOld.(map[string]interface{})