This commit is contained in:
2026-09-21 11:51:12 +03:00
parent 9cd93e4277
commit 2b229a84fb
240 changed files with 7735 additions and 3166 deletions

View File

@@ -58,6 +58,8 @@ func DataSourceComputeAudits() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
DeprecationMessage: "This data source is deprecated and will be removed in version 4.14.0; use decort_cb_audit_list instead.",
ReadContext: dataSourceComputeAuditsRead,
Timeouts: &schema.ResourceTimeout{

View File

@@ -0,0 +1,98 @@
/*
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package kvmvm
import (
"context"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func dataSourceComputeCPUAlignmentProfileRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
profile, err := utilityComputeGetCPUAlignmentProfile(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("model", profile.Model)
d.Set("name", profile.Name)
d.Set("vendor", profile.Vendor)
return nil
}
func dataSourceComputeCPUAlignmentProfileSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"compute_id": {
Type: schema.TypeInt,
Required: true,
Description: "ID of the compute instance",
},
"model": {
Type: schema.TypeString,
Computed: true,
Description: "CPU model of the alignment profile",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "Name of the CPU alignment profile",
},
"vendor": {
Type: schema.TypeString,
Computed: true,
Description: "CPU vendor of the alignment profile",
},
}
}
func DataSourceComputeCPUAlignmentProfile() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceComputeCPUAlignmentProfileRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceComputeCPUAlignmentProfileSchemaMake(),
}
}

View File

@@ -57,6 +57,8 @@ func DataSourceComputeGetAudits() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
DeprecationMessage: "This data source is deprecated and will be removed in version 4.14.0; use decort_cb_audit_list instead.",
ReadContext: dataSourceComputeGetAuditsRead,
Timeouts: &schema.ResourceTimeout{

View File

@@ -59,6 +59,8 @@ func DataSourceComputeGetLog() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
DeprecationMessage: "This data source is deprecated and will be removed in version 4.14.0.",
ReadContext: dataSourceComputeGetLogRead,
Timeouts: &schema.ResourceTimeout{

View File

@@ -34,6 +34,7 @@ package kvmvm
import (
"context"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -49,7 +50,7 @@ func dataSourceComputeMigrateStorageInfoRead(ctx context.Context, d *schema.Reso
id := uuid.New()
d.SetId(id.String())
d.Set("migrate_storage_info", result)
flattenMigrateStorageInfo(d, result)
return nil
}

View File

@@ -39,8 +39,10 @@ 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_disk_discard", bootDisk.Discard)
d.Set("boot_image_id", bootDisk.ImageID)
d.Set("chipset", computeRec.Chipset)
d.Set("clock", computeRec.Clock)
d.Set("cd_image_id", computeRec.CdImageId)
d.Set("clone_reference", computeRec.CloneReference)
d.Set("clones", computeRec.Clones)
@@ -85,6 +87,7 @@ func flattenCompute(d *schema.ResourceData, computeRec *compute.RecordCompute, p
d.Set("registered", computeRec.Registered)
d.Set("res_name", computeRec.ResName)
d.Set("reserved_node_cpus", computeRec.ReservedNodeCpus)
d.Set("resized_online", computeRec.ResizedOnline)
d.Set("rg_name", computeRec.RGName)
d.Set("rg_id", computeRec.RGID)
d.Set("snap_sets", flattenSnapSets(computeRec.SnapSets))
@@ -111,12 +114,26 @@ func flattenCompute(d *schema.ResourceData, computeRec *compute.RecordCompute, p
d.Set("zone_id", computeRec.ZoneID)
d.Set("os_version", computeRec.OSVersion)
d.Set("cpu_pin", computeRec.CPUPin)
d.Set("cpu_alignment_profile", computeRec.CPUAlignmentProfile.Name)
d.Set("numa_affinity", computeRec.NumaAffinity)
d.Set("hp_backed", computeRec.HPBacked)
d.Set("weight", computeRec.Weight)
return nil
}
func flattenCPUAlignmentProfile(profile compute.CPUAlignmentProfile) []map[string]interface{} {
if profile.Name == "" && profile.Model == "" && profile.Vendor == "" {
return nil
}
return []map[string]interface{}{
{
"name": profile.Name,
"model": profile.Model,
"vendor": profile.Vendor,
},
}
}
func flattenPCI(pciList compute.ListPCIDevices) []uint64 {
res := make([]uint64, 0, len(pciList.Data))
@@ -145,10 +162,11 @@ func flattenSnapSets(snaps compute.ListSnapshots) []map[string]interface{} {
for _, snap := range snaps {
res = append(res, map[string]interface{}{
"disks": snap.Disks,
"guid": snap.GUID,
"label": snap.Label,
"timestamp": snap.Timestamp,
"disks": snap.Disks,
"guid": snap.GUID,
"label": snap.Label,
"timestamp": snap.Timestamp,
"memory_dump_image": snap.MemoryDumpImage,
})
}
@@ -174,32 +192,33 @@ func flattenInterfaces(ifaces compute.ListInterfaces) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(ifaces))
for _, iface := range ifaces {
res = append(res, map[string]interface{}{
"bus_number": iface.BusNumber,
"conn_id": iface.ConnID,
"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,
"listen_ssh": iface.ListenSSH,
"mac": iface.MAC,
"mtu": iface.MTU,
"name": iface.Name,
"net_id": iface.NetID,
"netmask": iface.NetMask,
"net_type": iface.NetType,
"node_id": iface.NodeID,
"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,
"vnfs": iface.VNFs,
"libvirt_settings": flattenLibvirtSettings(iface.LibvirtSettings),
"bus_number": iface.BusNumber,
"conn_id": iface.ConnID,
"conn_type": iface.ConnType,
"def_gw": iface.DefGW,
"enabled": iface.Enabled,
"enable_secgroups": iface.EnableSecGroups,
"enable_default_gateway": iface.EnableDefaultGateway,
"flip_group_id": iface.FLIPGroupID,
"guid": iface.GUID,
"ip_address": iface.IPAddress,
"listen_ssh": iface.ListenSSH,
"mac": iface.MAC,
"mtu": iface.MTU,
"name": iface.Name,
"net_id": iface.NetID,
"netmask": iface.NetMask,
"net_type": iface.NetType,
"node_id": iface.NodeID,
"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,
"vnfs": iface.VNFs,
"libvirt_settings": flattenLibvirtSettings(iface.LibvirtSettings),
})
}
return res
@@ -273,6 +292,7 @@ func flattenComputeDisks(disksList compute.ListDisks, disksBlocks, extraDisks []
"pci_slot": disk.PCISlot,
"bus_number": disk.BusNumber,
"pool": disk.Pool,
"read_only": disk.ReadOnly,
"desc": disk.Description,
"image_id": disk.ImageID,
"independent": disk.Independent,
@@ -291,7 +311,7 @@ func flattenComputeDisks(disksList compute.ListDisks, disksBlocks, extraDisks []
"delete_time": disk.DeletedTime,
"update_time": disk.UpdatedTime,
"cache": disk.Cache,
"blk_discard": disk.BLKDiscard,
"discard": disk.Discard,
"block_size": disk.BlockSize,
"provision": disk.Provision,
"iotune": flattenIOTune(disk.IOTune),
@@ -346,6 +366,7 @@ func flattenComputeList(computes *compute.ListComputes) []map[string]interface{}
"arch": computeItem.Arch,
"auto_start_w_node": computeItem.AutoStart,
"chipset": computeItem.Chipset,
"clock": computeItem.Clock,
"cd_image_id": computeItem.CdImageId,
"boot_order": computeItem.BootOrder,
"boot_image_id": computeItem.BootImageID,
@@ -367,6 +388,7 @@ func flattenComputeList(computes *compute.ListComputes) []map[string]interface{}
"guid": computeItem.GUID,
"hp_backed": computeItem.HPBacked,
"compute_id": computeItem.ID,
"cpu_alignment_profiles": flattenCPUAlignmentProfile(computeItem.CPUAlignmentProfile),
"cpu_pin": computeItem.CPUPin,
"interfaces": flattenInterfaces(computeItem.Interfaces),
"live_migration_job_id": computeItem.LiveMigrationJobID,
@@ -390,6 +412,7 @@ func flattenComputeList(computes *compute.ListComputes) []map[string]interface{}
"registered": computeItem.Registered,
"res_name": computeItem.ResName,
"reserved_node_cpus": computeItem.ReservedNodeCpus,
"resized_online": computeItem.ResizedOnline,
"rg_id": computeItem.RGID,
"rg_name": computeItem.RGName,
"snap_sets": flattenSnapSets(computeItem.SnapSets),
@@ -438,6 +461,7 @@ func flattenDeletedComputeList(computes *compute.ListDeletedComputes) []map[stri
"arch": computeItem.Arch,
"auto_start_w_node": computeItem.AutoStart,
"chipset": computeItem.Chipset,
"clock": computeItem.Clock,
"cd_image_id": computeItem.CdImageId,
"boot_order": computeItem.BootOrder,
"bootdisk_size": computeItem.BootDiskSize,
@@ -459,6 +483,7 @@ func flattenDeletedComputeList(computes *compute.ListDeletedComputes) []map[stri
"guid": computeItem.GUID,
"hp_backed": computeItem.HPBacked,
"compute_id": computeItem.ID,
"cpu_alignment_profiles": flattenCPUAlignmentProfile(computeItem.CPUAlignmentProfile),
"cpu_pin": computeItem.CPUPin,
"interfaces": flattenInterfaces(computeItem.Interfaces),
"lock_status": computeItem.LockStatus,
@@ -479,6 +504,7 @@ func flattenDeletedComputeList(computes *compute.ListDeletedComputes) []map[stri
"registered": computeItem.Registered,
"res_name": computeItem.ResName,
"reserved_node_cpus": computeItem.ReservedNodeCpus,
"resized_online": computeItem.ResizedOnline,
"rg_id": computeItem.RGID,
"rg_name": computeItem.RGName,
"snap_sets": flattenSnapSets(computeItem.SnapSets),
@@ -580,7 +606,8 @@ func flattenDisks(disks []compute.InfoDisk) []map[string]interface{} {
// "bus_number": disk.BusNumber,
"disk_id": disk.ID,
// "pci_slot": disk.PCISlot,
"sep_id": disk.SepID,
"sep_id": disk.SepID,
"read_only": disk.ReadOnly,
}
res = append(res, temp)
}
@@ -779,10 +806,12 @@ func flattenDataCompute(d *schema.ResourceData, compFacts *compute.RecordCompute
d.Set("boot_order", compFacts.BootOrder)
d.Set("boot_image_id", compFacts.ImageID)
d.Set("chipset", compFacts.Chipset)
d.Set("clock", compFacts.Clock)
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_alignment_profiles", flattenCPUAlignmentProfile(compFacts.CPUAlignmentProfile))
d.Set("cpu_pin", compFacts.CPUPin)
d.Set("cpus", compFacts.CPUs)
d.Set("created_by", compFacts.CreatedBy)
@@ -824,6 +853,7 @@ func flattenDataCompute(d *schema.ResourceData, compFacts *compute.RecordCompute
d.Set("registered", compFacts.Registered)
d.Set("res_name", compFacts.ResName)
d.Set("reserved_node_cpus", compFacts.ReservedNodeCpus)
d.Set("resized_online", compFacts.ResizedOnline)
d.Set("rg_id", compFacts.RGID)
d.Set("rg_name", compFacts.RGName)
d.Set("snap_sets", flattenSnapSets(compFacts.SnapSets))
@@ -882,6 +912,7 @@ func parseComputeInterfacesToNetworks(networks []interface{}, ifaces compute.Lis
elem["sdn_interface_id"] = value.SDNInterfaceID
elem["weight"] = flattenNetworkWeight(networks, value.NetID, value.NetType)
elem["enabled"] = value.Enabled
elem["enable_default_gateway"] = value.EnableDefaultGateway
result = append(result, elem)
}
@@ -907,7 +938,7 @@ func flattenDisk(diskList compute.ListDisks) []map[string]interface{} {
"ckey": disk.CKey,
"meta": flattens.FlattenMeta(disk.Meta),
"account_id": disk.AccountID,
"blk_discard": disk.BLKDiscard,
"discard": disk.Discard,
"block_size": disk.BlockSize,
"boot_partition": disk.BootPartition,
"bus_number": disk.BusNumber,
@@ -957,6 +988,7 @@ func flattenDisk(diskList compute.ListDisks) []map[string]interface{} {
"to_clean": disk.ToClean,
"provision": disk.Provision,
"updated_time": disk.UpdatedTime,
"read_only": disk.ReadOnly,
}
res = append(res, temp)
}
@@ -1005,6 +1037,7 @@ func flattendDiskSnapshotList(sl compute.ListDetailedSnapshots) []interface{} {
temp := map[string]interface{}{
"guid": snapshot.GUID,
"label": snapshot.Label,
"pool_name": snapshot.PoolName,
"res_id": snapshot.ResID,
"snap_set_guid": snapshot.SnapSetGUID,
"snap_set_time": snapshot.SnapSetTime,
@@ -1063,3 +1096,193 @@ func flattenQemuQuest(qemuQuest compute.QemuQuest) []map[string]interface{} {
return res
}
func flattenMigrateStorageInfo(d *schema.ResourceData, info *compute.RecordMigrateStorageInfo) {
d.Set("completed", info.Completed)
d.Set("cpu_set", info.CPUSet)
d.Set("daemon_addr", info.DaemonAddr)
d.Set("domain_name", info.DomainName)
d.Set("domain_uuid", info.DomainUUID)
d.Set("elapsed_time", info.ElapsedTime)
d.Set("gid", info.GID)
d.Set("guid", info.GUID)
d.Set("migration_id", info.ID)
d.Set("interfaces", flattenShadowComputeInterfaces(info.Interfaces))
d.Set("log", info.Log)
d.Set("new_disk_xmls", info.NewDiskXmls)
d.Set("new_disks", info.NewDisks)
d.Set("old_disks", info.OldDisks)
d.Set("pid", info.PID)
d.Set("source_node_id", info.SourceNodeID)
d.Set("source_numa_node_id", info.SourceNumaNodeID)
d.Set("source_reserved_node_cpus", info.SourceReservedNodeCpus)
d.Set("source_url", info.SourceURL)
d.Set("status", info.Status)
d.Set("target_shadow_compute", flattenShadowCompute(info.TargetShadowCompute))
d.Set("target_node_id", info.TargetNodeID)
d.Set("target_url", info.TargetURL)
d.Set("vmlog_dir", info.VMLogDir)
}
func flattenShadowCompute(sc compute.ShadowCompute) []map[string]interface{} {
customFields, _ := json.Marshal(sc.CustomFields)
devices, _ := json.Marshal(sc.Devices)
userData, _ := json.Marshal(sc.Userdata)
return []map[string]interface{}{
{
"account_id": sc.AccountID,
"acl": flattenListACLInterface(sc.ACL),
"affinity_label": sc.AffinityLabel,
"affinity_rules": flattenShadowComputeRules(sc.AffinityRules),
"affinity_weight": sc.AffinityWeight,
"anti_affinity_rules": flattenShadowComputeRules(sc.AntiAffinityRules),
"arch": sc.Arch,
"auto_start": sc.AutoStart,
"boot_image_id": sc.BootImageID,
"boot_order": sc.BootOrder,
"boot_type": sc.BootType,
"bootdisk_size": sc.BootDiskSize,
"cd_image_id": sc.CDImageID,
"chipset": sc.Chipset,
"clock": sc.Clock,
"clone_reference": sc.CloneReference,
"clones": sc.Clones,
"computeci_id": sc.ComputeCIID,
"cpu_alignment_profile": flattenCPUAlignmentProfile(sc.CPUAlignmentProfile),
"cpupin": sc.CPUPin,
"cpus": sc.CPUs,
"custom_fields": string(customFields),
"desc": sc.Description,
"devices": string(devices),
"disks": flattenShadowComputeDisks(sc.Disks),
"driver": sc.Driver,
"gid": sc.GID,
"guid": sc.GUID,
"hp_backed": sc.HPBacked,
"hot_resize": sc.HotResize,
"id": sc.ID,
"interfaces": flattenShadowComputeInterfaces(sc.Interfaces),
"live_migration_job_id": sc.LiveMigrationJobID,
"loader_type": sc.LoaderType,
"lock_status": sc.LockStatus,
"manager_id": sc.ManagerID,
"manager_type": sc.ManagerType,
"migrationjob": sc.MigrationJob,
"milestones": sc.Milestones,
"name": sc.Name,
"need_reboot": sc.NeedReboot,
"network_interface_naming": sc.NetworkInterfaceNaming,
"node_id": sc.NodeID,
"numa_affinity": sc.NumaAffinity,
"numa_node_id": sc.NumaNodeID,
"os_users": flattenOSUsers(sc.OSUsers),
"os_version": sc.OSVersion,
"pinned_to_node": sc.PinnedToNode,
"preferred_cpu": sc.PreferredCPU,
"qemu_guest": flattenQemuQuest(sc.QemuGuest),
"read_only": sc.ReadOnly,
"ram": sc.RAM,
"reference_id": sc.ReferenceID,
"reserved_node_cpus": sc.ReservedNodeCpus,
"resized_online": sc.ResizedOnline,
"res_name": sc.ResName,
"rg_id": sc.RGID,
"snap_sets": flattenShadowComputeSnapshots(sc.SnapSets),
"stateless_sep_id": sc.StatelessSEPID,
"stateless_sep_type": sc.StatelessSEPType,
"status": sc.Status,
"tags": flattenTags(sc.Tags),
"tech_status": sc.TechStatus,
"user_managed": sc.UserManaged,
"userdata": string(userData),
"vgpus": sc.VGPUs,
"vnc_passwd": sc.VNCPassword,
"weight": sc.Weight,
"zone_id": sc.ZoneID,
},
}
}
func flattenShadowComputeDisks(disks []compute.ItemShadowComputeDisk) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(disks))
for _, disk := range disks {
res = append(res, map[string]interface{}{
"id": disk.ID,
})
}
return res
}
func flattenShadowComputeInterfaces(ifaces []compute.ItemShadowComputeInterface) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(ifaces))
for _, iface := range ifaces {
res = append(res, map[string]interface{}{
"name": iface.Name,
"target": iface.Target,
"pci_slot": iface.PCISlot,
"bus_number": iface.BusNumber,
"mac": iface.MAC,
"mtu": iface.MTU,
"type": iface.Type,
"conn_type": iface.ConnType,
"conn_id": iface.ConnID,
"flip_group_id": iface.FLIPGroupID,
"net_type": iface.NetType,
"net_id": iface.NetID,
"ip_address": iface.IPAddress,
"net_mask": iface.NetMask,
"def_gw": iface.DefGW,
"vnfs": iface.VNFs,
"qos": flattenQOS(iface.QOS),
"libvirt_settings": flattenLibvirtSettings(iface.LibvirtSettings),
"guid": iface.GUID,
"listen_ssh": iface.ListenSSH,
"enabled": iface.Enabled,
"enable_default_gateway": iface.EnableDefaultGateway,
"node_id": iface.NodeID,
"sdn_interface_id": iface.SDNInterfaceID,
"security_groups": iface.SecGroups,
"enable_secgroups": iface.EnableSecGroups,
"trunk_tags": iface.TrunkTags,
})
}
return res
}
// no guid
func flattenShadowComputeRules(rules compute.ListShadowComputeRules) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(rules))
for _, rule := range rules {
res = append(res, map[string]interface{}{
"key": rule.Key,
"mode": rule.Mode,
"policy": rule.Policy,
"topology": rule.Topology,
"value": rule.Value,
})
}
return res
}
// no compute/memory_dump_image
func flattenShadowComputeSnapshots(snaps compute.ListShadowComputeSnapshots) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(snaps))
for _, snap := range snaps {
res = append(res, map[string]interface{}{
"disks": snap.Disks,
"guid": snap.GUID,
"label": snap.Label,
"timestamp": snap.Timestamp,
})
}
return res
}

View File

@@ -1058,3 +1058,20 @@ func resourceComputeResourceV1() *schema.Resource {
},
}
}
func resourceComputeResourceV2() *schema.Resource {
s := resourceComputeSchemaMake()
// Add blk_discard
s["disks"].Elem.(*schema.Resource).Schema["blk_discard"] = &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Default: false,
}
// Add boot_disk_blk_discard
s["boot_disk_blk_discard"] = &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Default: false,
}
return &schema.Resource{Schema: s}
}

View File

@@ -89,12 +89,10 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
createReqX86.ZoneID = uint64(zoneID.(int))
}
if bootDiskBLKDiscard, ok := d.GetOk("boot_disk_blk_discard"); ok {
createReqX86.BootDiskBLKDiscard = bootDiskBLKDiscard.(bool)
if bootDiskDiscard, ok := d.GetOk("boot_disk_discard"); ok {
createReqX86.BootDiskDiscard = bootDiskDiscard.(string)
}
createReqX86.Interfaces = make([]kvmx86.Interface, 0)
if networks, ok := d.GetOk("network"); ok {
if networks.(*schema.Set).Len() > 0 {
ns := networks.(*schema.Set).List()
@@ -122,6 +120,10 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
reqInterface.Enabled = netInterfaceVal["enabled"].(bool)
}
if reqInterface.NetType == "VINS" {
reqInterface.EnableDefaultGateway = netInterfaceVal["enable_default_gateway"].(bool)
}
if reqInterface.NetType == "DPDK" || reqInterface.NetType == "EXTNET" || reqInterface.NetType == "TRUNK" {
reqInterface.MTU = uint64(netInterfaceVal["mtu"].(int))
}
@@ -179,8 +181,8 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
if cache, ok := diskVal["cache"]; ok {
reqDataDisk.Cache = cache.(string)
}
if blkDiscard, ok := diskVal["blk_discard"]; ok {
reqDataDisk.BLKDiscard = blkDiscard.(bool)
if discard, ok := diskVal["discard"]; ok {
reqDataDisk.Discard = discard.(string)
}
disksX86 = append(disksX86, reqDataDisk)
}
@@ -227,6 +229,9 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
createReqX86.CPUPin = d.Get("cpu_pin").(bool)
createReqX86.HPBacked = d.Get("hp_backed").(bool)
createReqX86.Chipset = d.Get("chipset").(string)
if clock, ok := d.GetOk("clock"); ok {
createReqX86.Clock = clock.(string)
}
if preferredCPU, ok := d.GetOk("preferred_cpu"); ok {
preferredList := preferredCPU.([]interface{})
@@ -527,6 +532,17 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
}
}
if profileName, ok := d.GetOk("cpu_alignment_profile"); ok {
req := compute.SetCPUAlignmentProfileRequest{
ComputeIDs: []int64{int64(computeId)},
CPUAlignmentProfile: profileName.(string),
}
_, err := c.CloudBroker().Compute().SetCPUAlignmentProfile(ctx, req)
if err != nil {
warnings.Add(err)
}
}
if ars, ok := d.GetOk("affinity_rules"); ok {
log.Debugf("resourceComputeCreate: Create affinity rules on ComputeID: %d", computeId)
addedAR := ars.([]interface{})
@@ -872,8 +888,8 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
}
}
if d.HasChange("boot_disk_blk_discard") {
if err := utilityComputeUpdateBootDiskBLKDiscard(ctx, d, m); err != nil {
if d.HasChange("boot_disk_discard") {
if err := utilityComputeUpdateBootDiskDiscard(ctx, d, m); err != nil {
return diag.FromErr(err)
}
}
@@ -893,6 +909,7 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
if d.HasChanges("description",
"name",
"clock",
"numa_affinity",
"cpu_pin",
"hp_backed",
@@ -1026,6 +1043,12 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
}
}
if d.HasChange("cpu_alignment_profile") {
if err := utilityComputeUpdateCPUAlignmentProfile(ctx, d, m); err != nil {
return diag.FromErr(err)
}
}
return append(resourceComputeRead(ctx, d, m), warnings.Get()...)
}
@@ -1057,7 +1080,7 @@ func resourceComputeDelete(ctx context.Context, d *schema.ResourceData, m interf
func ResourceCompute() *schema.Resource {
return &schema.Resource{
SchemaVersion: 2,
SchemaVersion: 3,
CustomizeDiff: func(ctx context.Context, diff *schema.ResourceDiff, i interface{}) error {
if diff.HasChanges() || diff.HasChanges("chipset", "pin_to_node", "auto_start_w_node", "libvirt_settings", "network", "affinity_rules", "anti_affinity_rules",
@@ -1100,6 +1123,11 @@ func ResourceCompute() *schema.Resource {
Upgrade: resourceCompueteStateUpgradeV1,
Version: 1,
},
{
Type: resourceComputeResourceV2().CoreConfigSchema().ImpliedType(),
Upgrade: resourceComputeStateUpgradeV2,
Version: 2,
},
},
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -18,3 +18,33 @@ func resourceCompueteStateUpgradeV1(ctx context.Context, rawState map[string]int
return rawState, nil
}
func resourceComputeStateUpgradeV2(ctx context.Context, rawState map[string]interface{}, meta any) (map[string]interface{}, error) {
log.Debug("resourceComputeStateUpgradeV2: upgrading state")
if v, ok := rawState["boot_disk_blk_discard"].(bool); ok {
if v {
rawState["boot_disk_discard"] = "unmap"
} else {
rawState["boot_disk_discard"] = "ignore"
}
}
delete(rawState, "boot_disk_blk_discard")
if disks, ok := rawState["disks"].([]interface{}); ok {
for _, d := range disks {
if disk, ok := d.(map[string]interface{}); ok {
if v, ok := disk["blk_discard"].(bool); ok {
if v {
disk["discard"] = "unmap"
} else {
disk["discard"] = "ignore"
}
}
delete(disk, "blk_discard")
}
}
}
return rawState, nil
}

View File

@@ -265,7 +265,7 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
renamedDisks := make([]interface{}, 0)
changeStoragePolicyDisks := make([]interface{}, 0)
cacheUpdatedDisks := make([]interface{}, 0)
blkDiscardUpdatedDisks := make([]interface{}, 0)
discardUpdatedDisks := make([]interface{}, 0)
blockSizeUpdatedDisks := make([]interface{}, 0)
iotuneUpdatedDisks := make([]interface{}, 0)
migratedDisks := make([]interface{}, 0)
@@ -325,8 +325,8 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
cacheUpdatedDisks = append(cacheUpdatedDisks, el)
}
if isChangeBLKDiscardDisk(oldConv, el) {
blkDiscardUpdatedDisks = append(blkDiscardUpdatedDisks, el)
if isChangeDiscardDisk(oldConv, el) {
discardUpdatedDisks = append(discardUpdatedDisks, el)
}
if isChangeBlockSizeDisk(oldConv, el) {
@@ -382,6 +382,9 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
if cacheVal, ok := diskConv["cache"].(string); ok {
req.Cache = cacheVal
}
if readOnly, ok := diskConv["read_only"].(bool); ok {
req.ReadOnly = readOnly
}
diskID, err := c.CloudBroker().Compute().DiskAdd(ctx, req)
if err != nil {
return err
@@ -515,8 +518,8 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
}
}
if len(blkDiscardUpdatedDisks) > 0 {
for _, disk := range blkDiscardUpdatedDisks {
if len(discardUpdatedDisks) > 0 {
for _, disk := range discardUpdatedDisks {
diskConv := disk.(map[string]interface{})
if isBootDisk(diskConv, chipset) {
continue
@@ -528,8 +531,8 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
}
req := disks.UpdateRequest{
DiskID: diskID,
BLKDiscard: diskConv["blk_discard"].(bool),
DiskID: diskID,
Discard: diskConv["discard"].(string),
}
_, err := c.CloudBroker().Disks().Update(ctx, req)
if err != nil {
@@ -672,10 +675,10 @@ func utilityComputeUpdateBootDiskCache(ctx context.Context, d *schema.ResourceDa
return err
}
func utilityComputeUpdateBootDiskBLKDiscard(ctx context.Context, d *schema.ResourceData, m interface{}) error {
func utilityComputeUpdateBootDiskDiscard(ctx context.Context, d *schema.ResourceData, m interface{}) error {
c := m.(*controller.ControllerCfg)
newBLKDiscard := d.Get("boot_disk_blk_discard").(bool)
newDiscard := d.Get("boot_disk_discard").(string)
var bootDiskID uint64
if v, ok := d.GetOk("boot_disk_id"); ok {
@@ -685,12 +688,12 @@ func utilityComputeUpdateBootDiskBLKDiscard(ctx context.Context, d *schema.Resou
}
if bootDiskID == 0 {
return fmt.Errorf("cannot update boot_disk_cache: boot disk ID is unknown for compute %s", d.Id())
return fmt.Errorf("cannot update boot_disk_discard: boot disk ID is unknown for compute %s", d.Id())
}
req := disks.UpdateRequest{
DiskID: bootDiskID,
BLKDiscard: newBLKDiscard,
DiskID: bootDiskID,
Discard: newDiscard,
}
_, err := c.CloudBroker().Disks().Update(ctx, req)
@@ -980,6 +983,10 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
req.SDNInterfaceID = netData["sdn_interface_id"].(string)
}
if req.NetType == "VINS" {
req.EnableDefaultGateway = netData["enable_default_gateway"].(bool)
}
_, err := c.CloudBroker().Compute().NetAttach(ctx, req)
if err != nil {
log.Errorf("utilityComputeNetworksConfigure: failed to attach net ID %d of type %s to Compute ID %s: %s",
@@ -1304,6 +1311,9 @@ func utilityComputeUpdate(ctx context.Context, d *schema.ResourceData, m interfa
if d.HasChange("chipset") {
req.Chipset = d.Get("chipset").(string)
}
if d.HasChange("clock") {
req.Clock = d.Get("clock").(string)
}
if d.HasChange("loader_type") {
req.LoaderType = d.Get("loader_type").(string)
@@ -1349,10 +1359,10 @@ 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.
// Note bene: numa_affinity, cpu_pin, hp_backed and clock 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", "hot_resize") && d.Get("started").(bool) {
if d.HasChanges("numa_affinity", "cpu_pin", "hp_backed", "chipset", "preferred_cpu", "hot_resize", "clock") && d.Get("started").(bool) {
isStopRequired = true
}
if isStopRequired {
@@ -2308,12 +2318,12 @@ func isChangeCacheDisk(els []interface{}, el interface{}) bool {
return false
}
func isChangeBLKDiscardDisk(els []interface{}, el interface{}) bool {
func isChangeDiscardDisk(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["blk_discard"].(bool) != elConv["blk_discard"].(bool) {
elOldConv["discard"].(string) != elConv["discard"].(string) {
return true
}
}

View File

@@ -0,0 +1,71 @@
/*
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package kvmvm
import (
"context"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityComputeUpdateCPUAlignmentProfile(ctx context.Context, d *schema.ResourceData, m interface{}) error {
c := m.(*controller.ControllerCfg)
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
profileName := d.Get("cpu_alignment_profile").(string)
if profileName == "" {
req := compute.DeleteCPUAlignmentProfileRequest{
ComputeIDs: []uint64{computeId},
}
_, err := c.CloudBroker().Compute().DeleteCPUAlignmentProfile(ctx, req)
return err
}
req := compute.SetCPUAlignmentProfileRequest{
ComputeIDs: []int64{int64(computeId)},
CPUAlignmentProfile: profileName,
}
_, err := c.CloudBroker().Compute().SetCPUAlignmentProfile(ctx, req)
return err
}
func utilityComputeGetCPUAlignmentProfile(ctx context.Context, d *schema.ResourceData, m interface{}) (*compute.CPUAlignmentProfile, error) {
c := m.(*controller.ControllerCfg)
req := compute.GetCPUAlignmentProfileRequest{
ComputeID: uint64(d.Get("compute_id").(int)),
}
return c.CloudBroker().Compute().GetCPUAlignmentProfile(ctx, req)
}

View File

@@ -40,16 +40,11 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityComputeMigrateStorageInfoCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) {
func utilityComputeMigrateStorageInfoCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*compute.RecordMigrateStorageInfo, error) {
c := m.(*controller.ControllerCfg)
req := compute.MigrateStorageInfoRequest{
ComputeID: uint64(d.Get("compute_id").(int)),
}
result, err := c.CloudBroker().Compute().MigrateStorageInfo(ctx, req)
if err != nil {
return "", err
}
return result, nil
return c.CloudBroker().Compute().MigrateStorageInfo(ctx, req)
}