This commit is contained in:
2025-11-18 16:20:26 +03:00
parent 4b3f21d9be
commit e42fbcef39
397 changed files with 17560 additions and 1501 deletions

View File

@@ -50,6 +50,7 @@ func dataSourceComputeAuditsRead(ctx context.Context, d *schema.ResourceData, m
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenComputeAudits(computeAudits))
d.Set("entry_count", computeAudits.EntryCount)
return nil
}

View File

@@ -39,6 +39,7 @@ func flattenCompute(d *schema.ResourceData, computeRec *compute.RecordCompute, p
d.Set("boot_disk_id", bootDisk.ID)
// we intentionally use the SizeMax field, do not change it until the BootDiskSize field is fixed on the platform
d.Set("boot_disk_size", bootDisk.SizeMax)
d.Set("boot_image_id", bootDisk.ImageID)
d.Set("chipset", computeRec.Chipset)
d.Set("cd_image_id", computeRec.CdImageId)
d.Set("clone_reference", computeRec.CloneReference)
@@ -96,14 +97,16 @@ func flattenCompute(d *schema.ResourceData, computeRec *compute.RecordCompute, p
d.Set("user_managed", computeRec.UserManaged)
d.Set("vnc_password", computeRec.VNCPassword)
d.Set("vgpus", flattenVGPUs(computeRec.VGPUs))
d.Set("virtual_image_id", computeRec.VirtualImageID)
d.Set("virtual_image_name", computeRec.VirtualImageName)
//TODO
// d.Set("virtual_image_id", computeRec.VirtualImageID)
// d.Set("virtual_image_name", computeRec.VirtualImageName)
d.Set("pci_devices", flattenPCI(*pciList))
d.Set("loader_type", computeRec.LoaderType)
d.Set("boot_type", computeRec.BootType)
d.Set("hot_resize", computeRec.HotResize)
d.Set("network_interface_naming", computeRec.NetworkInterfaceNaming)
d.Set("zone_id", computeRec.ZoneID)
d.Set("os_version", computeRec.OSVersion)
return nil
}
@@ -169,6 +172,7 @@ func flattenInterfaces(ifaces compute.ListInterfaces) []map[string]interface{} {
"conn_type": iface.ConnType,
"def_gw": iface.DefGW,
"enabled": iface.Enabled,
"enable_secgroups": iface.EnableSecGroups,
"flip_group_id": iface.FLIPGroupID,
"guid": iface.GUID,
"ip_address": iface.IPAddress,
@@ -183,6 +187,7 @@ func flattenInterfaces(ifaces compute.ListInterfaces) []map[string]interface{} {
"pci_slot": iface.PCISlot,
"qos": flattenQOS(iface.QOS),
"sdn_interface_id": iface.SDNInterfaceID,
"security_groups": iface.SecGroups,
"target": iface.Target,
"type": iface.Type,
"trunk_tags": iface.TrunkTags,
@@ -241,20 +246,22 @@ func flattenComputeDisks(disksList compute.ListDisks, disksBlocks, extraDisks []
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,
"pool": disk.Pool,
"desc": disk.Description,
"image_id": disk.ImageID,
"disk_id": disk.ID,
"shareable": disk.Shareable,
"size_used": disk.SizeUsed,
"size_max": disk.SizeMax,
"permanently": pernamentlyValue,
"present_to": disk.PresentTo,
"disk_name": disk.Name,
"node_ids": nodeIds,
"size": disk.SizeMax,
"sep_id": disk.SEPID,
"disk_type": disk.Type,
"pool": disk.Pool,
"desc": disk.Description,
"image_id": disk.ImageID,
"disk_id": disk.ID,
"shareable": disk.Shareable,
"size_used": disk.SizeUsed,
"size_max": disk.SizeMax,
"permanently": pernamentlyValue,
"present_to": disk.PresentTo,
"storage_policy_id": disk.StoragePolicyID,
"to_clean": disk.ToClean,
}
res = append(res, temp)
indexDataDisks++
@@ -296,77 +303,79 @@ func flattenComputeList(computes *compute.ListComputes) []map[string]interface{}
devices, _ := json.Marshal(computeItem.Devices)
userData, _ := json.Marshal(computeItem.Userdata)
temp := map[string]interface{}{
"acl": flattenListACLInterface(computeItem.ACL),
"account_id": computeItem.AccountID,
"account_name": computeItem.AccountName,
"affinity_label": computeItem.AffinityLabel,
"affinity_rules": flattenListRules(computeItem.AffinityRules),
"affinity_weight": computeItem.AffinityWeight,
"anti_affinity_rules": flattenListRules(computeItem.AntiAffinityRules),
"arch": computeItem.Arch,
"auto_start_w_node": computeItem.AutoStart,
"chipset": computeItem.Chipset,
"cd_image_id": computeItem.CdImageId,
"boot_order": computeItem.BootOrder,
"bootdisk_size": computeItem.BootDiskSize,
"clone_reference": computeItem.CloneReference,
"clones": computeItem.Clones,
"computeci_id": computeItem.ComputeCIID,
"cpus": computeItem.CPUs,
"created_by": computeItem.CreatedBy,
"created_time": computeItem.CreatedTime,
"custom_fields": string(customFields),
"deleted_by": computeItem.DeletedBy,
"deleted_time": computeItem.DeletedTime,
"desc": computeItem.Description,
"devices": string(devices),
"disks": flattenDisks(computeItem.Disks),
"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),
"live_migration_job_id": computeItem.LiveMigrationJobID,
"lock_status": computeItem.LockStatus,
"manager_id": computeItem.ManagerID,
"manager_type": computeItem.ManagerType,
"migrationjob": computeItem.MigrationJob,
"milestones": computeItem.Milestones,
"nid": computeItem.NID,
"name": computeItem.Name,
"need_reboot": computeItem.NeedReboot,
"numa_affinity": computeItem.NumaAffinity,
"numa_node_id": computeItem.NumaNodeId,
"os_users": flattenOSUsers(computeItem.OSUsers),
"pinned": computeItem.PinnedToStack,
"preferred_cpu": computeItem.PreferredCPU,
"qemu_guest": flattenQemuQuest(computeItem.QemuQuest),
"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),
"stack_id": computeItem.StackID,
"stack_name": computeItem.StackName,
"stateless_sep_id": computeItem.StatelessSEPID,
"stateless_sep_type": computeItem.StatelessSEPType,
"status": computeItem.Status,
"tags": flattenTags(computeItem.Tags),
"tech_status": computeItem.TechStatus,
"total_disk_size": computeItem.TotalDiskSize,
"updated_by": computeItem.UpdatedBy,
"updated_time": computeItem.UpdatedTime,
"user_data": string(userData),
"user_managed": computeItem.UserManaged,
"vgpus": computeItem.VGPUs,
"vins_connected": computeItem.VINSConnected,
"virtual_image_id": computeItem.VirtualImageID,
"acl": flattenListACLInterface(computeItem.ACL),
"account_id": computeItem.AccountID,
"account_name": computeItem.AccountName,
"affinity_label": computeItem.AffinityLabel,
"affinity_rules": flattenListRules(computeItem.AffinityRules),
"affinity_weight": computeItem.AffinityWeight,
"anti_affinity_rules": flattenListRules(computeItem.AntiAffinityRules),
"arch": computeItem.Arch,
"auto_start_w_node": computeItem.AutoStart,
"chipset": computeItem.Chipset,
"cd_image_id": computeItem.CdImageId,
"boot_order": computeItem.BootOrder,
"boot_image_id": computeItem.BootImageID,
"bootdisk_size": computeItem.BootDiskSize,
"clone_reference": computeItem.CloneReference,
"clones": computeItem.Clones,
"computeci_id": computeItem.ComputeCIID,
"cpus": computeItem.CPUs,
"created_by": computeItem.CreatedBy,
"created_time": computeItem.CreatedTime,
"custom_fields": string(customFields),
"deleted_by": computeItem.DeletedBy,
"deleted_time": computeItem.DeletedTime,
"desc": computeItem.Description,
"devices": string(devices),
"disks": flattenDisks(computeItem.Disks),
"driver": computeItem.Driver,
"gid": computeItem.GID,
"guid": computeItem.GUID,
"hp_backed": computeItem.HPBacked,
"compute_id": computeItem.ID,
"cpu_pin": computeItem.CPUPin,
"interfaces": flattenInterfaces(computeItem.Interfaces),
"live_migration_job_id": computeItem.LiveMigrationJobID,
"lock_status": computeItem.LockStatus,
"manager_id": computeItem.ManagerID,
"manager_type": computeItem.ManagerType,
"migrationjob": computeItem.MigrationJob,
"milestones": computeItem.Milestones,
"nid": computeItem.NID,
"name": computeItem.Name,
"need_reboot": computeItem.NeedReboot,
"numa_affinity": computeItem.NumaAffinity,
"numa_node_id": computeItem.NumaNodeId,
"os_users": flattenOSUsers(computeItem.OSUsers),
"os_version": computeItem.OSVersion,
"pinned": computeItem.PinnedToStack,
"preferred_cpu": computeItem.PreferredCPU,
"qemu_guest": flattenQemuQuest(computeItem.QemuQuest),
"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),
"stack_id": computeItem.StackID,
"stack_name": computeItem.StackName,
"stateless_sep_id": computeItem.StatelessSEPID,
"stateless_sep_type": computeItem.StatelessSEPType,
"status": computeItem.Status,
"tags": flattenTags(computeItem.Tags),
"tech_status": computeItem.TechStatus,
"total_disk_size": computeItem.TotalDiskSize,
"updated_by": computeItem.UpdatedBy,
"updated_time": computeItem.UpdatedTime,
"user_data": string(userData),
"user_managed": computeItem.UserManaged,
"vgpus": computeItem.VGPUs,
"vins_connected": computeItem.VINSConnected,
//TODO
// "virtual_image_id": computeItem.VirtualImageID,
"loader_type": computeItem.LoaderType,
"boot_type": computeItem.BootType,
"hot_resize": computeItem.HotResize,
@@ -386,74 +395,78 @@ func flattenDeletedComputeList(computes *compute.ListDeletedComputes) []map[stri
devices, _ := json.Marshal(computeItem.Devices)
userData, _ := json.Marshal(computeItem.Userdata)
temp := map[string]interface{}{
"acl": flattenListACLInterface(computeItem.ACL),
"account_id": computeItem.AccountID,
"account_name": computeItem.AccountName,
"affinity_label": computeItem.AffinityLabel,
"affinity_rules": flattenListRules(computeItem.AffinityRules),
"affinity_weight": computeItem.AffinityWeight,
"anti_affinity_rules": flattenListRules(computeItem.AntiAffinityRules),
"arch": computeItem.Arch,
"auto_start_w_node": computeItem.AutoStart,
"chipset": computeItem.Chipset,
"cd_image_id": computeItem.CdImageId,
"boot_order": computeItem.BootOrder,
"bootdisk_size": computeItem.BootDiskSize,
"clone_reference": computeItem.CloneReference,
"clones": computeItem.Clones,
"computeci_id": computeItem.ComputeCIID,
"cpus": computeItem.CPUs,
"created_by": computeItem.CreatedBy,
"created_time": computeItem.CreatedTime,
"custom_fields": string(customFields),
"deleted_by": computeItem.DeletedBy,
"deleted_time": computeItem.DeletedTime,
"desc": computeItem.Description,
"devices": string(devices),
"disks": flattenDisks(computeItem.Disks),
"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,
"manager_id": computeItem.ManagerID,
"manager_type": computeItem.ManagerType,
"migrationjob": computeItem.MigrationJob,
"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.PinnedToStack,
"preferred_cpu": computeItem.PreferredCPU,
"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),
"stack_id": computeItem.StackID,
"stack_name": computeItem.StackName,
"stateless_sep_id": computeItem.StatelessSEPID,
"stateless_sep_type": computeItem.StatelessSEPType,
"status": computeItem.Status,
"tags": flattenTags(computeItem.Tags),
"tech_status": computeItem.TechStatus,
"total_disk_size": computeItem.TotalDiskSize,
"updated_by": computeItem.UpdatedBy,
"updated_time": computeItem.UpdatedTime,
"user_data": string(userData),
"user_managed": computeItem.UserManaged,
"vgpus": computeItem.VGPUs,
"vins_connected": computeItem.VINSConnected,
"virtual_image_id": computeItem.VirtualImageID,
"acl": flattenListACLInterface(computeItem.ACL),
"account_id": computeItem.AccountID,
"account_name": computeItem.AccountName,
"affinity_label": computeItem.AffinityLabel,
"affinity_rules": flattenListRules(computeItem.AffinityRules),
"affinity_weight": computeItem.AffinityWeight,
"anti_affinity_rules": flattenListRules(computeItem.AntiAffinityRules),
"arch": computeItem.Arch,
"auto_start_w_node": computeItem.AutoStart,
"chipset": computeItem.Chipset,
"cd_image_id": computeItem.CdImageId,
"boot_order": computeItem.BootOrder,
"bootdisk_size": computeItem.BootDiskSize,
"boot_image_id": computeItem.BootImageID,
"clone_reference": computeItem.CloneReference,
"clones": computeItem.Clones,
"computeci_id": computeItem.ComputeCIID,
"cpus": computeItem.CPUs,
"created_by": computeItem.CreatedBy,
"created_time": computeItem.CreatedTime,
"custom_fields": string(customFields),
"deleted_by": computeItem.DeletedBy,
"deleted_time": computeItem.DeletedTime,
"desc": computeItem.Description,
"devices": string(devices),
"disks": flattenDisks(computeItem.Disks),
"driver": computeItem.Driver,
"gid": computeItem.GID,
"guid": computeItem.GUID,
"hp_backed": computeItem.HPBacked,
"compute_id": computeItem.ID,
"cpu_pin": computeItem.CPUPin,
//TODO
// "image_id": computeItem.ImageID,
"interfaces": flattenInterfaces(computeItem.Interfaces),
"lock_status": computeItem.LockStatus,
"manager_id": computeItem.ManagerID,
"manager_type": computeItem.ManagerType,
"migrationjob": computeItem.MigrationJob,
"milestones": computeItem.Milestones,
"name": computeItem.Name,
"need_reboot": computeItem.NeedReboot,
"numa_affinity": computeItem.NumaAffinity,
"numa_node_id": computeItem.NumaNodeId,
"os_users": flattenOSUsers(computeItem.OSUsers),
"os_version": computeItem.OSVersion,
"pinned": computeItem.PinnedToStack,
"preferred_cpu": computeItem.PreferredCPU,
"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),
"stack_id": computeItem.StackID,
"stack_name": computeItem.StackName,
"stateless_sep_id": computeItem.StatelessSEPID,
"stateless_sep_type": computeItem.StatelessSEPType,
"status": computeItem.Status,
"tags": flattenTags(computeItem.Tags),
"tech_status": computeItem.TechStatus,
"total_disk_size": computeItem.TotalDiskSize,
"updated_by": computeItem.UpdatedBy,
"updated_time": computeItem.UpdatedTime,
"user_data": string(userData),
"user_managed": computeItem.UserManaged,
"vgpus": computeItem.VGPUs,
"vins_connected": computeItem.VINSConnected,
//TODO
// "virtual_image_id": computeItem.VirtualImageID,
"loader_type": computeItem.LoaderType,
"boot_type": computeItem.BootType,
"hot_resize": computeItem.HotResize,
@@ -544,8 +557,8 @@ func flattenDisks(disks []compute.InfoDisk) []map[string]interface{} {
}
func flattenComputeAudits(computeAudits compute.ListDetailedAudits) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(computeAudits))
for _, computeAudit := range computeAudits {
res := make([]map[string]interface{}, 0, len(computeAudits.Data))
for _, computeAudit := range computeAudits.Data {
temp := map[string]interface{}{
"call": computeAudit.Call,
"responsetime": computeAudit.ResponseTime,
@@ -723,6 +736,7 @@ func flattenDataCompute(d *schema.ResourceData, compFacts *compute.RecordCompute
d.Set("arch", compFacts.Arch)
d.Set("auto_start_w_node", compFacts.AutoStart)
d.Set("boot_order", compFacts.BootOrder)
d.Set("boot_image_id", compFacts.ImageID)
d.Set("chipset", compFacts.Chipset)
d.Set("cd_image_id", compFacts.CdImageId)
d.Set("clone_reference", compFacts.CloneReference)
@@ -785,14 +799,16 @@ func flattenDataCompute(d *schema.ResourceData, compFacts *compute.RecordCompute
d.Set("user_managed", compFacts.UserManaged)
d.Set("vnc_password", compFacts.VNCPassword)
d.Set("vgpus", flattenVGPUs(compFacts.VGPUs))
d.Set("virtual_image_id", compFacts.VirtualImageID)
d.Set("virtual_image_name", compFacts.VirtualImageName)
//TODO
// d.Set("virtual_image_id", compFacts.VirtualImageID)
// d.Set("virtual_image_name", compFacts.VirtualImageName)
d.Set("pci_devices", flattenPCI(*pciList))
d.Set("loader_type", compFacts.LoaderType)
d.Set("boot_type", compFacts.BootType)
d.Set("hot_resize", compFacts.HotResize)
d.Set("network_interface_naming", compFacts.NetworkInterfaceNaming)
d.Set("zone_id", compFacts.ZoneID)
d.Set("os_version", compFacts.OSVersion)
//extra fields setting
bootDisk := findBootDisk(compFacts.Disks)
if bootDisk != nil {
@@ -823,6 +839,7 @@ func parseComputeInterfacesToNetworks(networks []interface{}, ifaces compute.Lis
elem["mtu"] = value.MTU
elem["sdn_interface_id"] = value.SDNInterfaceID
elem["weight"] = flattenNetworkWeight(networks, value.NetID, value.NetType)
elem["enabled"] = value.Enabled
result = append(result, elem)
}
@@ -886,8 +903,10 @@ func flattenDisk(diskList compute.ListDisks) []map[string]interface{} {
"size_used": disk.SizeUsed,
"snapshots": flattendDiskSnapshotList(disk.Snapshots),
"status": disk.Status,
"storage_policy_id": disk.StoragePolicyID,
"tech_status": disk.TechStatus,
"type": disk.Type,
"to_clean": disk.ToClean,
}
res = append(res, temp)
}

View File

@@ -0,0 +1,10 @@
package kvmvm
type updatedNetwork struct {
DetachMap []map[string]interface{}
ChangeIPMap []map[string]interface{}
ChangeMacMap []map[string]interface{}
ChangeMTUMap []map[string]interface{}
AttachMap []map[string]interface{}
EnableMap []map[string]interface{}
}

View File

@@ -34,6 +34,8 @@ package kvmvm
import (
"context"
"errors"
"fmt"
"sort"
"strconv"
"strings"
@@ -116,6 +118,10 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
NetID: uint64(netInterfaceVal["net_id"].(int)),
}
if enabledNetwork(d.GetRawConfig().GetAttr("network"), reqInterface.NetID, reqInterface.NetType) {
reqInterface.Enabled = netInterfaceVal["enabled"].(bool)
}
if reqInterface.NetType == "DPDK" || reqInterface.NetType == "EXTNET" {
reqInterface.MTU = uint64(netInterfaceVal["mtu"].(int))
}
@@ -148,8 +154,9 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
for _, elem := range disks.([]interface{}) {
diskVal := elem.(map[string]interface{})
reqDataDisk := kvmx86.DataDisk{
DiskName: diskVal["disk_name"].(string),
Size: uint64(diskVal["size"].(int)),
DiskName: diskVal["disk_name"].(string),
Size: uint64(diskVal["size"].(int)),
StoragePolicyID: uint64(diskVal["storage_policy_id"].(int)),
}
if sepId, ok := diskVal["sep_id"]; ok {
reqDataDisk.SepID = uint64(sepId.(int))
@@ -178,12 +185,12 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
}
var computeId uint64
driver := d.Get("driver").(string)
createReqX86.RGID = uint64(d.Get("rg_id").(int))
createReqX86.Name = d.Get("name").(string)
createReqX86.CPU = uint64(d.Get("cpu").(int))
createReqX86.RAM = uint64(d.Get("ram").(int))
createReqX86.StoragePolicyID = uint64(d.Get("storage_policy_id").(int))
if image, ok := d.GetOk("image_id"); ok {
createReqX86.ImageID = uint64(image.(int))
@@ -192,8 +199,6 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
createReqX86.WithoutBootDisk = withoutBootDisk.(bool)
}
createReqX86.Driver = driver
if custom_fields, ok := d.GetOk("custom_fields"); ok {
val := custom_fields.(string)
val = strings.ReplaceAll(val, "\\", "")
@@ -221,6 +226,10 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
}
}
if osVersion, ok := d.GetOk("os_version"); ok {
createReqX86.OSVersion = osVersion.(string)
}
log.Debugf("resourceComputeCreate: creating Compute of type KVM VM x86")
apiResp, err := c.CloudBroker().KVMX86().Create(ctx, createReqX86)
if err != nil {
@@ -260,7 +269,7 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
loaderType, loaderTypeOk := d.GetOk("loader_type")
bootType, bootTypeOk := d.GetOk("boot_type")
hotResize, hotResizeOk := d.GetOk("hot_resize")
hotResize, hotResizeOk := d.GetOkExists("hot_resize")
networkInterfaceNaming, networkInterfaceNamingOk := d.GetOk("network_interface_naming")
if loaderTypeOk {
@@ -370,6 +379,10 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
break
}
}
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)))
continue
}
log.Debugf("resourceComputeCreate: Configure libvirt virtio interface parameters on Network with type %s and id %d", netType, netId)
req := compute.SetNetConfigRequest{
ComputeID: computeId,
@@ -390,6 +403,45 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
}
}
if secGroups, ok := d.GetOk("security_groups"); ok {
if secGroups.(*schema.Set).Len() > 0 {
sgl := secGroups.(*schema.Set).List()
for _, elem := range sgl {
secGroupsMap := elem.(map[string]interface{})
netType := secGroupsMap["net_type"].(string)
netId := uint64(secGroupsMap["net_id"].(int))
var mac string
for _, iface := range simpleCompRec.Interfaces {
if iface.NetID == netId && iface.NetType == netType {
mac = iface.MAC
break
}
}
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)))
continue
}
secGroupsIDs := make([]uint64, 0)
for _, id := range secGroupsMap["security_groups"].(*schema.Set).List() {
secGroupsIDs = append(secGroupsIDs, uint64(id.(int)))
}
log.Debugf("resourceComputeCreate: Configure security groups interface parameters on Network with type %s and id %d", netType, netId)
req := compute.ChangeSecGroupsRequest{
ComputeID: computeId,
Interface: mac,
SecGroups: secGroupsIDs,
EnableSecGroups: secGroupsMap["enable_secgroups"].(bool),
}
_, err := c.CloudBroker().Compute().ChangeSecGroups(ctx, req)
if err != nil {
warnings.Add(err)
}
}
}
}
if start, ok := d.GetOk("started"); ok && start.(bool) {
req := compute.StartRequest{ComputeID: computeId}
log.Debugf("resourceComputeCreate: starting Compute ID %d after completing its resource configuration", computeId)
@@ -767,7 +819,8 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
"loader_type",
"boot_type",
"hot_resize",
"network_interface_naming") {
"network_interface_naming",
"os_version") {
if err := utilityComputeUpdate(ctx, d, m); err != nil {
return diag.FromErr(err)
}
@@ -780,6 +833,13 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
}
}
if d.HasChange("security_groups") {
err = utilityComputeSecGroupsConfigure(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("disks") {
if err := utilityComputeUpdateDisks(ctx, d, m); err != nil {
return diag.FromErr(err)
@@ -938,7 +998,7 @@ func ResourceCompute() *schema.Resource {
CustomizeDiff: func(ctx context.Context, diff *schema.ResourceDiff, i interface{}) error {
if diff.HasChanges() || diff.HasChanges("chipset", "pin_to_stack", "auto_start_w_node", "libvirt_settings", "network", "affinity_rules", "anti_affinity_rules",
"extra_disks", "tags", "port_forwarding", "user_access", "snapshot", "pci_devices", "preferred_cpu") {
"extra_disks", "tags", "port_forwarding", "user_access", "snapshot", "pci_devices", "preferred_cpu", "security_groups") {
diff.SetNewComputed("updated_time")
diff.SetNewComputed("updated_by")
}

View File

@@ -145,6 +145,10 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
},
},
"boot_image_id": {
Type: schema.TypeInt,
Computed: true,
},
"chipset": {
Type: schema.TypeString,
Computed: true,
@@ -510,6 +514,10 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"storage_policy_id": {
Type: schema.TypeInt,
Computed: true,
},
"tech_status": {
Type: schema.TypeString,
Computed: true,
@@ -518,6 +526,10 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"to_clean": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},
@@ -577,6 +589,10 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeBool,
Computed: true,
},
"enable_secgroups": {
Type: schema.TypeBool,
Computed: true,
},
"flip_group_id": {
Type: schema.TypeInt,
Computed: true,
@@ -702,6 +718,13 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"security_groups": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"vnfs": {
Type: schema.TypeList,
Computed: true,
@@ -796,6 +819,10 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
},
},
},
"os_version": {
Type: schema.TypeString,
Computed: true,
},
"pinned": {
Type: schema.TypeInt,
Computed: true,
@@ -1142,11 +1169,6 @@ func dataSourceComputeListSchemaMake() map[string]*schema.Schema {
Optional: true,
Description: "Find by stack ID",
},
"image_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Find by image ID",
},
"cd_image_id": {
Type: schema.TypeInt,
Optional: true,
@@ -1179,6 +1201,11 @@ func dataSourceComputeListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Optional: true,
},
"zone_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Zone ID",
},
"ignore_k8s": {
Type: schema.TypeBool,
Optional: true,
@@ -1321,6 +1348,10 @@ func dataSourceComputeListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"boot_image_id": {
Type: schema.TypeInt,
Computed: true,
},
"chipset": {
Type: schema.TypeString,
Computed: true,
@@ -1449,6 +1480,10 @@ func dataSourceComputeListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeBool,
Computed: true,
},
"enable_secgroups": {
Type: schema.TypeBool,
Computed: true,
},
"flip_group_id": {
Type: schema.TypeInt,
Computed: true,
@@ -1561,6 +1596,13 @@ func dataSourceComputeListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"security_groups": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"target": {
Type: schema.TypeString,
Computed: true,
@@ -1651,6 +1693,10 @@ func dataSourceComputeListSchemaMake() map[string]*schema.Schema {
},
},
},
"os_version": {
Type: schema.TypeString,
Computed: true,
},
"pinned": {
Type: schema.TypeInt,
Computed: true,
@@ -2061,6 +2107,10 @@ func dataSourceComputeListDeletedSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"boot_image_id": {
Type: schema.TypeInt,
Computed: true,
},
"chipset": {
Type: schema.TypeString,
Computed: true,
@@ -2185,6 +2235,10 @@ func dataSourceComputeListDeletedSchemaMake() map[string]*schema.Schema {
Type: schema.TypeBool,
Computed: true,
},
"enable_secgroups": {
Type: schema.TypeBool,
Computed: true,
},
"flip_group_id": {
Type: schema.TypeInt,
Computed: true,
@@ -2297,6 +2351,13 @@ func dataSourceComputeListDeletedSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"security_groups": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"target": {
Type: schema.TypeString,
Computed: true,
@@ -2379,6 +2440,10 @@ func dataSourceComputeListDeletedSchemaMake() map[string]*schema.Schema {
},
},
},
"os_version": {
Type: schema.TypeString,
Computed: true,
},
"pinned": {
Type: schema.TypeInt,
Computed: true,
@@ -2561,6 +2626,42 @@ func dataSourceComputeAuditsSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Required: true,
},
"timestamp_at": {
Type: schema.TypeInt,
Optional: true,
},
"timestamp_to": {
Type: schema.TypeInt,
Optional: true,
},
"user": {
Type: schema.TypeString,
Optional: true,
},
"call": {
Type: schema.TypeString,
Optional: true,
},
"sort_by": {
Type: schema.TypeString,
Optional: true,
},
"page": {
Type: schema.TypeInt,
Optional: true,
},
"size": {
Type: schema.TypeInt,
Optional: true,
},
"min_status_code": {
Type: schema.TypeInt,
Optional: true,
},
"max_status_code": {
Type: schema.TypeInt,
Optional: true,
},
"items": {
Type: schema.TypeList,
@@ -2590,6 +2691,10 @@ func dataSourceComputeAuditsSchemaMake() map[string]*schema.Schema {
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
}
@@ -3226,13 +3331,6 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
ValidateFunc: validation.IntAtLeast(1),
Description: "ID of the resource group where this compute should be deployed.",
},
"driver": {
Type: schema.TypeString,
Required: true,
StateFunc: statefuncs.StateFuncToUpper,
ValidateFunc: validation.StringInSlice([]string{"KVM_X86"}, false), // observe case while validating
Description: "Hardware architecture of this compute instance.",
},
"cpu": {
Type: schema.TypeInt,
Required: true,
@@ -3248,6 +3346,11 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
),
Description: "Amount of RAM in MB to allocate to this compute instance.",
},
"storage_policy_id": {
Type: schema.TypeInt,
Required: true,
Description: "Storage policy id of compute. The rules of the specified storage policy will be used.",
},
"image_id": {
Type: schema.TypeInt,
Optional: true,
@@ -3386,6 +3489,12 @@ 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",
},
},
},
Description: "Optional network connection(s) for this compute. You may specify several network blocks, one for each connection.",
@@ -3443,6 +3552,40 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
Description: "Configure libvirt virtio interface parameters. You can only delete values locally. Data on the platform cannot be deleted.",
},
"security_groups": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"net_type": {
Type: schema.TypeString,
Required: true,
StateFunc: statefuncs.StateFuncToUpper,
ValidateFunc: validation.StringInSlice([]string{"VINS", "EXTNET", "VFNIC", "DPDK", "SDN", "TRUNK"}, false), // observe case while validating
Description: "Type of the network",
},
"net_id": {
Type: schema.TypeInt,
Required: true,
Description: "ID of the network",
},
"security_groups": {
Type: schema.TypeSet,
Required: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"enable_secgroups": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
},
},
Description: "list of security group IDs to apply to this interface",
},
"affinity_label": {
Type: schema.TypeString,
Optional: true,
@@ -3541,6 +3684,11 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
Required: true,
Description: "Disk size in GiB",
},
"storage_policy_id": {
Type: schema.TypeInt,
Required: true,
Description: "Storage policy id of disk. The rules of the specified storage policy will be used.",
},
"sep_id": {
Type: schema.TypeInt,
Computed: true,
@@ -3608,6 +3756,10 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"to_clean": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},
@@ -3841,6 +3993,12 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
ValidateFunc: validation.StringInSlice([]string{"eth", "ens"}, false),
Description: "Name of netfowrk interface.",
},
"os_version": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "the OS version installed on the VM",
},
// Computed properties
"account_id": {
Type: schema.TypeInt,
@@ -3904,6 +4062,10 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "This compute instance boot disk ID.",
},
"boot_image_id": {
Type: schema.TypeInt,
Computed: true,
},
"cd_image_id": {
Type: schema.TypeInt,
Computed: true,
@@ -3943,6 +4105,10 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"driver": {
Type: schema.TypeString,
Computed: true,
},
"gid": {
Type: schema.TypeInt,
Computed: true,
@@ -3980,6 +4146,10 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeBool,
Computed: true,
},
"enable_secgroups": {
Type: schema.TypeBool,
Computed: true,
},
"flip_group_id": {
Type: schema.TypeInt,
Computed: true,
@@ -4092,6 +4262,13 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"security_groups": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"target": {
Type: schema.TypeString,
Computed: true,

View File

@@ -39,6 +39,7 @@ import (
"strconv"
"strings"
"github.com/hashicorp/go-cty/cty"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/disks"
@@ -111,7 +112,13 @@ func utilityComputeResize(ctx context.Context, d *schema.ResourceData, m interfa
c := m.(*controller.ControllerCfg)
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
if d.Get("started").(bool) {
var isStopRequired bool
old, new := d.GetChange("cpu")
if d.Get("started").(bool) && (old.(int) > new.(int)) && d.Get("force_resize").(bool) {
isStopRequired = true
}
if isStopRequired {
stopReq := compute.StopRequest{
ComputeID: computeId,
Force: false,
@@ -176,7 +183,7 @@ func utilityComputeResize(ctx context.Context, d *schema.ResourceData, m interfa
}
}
if d.Get("started").(bool) {
if isStopRequired {
if _, err := c.CloudBroker().Compute().Start(ctx, compute.StartRequest{ComputeID: computeId}); err != nil {
return err
}
@@ -227,6 +234,7 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
addedDisks := make([]interface{}, 0)
resizedDisks := make([]interface{}, 0)
renamedDisks := make([]interface{}, 0)
changeStoragePolicyDisks := make([]interface{}, 0)
presentNewDisks := make([]interface{}, 0)
presentOldDisks := make([]interface{}, 0)
@@ -241,7 +249,7 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
presentOldDisks = append(presentOldDisks, el)
}
// !isRenameDisk(newConv, el) && !isResizeDisk(newConv, el) are required in case two or more disks are being created and their disk_id is the same (=0)
if !isContainsDisk(newConv, el) && !isRenameDisk(newConv, el) && !isResizeDisk(newConv, el) {
if !isContainsDisk(newConv, el) && !isRenameDisk(newConv, el) && !isResizeDisk(newConv, el) && !isChangeStoragePolicy(newConv, el) {
flag := false
extraDisks := d.Get("extra_disks").(*schema.Set).List()
delDisk := el.(map[string]interface{})
@@ -272,19 +280,12 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
if isRenameDisk(oldConv, el) {
renamedDisks = append(renamedDisks, el)
}
if isChangeStoragePolicy(oldConv, el) {
changeStoragePolicyDisks = append(changeStoragePolicyDisks, el)
}
}
if len(deletedDisks) > 0 {
stopReq := compute.StopRequest{
ComputeID: computeId,
Force: false,
}
_, err := c.CloudBroker().Compute().Stop(ctx, stopReq)
if err != nil {
return err
}
for _, disk := range deletedDisks {
diskConv := disk.(map[string]interface{})
if diskConv["disk_type"].(string) == "B" {
@@ -302,14 +303,6 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
return err
}
}
req := compute.StartRequest{
ComputeID: computeId,
AltBootID: 0,
}
_, err = c.CloudBroker().Compute().Start(ctx, req)
if err != nil {
return err
}
}
if len(addedDisks) > 0 {
@@ -319,9 +312,10 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
continue
}
req := compute.DiskAddRequest{
ComputeID: computeId,
DiskName: diskConv["disk_name"].(string),
Size: uint64(diskConv["size"].(int)),
ComputeID: computeId,
DiskName: diskConv["disk_name"].(string),
Size: uint64(diskConv["size"].(int)),
StoragePolicyID: uint64(diskConv["storage_policy_id"].(int)),
}
if diskConv["sep_id"].(int) != 0 {
req.SepID = uint64(diskConv["sep_id"].(int))
@@ -399,6 +393,21 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
}
}
}
if len(changeStoragePolicyDisks) > 0 {
for _, disk := range changeStoragePolicyDisks {
diskConv := disk.(map[string]interface{})
req := disks.ChangeDiskStoragePolicyRequest{
DiskID: uint64(diskConv["disk_id"].(int)),
StoragePolicyID: uint64(diskConv["storage_policy_id"].(int)),
}
_, err := c.CloudBroker().Disks().ChangeDiskStoragePolicy(ctx, req)
if err != nil {
return err
}
}
}
for i := range presentNewDisks {
newDisk := presentNewDisks[i].(map[string]interface{})
@@ -589,12 +598,12 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
oldList := oldSet.(*schema.Set).List()
newList := newSet.(*schema.Set).List()
detachMap, changeIpMap, changeMacMap, changeMTUMap, attachMap := differenceNetwork(oldList, newList)
updateNetwork := differenceNetwork(oldList, newList)
apiErrCount := 0
var lastSavedError error
log.Debugf("utilityComputeNetworksConfigure: detach set has %d items for Compute ID %s", len(detachMap), d.Id())
for _, netData := range detachMap {
log.Debugf("utilityComputeNetworksConfigure: detach set has %d items for Compute ID %s", len(updateNetwork.DetachMap), d.Id())
for _, netData := range updateNetwork.DetachMap {
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
req := compute.NetDetachRequest{
ComputeID: computeId,
@@ -611,8 +620,8 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
}
}
log.Debugf("utilityComputeNetworksConfigure: changeIp set has %d items for Compute ID %s", len(changeIpMap), d.Id())
for _, netData := range changeIpMap {
log.Debugf("utilityComputeNetworksConfigure: changeIp set has %d items for Compute ID %s", len(updateNetwork.ChangeIPMap), d.Id())
for _, netData := range updateNetwork.ChangeIPMap {
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
req := compute.ChangeIPRequest{
ComputeID: computeId,
@@ -634,9 +643,9 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
oldLibvirtSet, newLibvirtSet := d.GetChange("libvirt_settings")
addedLibvirtSettings := (newLibvirtSet.(*schema.Set).Difference(oldLibvirtSet.(*schema.Set))).List()
libvirtSettingsMap := addAttachedNetwork(addedLibvirtSettings, newLibvirtSet.(*schema.Set).List(), attachMap)
libvirtSettingsMap := addAttachedNetwork(addedLibvirtSettings, newLibvirtSet.(*schema.Set).List(), updateNetwork.AttachMap)
if oldSet.(*schema.Set).Len() == len(detachMap) || oldSet.(*schema.Set).Len() == 0 || len(libvirtSettingsMap) > 0 || hasDPDKnetwork(attachMap) || len(changeMacMap) > 0 {
if oldSet.(*schema.Set).Len() == len(updateNetwork.DetachMap) || oldSet.(*schema.Set).Len() == 0 || len(libvirtSettingsMap) > 0 || hasDPDKnetwork(updateNetwork.AttachMap) || len(updateNetwork.ChangeMacMap) > 0 {
if err := utilityComputeStop(ctx, d, m); err != nil {
apiErrCount++
lastSavedError = err
@@ -646,8 +655,8 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
}
}
log.Debugf("utilityComputeNetworksConfigure: changeMac set has %d items for Compute ID %s", len(changeMacMap), d.Id())
for _, netData := range changeMacMap {
log.Debugf("utilityComputeNetworksConfigure: changeMac set has %d items for Compute ID %s", len(updateNetwork.ChangeMacMap), d.Id())
for _, netData := range updateNetwork.ChangeMacMap {
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
req := compute.ChangeMACRequest{
ComputeID: computeId,
@@ -664,9 +673,9 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
}
}
sort.Slice(attachMap, func(i, j int) bool {
weightI := attachMap[i]["weight"].(int)
weightJ := attachMap[j]["weight"].(int)
sort.Slice(updateNetwork.AttachMap, func(i, j int) bool {
weightI := updateNetwork.AttachMap[i]["weight"].(int)
weightJ := updateNetwork.AttachMap[j]["weight"].(int)
if weightI == 0 {
return false
}
@@ -675,8 +684,8 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
}
return weightI < weightJ
})
log.Debugf("utilityComputeNetworksConfigure: attach set has %d items for Compute ID %s", len(attachMap), d.Id())
for _, netData := range attachMap {
log.Debugf("utilityComputeNetworksConfigure: attach set has %d items for Compute ID %s", len(updateNetwork.AttachMap), d.Id())
for _, netData := range updateNetwork.AttachMap {
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
req := compute.NetAttachRequest{
ComputeID: computeId,
@@ -696,7 +705,7 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
req.MACAddr = netData["mac"].(string)
}
if req.NetType == "DPDK" {
if req.NetType == "DPDK" || req.NetType == "EXTNET" {
req.MTU = uint64(netData["mtu"].(int))
}
@@ -724,7 +733,7 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
}
if computeRec != nil {
log.Debugf("utilityComputeNetworksConfigure: libvirt virtio set has %d items for Compute ID %s", len(attachMap), d.Id())
log.Debugf("utilityComputeNetworksConfigure: libvirt virtio set has %d items for Compute ID %s", len(libvirtSettingsMap), d.Id())
for _, libvirtSetting := range libvirtSettingsMap {
netType := libvirtSetting["net_type"].(string)
netId := uint64(libvirtSetting["net_id"].(int))
@@ -766,8 +775,8 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
}
}
log.Debugf("utilityComputeNetworksConfigure: changeMTU set has %d items for Compute ID %s", len(changeMTUMap), d.Id())
for _, netData := range changeMTUMap {
log.Debugf("utilityComputeNetworksConfigure: changeMTU set has %d items for Compute ID %s", len(updateNetwork.ChangeMTUMap), d.Id())
for _, netData := range updateNetwork.ChangeMTUMap {
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
req := compute.ChangeMTURequest{
ComputeID: computeId,
@@ -784,6 +793,28 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
}
}
log.Debugf("utilityComputeNetworksConfigure: enableMap set has %d items for Compute ID %s", len(updateNetwork.EnableMap), d.Id())
for _, netData := range updateNetwork.EnableMap {
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
req := compute.ChangeLinkStateRequest{
ComputeID: computeId,
Interface: netData["mac"].(string),
State: "off",
}
if netData["enabled"].(bool) {
req.State = "on"
}
_, err := c.CloudBroker().Compute().ChangeLinkState(ctx, req)
if err != nil {
log.Errorf("utilityComputeNetworksConfigure: failed to change link state network ID %d of type %s from Compute ID %s: %s",
netData["net_id"].(int), netData["net_type"].(string), d.Id(), err)
apiErrCount++
lastSavedError = err
}
}
if apiErrCount > 0 {
log.Errorf("utilityComputeNetworksConfigure: there were %d error(s) when managing networks of Compute ID %s. Last error was: %s",
apiErrCount, d.Id(), lastSavedError)
@@ -793,12 +824,13 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
return nil
}
func differenceNetwork(oldList, newList []interface{}) (detachMap, changeIpMap, changeMacMap, changeMTUMap, attachMap []map[string]interface{}) {
attachMap = make([]map[string]interface{}, 0)
changeIpMap = make([]map[string]interface{}, 0)
changeMacMap = make([]map[string]interface{}, 0)
changeMTUMap = make([]map[string]interface{}, 0)
detachMap = make([]map[string]interface{}, 0)
func differenceNetwork(oldList, newList []interface{}) *updatedNetwork {
attachMap := make([]map[string]interface{}, 0)
changeIpMap := make([]map[string]interface{}, 0)
changeMacMap := make([]map[string]interface{}, 0)
changeMTUMap := make([]map[string]interface{}, 0)
detachMap := make([]map[string]interface{}, 0)
enableMap := make([]map[string]interface{}, 0)
for _, oldNetwork := range oldList {
oldMap := oldNetwork.(map[string]interface{})
found := false
@@ -816,6 +848,13 @@ func differenceNetwork(oldList, newList []interface{}) (detachMap, changeIpMap,
if (newMap["net_type"].(string) == "EXTNET" || newMap["net_type"].(string) == "DPDK") && (newMap["mtu"] != oldMap["mtu"] && newMap["mtu"].(int) != 0) {
changeMTUMap = append(changeMTUMap, newMap)
}
if newMap["enabled"].(bool) != oldMap["enabled"].(bool) {
mac, _ := newMap["mac"].(string)
if mac == "" {
newMap["mac"] = oldMap["mac"]
}
enableMap = append(enableMap, newMap)
}
}
if found {
break
@@ -843,7 +882,16 @@ func differenceNetwork(oldList, newList []interface{}) (detachMap, changeIpMap,
attachMap = append(attachMap, newMap)
}
return
res := updatedNetwork{
DetachMap: detachMap,
ChangeIPMap: changeIpMap,
ChangeMacMap: changeMacMap,
ChangeMTUMap: changeMTUMap,
AttachMap: attachMap,
EnableMap: enableMap,
}
return &res
}
func compareNetwork(newMap, oldMap map[string]interface{}) bool {
@@ -893,6 +941,75 @@ func addAttachedNetwork(addedLibvirtSettings []interface{}, newLibvirtSettings [
return
}
func utilityComputeSecGroupsConfigure(ctx context.Context, d *schema.ResourceData, m interface{}) error {
c := m.(*controller.ControllerCfg)
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
simpleCompRec, err := utilityComputeCheckPresence(ctx, d, m)
if err != nil {
return err
}
apiErrCount := 0
var lastSavedError error
oldSecGroups, newSecGroups := d.GetChange("security_groups")
updateSecGroups := (newSecGroups.(*schema.Set).Difference(oldSecGroups.(*schema.Set))).List()
log.Debugf("utilityComputeSecGroupsConfigure: update security groups has %d items for Compute ID %s", len(updateSecGroups), d.Id())
if len(updateSecGroups) > 0 {
for _, elem := range updateSecGroups {
secGroupsMap := elem.(map[string]interface{})
netType := secGroupsMap["net_type"].(string)
netId := uint64(secGroupsMap["net_id"].(int))
var mac string
for _, iface := range simpleCompRec.Interfaces {
if iface.NetID == netId && iface.NetType == netType {
mac = iface.MAC
break
}
}
if mac == "" {
log.Errorf("utilityComputeSecGroupsConfigure: Network with type %s and id %d is not connected to the compute %s",
netType, netId, d.Id())
apiErrCount++
lastSavedError = errors.New(fmt.Sprintf("utilityComputeSecGroupsConfigure: Network with type %s and id %d is not connected to the compute %s",
netType, netId, d.Id()))
continue
}
secGroupsIDs := make([]uint64, 0)
for _, id := range secGroupsMap["security_groups"].(*schema.Set).List() {
secGroupsIDs = append(secGroupsIDs, uint64(id.(int)))
}
log.Debugf("utilityComputeSecGroupsConfigure: Configure security groups interface parameters on Network with type %s and id %d", netType, netId)
req := compute.ChangeSecGroupsRequest{
ComputeID: computeId,
Interface: mac,
SecGroups: secGroupsIDs,
}
if secGroupsMap["enable_secgroups"] != nil {
req.EnableSecGroups = secGroupsMap["enable_secgroups"].(bool)
}
_, err := c.CloudBroker().Compute().ChangeSecGroups(ctx, req)
if err != nil {
apiErrCount++
lastSavedError = err
}
}
}
if apiErrCount > 0 {
log.Errorf("utilityComputeSecGroupsConfigure: there were %d error(s) when managing security groups of Compute ID %s. Last error was: %s",
apiErrCount, d.Id(), lastSavedError)
return lastSavedError
}
return nil
}
func utilityComputeUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) error {
c := m.(*controller.ControllerCfg)
@@ -931,6 +1048,10 @@ func utilityComputeUpdate(ctx context.Context, d *schema.ResourceData, m interfa
req.NetworkInterfaceNaming = d.Get("network_interface_naming").(string)
}
if d.HasChange("os_version") {
req.OSVersion = d.Get("os_version").(string)
}
req.CPUPin = d.Get("cpu_pin").(bool)
req.HPBacked = d.Get("hp_backed").(bool)
req.AutoStart = d.Get("auto_start_w_node").(bool)
@@ -954,7 +1075,7 @@ func utilityComputeUpdate(ctx context.Context, d *schema.ResourceData, m interfa
// Note bene: numa_affinity, cpu_pin and hp_backed are not allowed to be changed for compute in STARTED tech status.
// If STARTED, we need to stop it before update
var isStopRequired bool
if d.HasChanges("numa_affinity", "cpu_pin", "hp_backed", "chipset", "preferred_cpu") && d.Get("started").(bool) {
if d.HasChanges("numa_affinity", "cpu_pin", "hp_backed", "chipset", "preferred_cpu", "hot_resize") && d.Get("started").(bool) {
isStopRequired = true
}
if isStopRequired {
@@ -1597,9 +1718,10 @@ func utilityComputeUpdateImage(ctx context.Context, d *schema.ResourceData, m in
if oldImage.(int) != newImage.(int) {
req := compute.RedeployRequest{
ComputeID: computeId,
ImageID: uint64(newImage.(int)),
DataDisks: "KEEP",
ComputeID: computeId,
ImageID: uint64(newImage.(int)),
DataDisks: "KEEP",
StoragePolicyID: uint64(d.Get("storage_policy_id").(int)),
}
if diskSize, ok := d.GetOk("boot_disk_size"); ok {
@@ -1612,6 +1734,10 @@ func utilityComputeUpdateImage(ctx context.Context, d *schema.ResourceData, m in
req.ForceStop = forceStop.(bool)
}
if osVersion, ok := d.GetOk("os_version"); ok {
req.OSVersion = osVersion.(string)
}
_, err := c.CloudBroker().Compute().Redeploy(ctx, req)
if err != nil {
return err
@@ -1772,6 +1898,18 @@ func isRenameDisk(els []interface{}, el interface{}) bool {
return false
}
func isChangeStoragePolicy(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["storage_policy_id"].(int) != elConv["storage_policy_id"].(int) {
return true
}
}
return false
}
func isContainsDisk(els []interface{}, el interface{}) bool {
for _, elOld := range els {
elOldConv := elOld.(map[string]interface{})
@@ -1839,3 +1977,25 @@ func getComputeDiskIDs(disksList compute.ListDisks, disksBlocks, extraDisks []in
return res
}
func enabledNetwork(rawNetworkConfig cty.Value, netID uint64, netType string) bool {
for _, netConfigVal := range rawNetworkConfig.AsValueSlice() {
if netConfigVal.IsNull() {
continue
}
netConfig := netConfigVal.AsValueMap()
tempID, _ := netConfig["net_id"].AsBigFloat().Int64()
configNetID := uint64(tempID)
configNetType := netConfig["net_type"].AsString()
if configNetID == netID && configNetType == netType {
enabledVal := netConfig["enabled"]
return !enabledVal.IsNull()
}
}
return false
}

View File

@@ -45,10 +45,36 @@ func utilityComputeAuditsCheckPresence(ctx context.Context, d *schema.ResourceDa
req := compute.AuditsRequest{
ComputeID: uint64(d.Get("compute_id").(int)),
}
if timestampAt, ok := d.GetOk("timestamp_at"); ok {
req.TimestampAT = uint64(timestampAt.(int))
}
if timestampTo, ok := d.GetOk("timestamp_to"); ok {
req.TimestampTO = uint64(timestampTo.(int))
}
if user, ok := d.GetOk("user"); ok {
req.User = user.(string)
}
if call, ok := d.GetOk("call"); ok {
req.Call = call.(string)
}
if sortBy, ok := d.GetOk("sort_by"); ok {
req.SortBy = sortBy.(string)
}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
if minStatusCode, ok := d.GetOk("min_status_code"); ok {
req.MinStatusCode = uint64(minStatusCode.(int))
}
if maxStatusCode, ok := d.GetOk("max_status_code"); ok {
req.MaxStatusCode = uint64(maxStatusCode.(int))
}
computeAudits, err := c.CloudBroker().Compute().Audits(ctx, req)
if err != nil {
return nil, err
return compute.ListDetailedAudits{}, err
}
return computeAudits, nil
return *computeAudits, nil
}

View File

@@ -75,9 +75,6 @@ func utilityDataComputeListCheckPresence(ctx context.Context, d *schema.Resource
if stackName, ok := d.GetOk("stack_name"); ok {
req.StackName = stackName.(string)
}
if imageID, ok := d.GetOk("image_id"); ok {
req.ImageID = imageID.(uint64)
}
if cdImageID, ok := d.GetOk("cd_image_id"); ok {
req.CDImageID = cdImageID.(uint64)
}
@@ -99,6 +96,9 @@ func utilityDataComputeListCheckPresence(ctx context.Context, d *schema.Resource
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
if zoneID, ok := d.GetOk("zone_id"); ok {
req.ZoneID = uint64(zoneID.(int))
}
listComputes, err := c.CloudBroker().Compute().List(ctx, req)
if err != nil {