4.9.10
This commit is contained in:
@@ -307,6 +307,7 @@ func flattenComputeDisksDemo(disksList compute.ListComputeDisks, disksBlocks, ex
|
||||
"size": disk.SizeMax,
|
||||
"permanently": permanentlyValue,
|
||||
"present_to": disk.PresentTo,
|
||||
"iotune": flattenIotune(disk.IOTune),
|
||||
}
|
||||
res = append(res, temp)
|
||||
indexDataDisks++
|
||||
|
||||
@@ -587,6 +587,12 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
}
|
||||
}
|
||||
|
||||
if _, ok := d.GetOk("disks"); ok {
|
||||
if err := utilityComputeCreateIOTune(ctx, d, m); err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
log.Debugf("resourceComputeCreate: new Compute ID %d, name %s creation sequence complete", computeId, d.Get("name").(string))
|
||||
|
||||
@@ -1063,6 +1069,7 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
addedDisks := make([]interface{}, 0)
|
||||
resizedDisks := make([]interface{}, 0)
|
||||
renamedDisks := make([]interface{}, 0)
|
||||
iotuneUpdatedDisks := make([]interface{}, 0)
|
||||
|
||||
oldDisks, newDisks := d.GetChange("disks")
|
||||
oldConv := oldDisks.([]interface{})
|
||||
@@ -1100,6 +1107,9 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
if isRenameDisk(oldConv, el) {
|
||||
renamedDisks = append(renamedDisks, el)
|
||||
}
|
||||
if isChangeIOTuneDisk(oldConv, el) {
|
||||
iotuneUpdatedDisks = append(iotuneUpdatedDisks, el)
|
||||
}
|
||||
}
|
||||
|
||||
if len(deletedDisks) > 0 {
|
||||
@@ -1153,10 +1163,33 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
if diskConv["image_id"].(int) != 0 {
|
||||
req.ImageID = uint64(diskConv["image_id"].(int))
|
||||
}
|
||||
_, err := c.CloudAPI().Compute().DiskAdd(ctx, req)
|
||||
diskID, err := c.CloudAPI().Compute().DiskAdd(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
if iotuneRaw, ok := diskConv["iotune"].([]interface{}); ok && len(iotuneRaw) > 0 {
|
||||
iotuneMap := iotuneRaw[0].(map[string]interface{})
|
||||
limitReq := disks.LimitIORequest{
|
||||
DiskID: diskID,
|
||||
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.CloudAPI().Disks().LimitIO(ctx, limitReq)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1194,6 +1227,46 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(iotuneUpdatedDisks) > 0 {
|
||||
for _, disk := range iotuneUpdatedDisks {
|
||||
diskConv := disk.(map[string]interface{})
|
||||
if diskConv["disk_type"].(string) == "B" {
|
||||
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{})
|
||||
req := disks.LimitIORequest{
|
||||
DiskID: diskID,
|
||||
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.CloudAPI().Disks().LimitIO(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("affinity_label") {
|
||||
@@ -1818,6 +1891,81 @@ func disksSubresourceSchemaMake() map[string]*schema.Schema {
|
||||
Default: false,
|
||||
Description: "Disk deletion status",
|
||||
},
|
||||
"iotune": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
MaxItems: 1,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"read_bytes_sec": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"read_bytes_sec_max": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"read_iops_sec": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"read_iops_sec_max": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"size_iops_sec": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"total_bytes_sec": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"total_bytes_sec_max": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"total_iops_sec": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"total_iops_sec_max": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"write_bytes_sec": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"write_bytes_sec_max": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"write_iops_sec": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"write_iops_sec_max": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"disk_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
|
||||
@@ -40,6 +40,7 @@ import (
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/compute"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/disks"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
@@ -433,3 +434,118 @@ func differenceNetwork(oldList, newList []interface{}) (detachMap, changeIpMap,
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
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.CloudAPI().Disks().LimitIO(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func getComputeDiskIDs(disksList compute.ListComputeDisks, disksBlocks, extraDisks []interface{}, bootDiskId uint64) []interface{} {
|
||||
res := make([]interface{}, 0)
|
||||
|
||||
if len(disksBlocks) == 0 {
|
||||
return res
|
||||
}
|
||||
|
||||
sort.Slice(disksList, func(i, j int) bool {
|
||||
return disksList[i].ID < disksList[j].ID
|
||||
})
|
||||
|
||||
for _, disk := range disksList {
|
||||
if disk.ID == bootDiskId || findInExtraDisks(uint(disk.ID), extraDisks) { //skip main bootdisk and extraDisks
|
||||
continue
|
||||
}
|
||||
|
||||
res = append(res, disk.ID)
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
func isChangeIOTuneDisk(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) {
|
||||
continue
|
||||
}
|
||||
oldIOTune := elOldConv["iotune"].([]interface{})
|
||||
newIOTune := elConv["iotune"].([]interface{})
|
||||
if len(oldIOTune) == 0 && len(newIOTune) == 0 {
|
||||
return false
|
||||
}
|
||||
if len(oldIOTune) == 0 || len(newIOTune) == 0 {
|
||||
return true
|
||||
}
|
||||
oldMap := oldIOTune[0].(map[string]interface{})
|
||||
newMap := newIOTune[0].(map[string]interface{})
|
||||
return oldMap["read_bytes_sec"].(int) != newMap["read_bytes_sec"].(int) ||
|
||||
oldMap["read_bytes_sec_max"].(int) != newMap["read_bytes_sec_max"].(int) ||
|
||||
oldMap["read_iops_sec"].(int) != newMap["read_iops_sec"].(int) ||
|
||||
oldMap["read_iops_sec_max"].(int) != newMap["read_iops_sec_max"].(int) ||
|
||||
oldMap["size_iops_sec"].(int) != newMap["size_iops_sec"].(int) ||
|
||||
oldMap["total_bytes_sec"].(int) != newMap["total_bytes_sec"].(int) ||
|
||||
oldMap["total_bytes_sec_max"].(int) != newMap["total_bytes_sec_max"].(int) ||
|
||||
oldMap["total_iops_sec"].(int) != newMap["total_iops_sec"].(int) ||
|
||||
oldMap["total_iops_sec_max"].(int) != newMap["total_iops_sec_max"].(int) ||
|
||||
oldMap["write_bytes_sec"].(int) != newMap["write_bytes_sec"].(int) ||
|
||||
oldMap["write_bytes_sec_max"].(int) != newMap["write_bytes_sec_max"].(int) ||
|
||||
oldMap["write_iops_sec"].(int) != newMap["write_iops_sec"].(int) ||
|
||||
oldMap["write_iops_sec_max"].(int) != newMap["write_iops_sec_max"].(int)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user