1.10.5
This commit is contained in:
@@ -333,6 +333,7 @@ func flattenComputeDisksDemo(disksList compute.ListComputeDisks, disksBlocks, ex
|
||||
"deleted_time": disk.DeletedTime,
|
||||
"updated_time": disk.UpdatedTime,
|
||||
"permanently": pernamentlyValue,
|
||||
"iotune": flattenIotune(disk.IOTune),
|
||||
}
|
||||
res = append(res, temp)
|
||||
indexDataDisks++
|
||||
|
||||
@@ -384,6 +384,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)
|
||||
}
|
||||
}
|
||||
|
||||
if !cleanup {
|
||||
|
||||
if enabled, ok := d.GetOk("enabled"); ok {
|
||||
@@ -1118,6 +1124,7 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
resizedDisks := make([]interface{}, 0)
|
||||
renamedDisks := make([]interface{}, 0)
|
||||
changeStoragePolicyDisks := make([]interface{}, 0)
|
||||
iotuneUpdatedDisks := make([]interface{}, 0)
|
||||
|
||||
oldDisks, newDisks := d.GetChange("disks")
|
||||
oldConv := oldDisks.([]interface{})
|
||||
@@ -1158,6 +1165,9 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
if isChangeStoragePolicy(oldConv, el) {
|
||||
changeStoragePolicyDisks = append(changeStoragePolicyDisks, el)
|
||||
}
|
||||
if isChangeIOTuneDisk(oldConv, el) {
|
||||
iotuneUpdatedDisks = append(iotuneUpdatedDisks, el)
|
||||
}
|
||||
}
|
||||
|
||||
if len(deletedDisks) > 0 {
|
||||
@@ -1210,10 +1220,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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1267,6 +1300,59 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(iotuneUpdatedDisks) > 0 {
|
||||
computeRec, err := utilityComputeCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
allDisks := computeRec.Disks
|
||||
bootDisk := findBootDisk(allDisks)
|
||||
diskIDs := getComputeDiskIDs(d, allDisks)
|
||||
for i, disk := range iotuneUpdatedDisks {
|
||||
diskConv := disk.(map[string]interface{})
|
||||
if diskConv["disk_type"].(string) == "B" {
|
||||
continue
|
||||
}
|
||||
if bootDisk != nil && diskConv["disk_id"].(int) == int(bootDisk.ID) {
|
||||
continue
|
||||
}
|
||||
var diskID uint64
|
||||
if id := diskConv["disk_id"].(int); id != 0 {
|
||||
diskID = uint64(id)
|
||||
} else if i < len(diskIDs) {
|
||||
diskID = diskIDs[i]
|
||||
}
|
||||
if diskID == 0 {
|
||||
continue
|
||||
}
|
||||
iotuneRaw, ok := diskConv["iotune"].([]interface{})
|
||||
if !ok || len(iotuneRaw) == 0 {
|
||||
continue
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("affinity_label") {
|
||||
@@ -1866,6 +1952,40 @@ func isContainsDisk(els []interface{}, el interface{}) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
func isContainsAR(els []interface{}, el interface{}) bool {
|
||||
for _, elOld := range els {
|
||||
elOldConv := elOld.(map[string]interface{})
|
||||
@@ -1960,6 +2080,81 @@ func disksSubresourceSchemaMake() map[string]*schema.Schema {
|
||||
Optional: true,
|
||||
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,
|
||||
|
||||
@@ -43,6 +43,7 @@ import (
|
||||
"github.com/hashicorp/go-cty/cty"
|
||||
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"
|
||||
@@ -622,3 +623,94 @@ func enabledNetwork(rawNetworkConfig cty.Value, netID uint64, netType string) bo
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func getComputeDiskIDs(d *schema.ResourceData, disksList compute.ListComputeDisks) []uint64 {
|
||||
diskList := d.Get("disks").([]interface{})
|
||||
ids := make([]uint64, 0, len(diskList))
|
||||
for _, item := range diskList {
|
||||
diskConv := item.(map[string]interface{})
|
||||
diskName := diskConv["disk_name"].(string)
|
||||
for _, disk := range disksList {
|
||||
if disk.Name == diskName {
|
||||
ids = append(ids, disk.ID)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
func utilityComputeCreateIOTune(ctx context.Context, d *schema.ResourceData, m interface{}) error {
|
||||
diskList, ok := d.GetOk("disks")
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
disksSlice := diskList.([]interface{})
|
||||
|
||||
hasIotune := false
|
||||
for _, item := range disksSlice {
|
||||
diskConv := item.(map[string]interface{})
|
||||
if iotuneRaw, ok := diskConv["iotune"].([]interface{}); ok && len(iotuneRaw) > 0 {
|
||||
hasIotune = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !hasIotune {
|
||||
return nil
|
||||
}
|
||||
|
||||
computeRec, err := utilityComputeCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
allDisks := computeRec.Disks
|
||||
bootDisk := findBootDisk(allDisks)
|
||||
diskIDs := getComputeDiskIDs(d, allDisks)
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
for i, item := range disksSlice {
|
||||
diskConv := item.(map[string]interface{})
|
||||
if diskConv["disk_type"].(string) == "B" {
|
||||
continue
|
||||
}
|
||||
if bootDisk != nil && diskConv["disk_id"].(int) == int(bootDisk.ID) {
|
||||
continue
|
||||
}
|
||||
iotuneRaw, ok := diskConv["iotune"].([]interface{})
|
||||
if !ok || len(iotuneRaw) == 0 {
|
||||
continue
|
||||
}
|
||||
var diskID uint64
|
||||
if id := diskConv["disk_id"].(int); id != 0 {
|
||||
diskID = uint64(id)
|
||||
} else if i < len(diskIDs) {
|
||||
diskID = diskIDs[i]
|
||||
}
|
||||
if diskID == 0 {
|
||||
continue
|
||||
}
|
||||
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 err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user