4.6.0
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
package kvmvm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strconv"
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens"
|
||||
)
|
||||
|
||||
func flattenCompute(ctx context.Context, d *schema.ResourceData, computeRec *compute.RecordCompute) error {
|
||||
func flattenCompute(d *schema.ResourceData, computeRec *compute.RecordCompute) error {
|
||||
log.Debugf("flattenCompute: ID %d, RG ID %d", computeRec.ID, computeRec.RGID)
|
||||
|
||||
customFields, _ := json.Marshal(computeRec.CustomFields)
|
||||
@@ -49,7 +49,7 @@ func flattenCompute(ctx context.Context, d *schema.ResourceData, computeRec *com
|
||||
d.Set("deleted_time", computeRec.DeletedTime)
|
||||
d.Set("description", computeRec.Description)
|
||||
d.Set("devices", string(devices))
|
||||
err := d.Set("disks", flattenComputeDisks(ctx, d, computeRec.Disks, d.Get("extra_disks").(*schema.Set).List(), bootDisk.ID))
|
||||
err := d.Set("disks", flattenComputeDisks(computeRec.Disks, d.Get("disks").([]interface{}), d.Get("extra_disks").(*schema.Set).List(), bootDisk.ID))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -58,18 +58,26 @@ func flattenCompute(ctx context.Context, d *schema.ResourceData, computeRec *com
|
||||
d.Set("guid", computeRec.GUID)
|
||||
d.Set("compute_id", computeRec.ID)
|
||||
d.Set("image_id", computeRec.ImageID)
|
||||
d.Set("image_name", computeRec.ImageName)
|
||||
d.Set("interfaces", flattenInterfaces(computeRec.Interfaces))
|
||||
d.Set("lock_status", computeRec.LockStatus)
|
||||
d.Set("manager_id", computeRec.ManagerID)
|
||||
d.Set("manager_type", computeRec.ManagerType)
|
||||
d.Set("migrationjob", computeRec.MigrationJob)
|
||||
d.Set("milestones", computeRec.Milestones)
|
||||
d.Set("natable_vins_id", computeRec.NatableVINSID)
|
||||
d.Set("natable_vins_ip", computeRec.NatableVINSIP)
|
||||
d.Set("natable_vins_name", computeRec.NatableVINSName)
|
||||
d.Set("natable_vins_network", computeRec.NatableVINSNetwork)
|
||||
d.Set("natable_vins_network_name", computeRec.NatableVINSNetworkName)
|
||||
d.Set("need_reboot", computeRec.NeedReboot)
|
||||
d.Set("numa_node_id", computeRec.NumaNodeId)
|
||||
d.Set("os_users", flattenOSUsers(computeRec.OSUsers))
|
||||
d.Set("pinned", computeRec.Pinned)
|
||||
d.Set("reference_id", computeRec.ReferenceID)
|
||||
d.Set("registered", computeRec.Registered)
|
||||
d.Set("res_name", computeRec.ResName)
|
||||
d.Set("reserved_node_cpus", computeRec.ReservedNodeCpus)
|
||||
d.Set("rg_name", computeRec.RGName)
|
||||
d.Set("snap_sets", flattenSnapSets(computeRec.SnapSets))
|
||||
d.Set("stack_id", computeRec.StackID)
|
||||
@@ -85,7 +93,7 @@ func flattenCompute(ctx context.Context, d *schema.ResourceData, computeRec *com
|
||||
d.Set("user_managed", computeRec.UserManaged)
|
||||
d.Set("vgpus", computeRec.VGPUs)
|
||||
d.Set("virtual_image_id", computeRec.VirtualImageID)
|
||||
|
||||
d.Set("virtual_image_name", computeRec.VirtualImageName)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -140,6 +148,7 @@ func flattenInterfaces(ifaces compute.ListInterfaces) []map[string]interface{} {
|
||||
"conn_id": iface.ConnID,
|
||||
"conn_type": iface.ConnType,
|
||||
"def_gw": iface.DefGW,
|
||||
"enabled": iface.Enabled,
|
||||
"flip_group_id": iface.FLIPGroupID,
|
||||
"guid": iface.GUID,
|
||||
"ip_address": iface.IPAddress,
|
||||
@@ -149,6 +158,7 @@ func flattenInterfaces(ifaces compute.ListInterfaces) []map[string]interface{} {
|
||||
"net_id": iface.NetID,
|
||||
"netmask": iface.NetMask,
|
||||
"net_type": iface.NetType,
|
||||
"node_id": iface.NodeID,
|
||||
"pci_slot": iface.PCISlot,
|
||||
"qos": flattenQOS(iface.QOS),
|
||||
"target": iface.Target,
|
||||
@@ -171,20 +181,30 @@ func flattenQOS(qos compute.QOS) []map[string]interface{} {
|
||||
}
|
||||
}
|
||||
|
||||
func flattenComputeDisks(ctx context.Context, d *schema.ResourceData, disksList compute.ListDisks, extraDisks []interface{}, bootDiskId uint64) []map[string]interface{} {
|
||||
func flattenComputeDisks(disksList compute.ListDisks, disksBlocks, extraDisks []interface{}, bootDiskId uint64) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(disksList))
|
||||
|
||||
if len(disksBlocks) == 0 {
|
||||
return res
|
||||
}
|
||||
|
||||
sort.Slice(disksList, func(i, j int) bool {
|
||||
return disksList[i].ID < disksList[j].ID
|
||||
})
|
||||
|
||||
indexDataDisks := 0
|
||||
|
||||
for _, disk := range disksList {
|
||||
if disk.ID == bootDiskId || findInExtraDisks(uint(disk.ID), extraDisks) { //skip main bootdisk and extraDisks
|
||||
continue
|
||||
}
|
||||
|
||||
permanently, ok := ctx.Value(DiskKey(strconv.Itoa(int(disk.ID)))).(bool) // get permamently from Create or Update context
|
||||
if !ok {
|
||||
permanently = getPermanentlyByDiskID(d, disk.ID) // get permanently from state when Read is not after Create/Update
|
||||
}
|
||||
pernamentlyValue := disksBlocks[indexDataDisks].(map[string]interface{})["permanently"].(bool)
|
||||
nodeIds := disksBlocks[indexDataDisks].(map[string]interface{})["node_ids"].(*schema.Set)
|
||||
|
||||
temp := map[string]interface{}{
|
||||
"disk_name": disk.Name,
|
||||
"node_ids": nodeIds,
|
||||
"size": disk.SizeMax,
|
||||
"sep_id": disk.SEPID,
|
||||
"disk_type": disk.Type,
|
||||
@@ -195,31 +215,15 @@ func flattenComputeDisks(ctx context.Context, d *schema.ResourceData, disksList
|
||||
"shareable": disk.Shareable,
|
||||
"size_used": disk.SizeUsed,
|
||||
"size_max": disk.SizeMax,
|
||||
"permanently": permanently,
|
||||
"permanently": pernamentlyValue,
|
||||
}
|
||||
res = append(res, temp)
|
||||
indexDataDisks++
|
||||
}
|
||||
sort.Slice(res, func(i, j int) bool {
|
||||
return res[i]["disk_id"].(uint64) < res[j]["disk_id"].(uint64)
|
||||
})
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
// getPermanentlyByDiskID gets permanently value of specific disk (by diskId) from disks current state
|
||||
func getPermanentlyByDiskID(d *schema.ResourceData, diskId uint64) bool {
|
||||
disks := d.Get("disks").([]interface{})
|
||||
|
||||
for _, diskItem := range disks {
|
||||
disk := diskItem.(map[string]interface{})
|
||||
if uint64(disk["disk_id"].(int)) == diskId {
|
||||
return disk["permanently"].(bool)
|
||||
}
|
||||
}
|
||||
|
||||
log.Infof("getPermanentlyByDiskID: disk with id %d not found in state", diskId)
|
||||
return false
|
||||
}
|
||||
|
||||
func findInExtraDisks(diskId uint, extraDisks []interface{}) bool {
|
||||
for _, ExtraDisk := range extraDisks {
|
||||
if diskId == uint(ExtraDisk.(int)) {
|
||||
@@ -262,7 +266,7 @@ func flattenComputeList(computes *compute.ListComputes) []map[string]interface{}
|
||||
"arch": computeItem.Arch,
|
||||
"cd_image_id": computeItem.CdImageId,
|
||||
"boot_order": computeItem.BootOrder,
|
||||
"boot_disk_size": computeItem.BootDiskSize,
|
||||
"bootdisk_size": computeItem.BootDiskSize,
|
||||
"clone_reference": computeItem.CloneReference,
|
||||
"clones": computeItem.Clones,
|
||||
"computeci_id": computeItem.ComputeCIID,
|
||||
@@ -278,7 +282,9 @@ func flattenComputeList(computes *compute.ListComputes) []map[string]interface{}
|
||||
"driver": computeItem.Driver,
|
||||
"gid": computeItem.GID,
|
||||
"guid": computeItem.GUID,
|
||||
"hp_backed": computeItem.HPBacked,
|
||||
"compute_id": computeItem.ID,
|
||||
"cpu_pin": computeItem.CPUPin,
|
||||
"image_id": computeItem.ImageID,
|
||||
"interfaces": flattenInterfaces(computeItem.Interfaces),
|
||||
"lock_status": computeItem.LockStatus,
|
||||
@@ -288,12 +294,15 @@ func flattenComputeList(computes *compute.ListComputes) []map[string]interface{}
|
||||
"milestones": computeItem.Milestones,
|
||||
"name": computeItem.Name,
|
||||
"need_reboot": computeItem.NeedReboot,
|
||||
"numa_affinity": computeItem.NumaAffinity,
|
||||
"numa_node_id": computeItem.NumaNodeId,
|
||||
"os_users": flattenOSUsers(computeItem.OSUsers),
|
||||
"pinned": computeItem.Pinned,
|
||||
"ram": computeItem.RAM,
|
||||
"reference_id": computeItem.ReferenceID,
|
||||
"registered": computeItem.Registered,
|
||||
"res_name": computeItem.ResName,
|
||||
"reserved_node_cpus": computeItem.ReservedNodeCpus,
|
||||
"rg_id": computeItem.RGID,
|
||||
"rg_name": computeItem.RGName,
|
||||
"snap_sets": flattenSnapSets(computeItem.SnapSets),
|
||||
@@ -503,23 +512,32 @@ func flattenPCIDevice(deviceList []compute.ItemPCIDevice) []map[string]interface
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenVGPU(m []interface{}) []string {
|
||||
var output []string
|
||||
for _, item := range m {
|
||||
switch d := item.(type) {
|
||||
case string:
|
||||
output = append(output, d)
|
||||
case int:
|
||||
output = append(output, strconv.Itoa(d))
|
||||
case int64:
|
||||
output = append(output, strconv.FormatInt(d, 10))
|
||||
case float64:
|
||||
output = append(output, strconv.FormatInt(int64(d), 10))
|
||||
default:
|
||||
output = append(output, "")
|
||||
func flattenVGPU(vgpuList []compute.ItemVGPU) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(vgpuList))
|
||||
for _, dev := range vgpuList {
|
||||
temp := map[string]interface{}{
|
||||
"account_id": dev.AccountID,
|
||||
"created_time": dev.CreatedTime,
|
||||
"deleted_time": dev.DeletedTime,
|
||||
"gid": dev.GID,
|
||||
"guid": dev.GUID,
|
||||
"vgpu_id": dev.ID,
|
||||
"last_claimed_by": dev.LastClaimedBy,
|
||||
"last_update_time": dev.LastUpdateTime,
|
||||
"mode": dev.Mode,
|
||||
"pci_slot": dev.PCISlot,
|
||||
"pgpuid": dev.PGPUID,
|
||||
"profile_id": dev.ProfileID,
|
||||
"ram": dev.RAM,
|
||||
"reference_id": dev.ReferenceID,
|
||||
"rg_id": dev.RGID,
|
||||
"status": dev.Status,
|
||||
"type": dev.Type,
|
||||
"vm_id": dev.VMID,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return output
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenNodes(m []interface{}) []string {
|
||||
@@ -553,6 +571,8 @@ func flattenDataCompute(d *schema.ResourceData, compFacts *compute.RecordCompute
|
||||
customFields, _ := json.Marshal(compFacts.CustomFields)
|
||||
devices, _ := json.Marshal(compFacts.Devices)
|
||||
userData, _ := json.Marshal(compFacts.Userdata)
|
||||
// general fields setting
|
||||
d.SetId(fmt.Sprintf("%d", compFacts.ID))
|
||||
d.Set("account_id", compFacts.AccountID)
|
||||
d.Set("account_name", compFacts.AccountName)
|
||||
d.Set("acl", flattenListACLInterface(compFacts.ACL))
|
||||
@@ -562,11 +582,11 @@ func flattenDataCompute(d *schema.ResourceData, compFacts *compute.RecordCompute
|
||||
d.Set("anti_affinity_rules", flattenAffinityRules(compFacts.AntiAffinityRules))
|
||||
d.Set("arch", compFacts.Arch)
|
||||
d.Set("boot_order", compFacts.BootOrder)
|
||||
d.Set("boot_disk_size", compFacts.BootDiskSize)
|
||||
d.Set("cd_image_id", compFacts.CdImageId)
|
||||
d.Set("clone_reference", compFacts.CloneReference)
|
||||
d.Set("clones", compFacts.Clones)
|
||||
d.Set("computeci_id", compFacts.ComputeCIID)
|
||||
d.Set("cpu_pin", compFacts.CPUPin)
|
||||
d.Set("cpus", compFacts.CPUs)
|
||||
d.Set("created_by", compFacts.CreatedBy)
|
||||
d.Set("created_time", compFacts.CreatedTime)
|
||||
@@ -579,7 +599,9 @@ func flattenDataCompute(d *schema.ResourceData, compFacts *compute.RecordCompute
|
||||
d.Set("driver", compFacts.Driver)
|
||||
d.Set("gid", compFacts.GID)
|
||||
d.Set("guid", compFacts.GUID)
|
||||
d.Set("hp_backed", compFacts.HPBacked)
|
||||
d.Set("image_id", compFacts.ImageID)
|
||||
d.Set("image_name", compFacts.ImageName)
|
||||
d.Set("interfaces", flattenInterfaces(compFacts.Interfaces))
|
||||
d.Set("lock_status", compFacts.LockStatus)
|
||||
d.Set("manager_id", compFacts.ManagerID)
|
||||
@@ -587,13 +609,21 @@ func flattenDataCompute(d *schema.ResourceData, compFacts *compute.RecordCompute
|
||||
d.Set("migrationjob", compFacts.MigrationJob)
|
||||
d.Set("milestones", compFacts.Milestones)
|
||||
d.Set("name", compFacts.Name)
|
||||
d.Set("natable_vins_id", compFacts.NatableVINSID)
|
||||
d.Set("natable_vins_ip", compFacts.NatableVINSIP)
|
||||
d.Set("natable_vins_name", compFacts.NatableVINSName)
|
||||
d.Set("natable_vins_network", compFacts.NatableVINSNetwork)
|
||||
d.Set("natable_vins_network_name", compFacts.NatableVINSNetworkName)
|
||||
d.Set("need_reboot", compFacts.NeedReboot)
|
||||
d.Set("numa_affinity", compFacts.NumaAffinity)
|
||||
d.Set("numa_node_id", compFacts.NumaNodeId)
|
||||
d.Set("os_users", flattenOSUsers(compFacts.OSUsers))
|
||||
d.Set("pinned", compFacts.Pinned)
|
||||
d.Set("ram", compFacts.RAM)
|
||||
d.Set("reference_id", compFacts.ReferenceID)
|
||||
d.Set("registered", compFacts.Registered)
|
||||
d.Set("res_name", compFacts.ResName)
|
||||
d.Set("reserved_node_cpus", compFacts.ReservedNodeCpus)
|
||||
d.Set("rg_id", compFacts.RGID)
|
||||
d.Set("rg_name", compFacts.RGName)
|
||||
d.Set("snap_sets", flattenSnapSets(compFacts.SnapSets))
|
||||
@@ -610,6 +640,15 @@ func flattenDataCompute(d *schema.ResourceData, compFacts *compute.RecordCompute
|
||||
d.Set("user_managed", compFacts.UserManaged)
|
||||
d.Set("vgpus", compFacts.VGPUs)
|
||||
d.Set("virtual_image_id", compFacts.VirtualImageID)
|
||||
d.Set("virtual_image_name", compFacts.VirtualImageName)
|
||||
//extra fields setting
|
||||
bootDisk := findBootDisk(compFacts.Disks)
|
||||
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
|
||||
d.Set("sep_id", bootDisk.SEPID)
|
||||
d.Set("pool", bootDisk.Pool)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -669,6 +708,7 @@ func flattenDisk(diskList compute.ListDisks) []map[string]interface{} {
|
||||
"purge_attempts": disk.PurgeAttempts,
|
||||
"present_to": disk.PresentTo,
|
||||
"purge_time": disk.PurgeTime,
|
||||
"replication": flattenDiskReplication(disk.Replication),
|
||||
"reality_device_number": disk.RealityDeviceNumber,
|
||||
"reference_id": disk.ReferenceID,
|
||||
"res_id": disk.ResID,
|
||||
@@ -689,6 +729,20 @@ func flattenDisk(diskList compute.ListDisks) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenDiskReplication(rep compute.ItemReplication) []map[string]interface{} {
|
||||
res := []map[string]interface{}{
|
||||
{
|
||||
"disk_id": rep.DiskID,
|
||||
"pool_id": rep.PoolID,
|
||||
"role": rep.Role,
|
||||
"self_volume_id": rep.SelfVolumeID,
|
||||
"storage_id": rep.StorageID,
|
||||
"volume_id": rep.VolumeID,
|
||||
},
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenIOTune(iot compute.IOTune) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
|
||||
Reference in New Issue
Block a user