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

@@ -220,8 +220,12 @@ func computeSnapshotsSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"pool_name": {
Type: schema.TypeString,
Computed: true,
},
"reference_id": {
Type: schema.TypeInt,
Type: schema.TypeString,
Computed: true,
},
"res_id": {
@@ -244,20 +248,44 @@ func computeSnapshotsSchemaMake() map[string]*schema.Schema {
}
func computeListDisksSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"_ckey": {
/*"_ckey": {
Type: schema.TypeString,
Computed: true,
},
"acl": {
Type: schema.TypeString,
},*/
/*"acl": {
Type: schema.TypeList,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"user_group_id": {
Type: schema.TypeString,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
"right": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"explicit": {
Type: schema.TypeBool,
Computed: true,
},
},
},
Computed: true,
},
},*/
"account_id": {
Type: schema.TypeInt,
Computed: true,
},
"blk_discard": {
Type: schema.TypeBool,
"discard": {
Type: schema.TypeString,
Computed: true,
},
"block_size": {
@@ -316,10 +344,11 @@ func computeListDisksSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"image_name": {
// TODO
/*"image_name": {
Type: schema.TypeString,
Computed: true,
},
},*/
"images": {
Type: schema.TypeList,
Computed: true,
@@ -489,6 +518,10 @@ func computeListDisksSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"read_only": {
Type: schema.TypeBool,
Computed: true,
},
}
}
@@ -539,6 +572,10 @@ func computeInterfacesSchemaMake() map[string]*schema.Schema {
Type: schema.TypeBool,
Computed: true,
},
"enable_default_gateway": {
Type: schema.TypeBool,
Computed: true,
},
"flip_group_id": {
Type: schema.TypeInt,
Computed: true,
@@ -708,8 +745,13 @@ func computeSnapSetsSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"memory_dump_image": {
Type: schema.TypeInt,
Computed: true,
},
}
}
func dataSourceComputeSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"compute_id": {
@@ -766,6 +808,10 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"clock": {
Type: schema.TypeString,
Computed: true,
},
"boot_order": {
Type: schema.TypeList,
Computed: true,
@@ -789,6 +835,10 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"node_id": {
Type: schema.TypeInt,
Computed: true,
},
"pci_devices": {
Type: schema.TypeList,
Computed: true,
@@ -807,6 +857,26 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"cpu_alignment_profiles": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
},
"model": {
Type: schema.TypeString,
Computed: true,
},
"vendor": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"cpu_pin": {
Type: schema.TypeBool,
Computed: true,
@@ -998,6 +1068,10 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeBool,
Computed: true,
},
"resized_online": {
Type: schema.TypeBool,
Computed: true,
},
"res_name": {
Type: schema.TypeString,
Computed: true,

View File

@@ -136,6 +136,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_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

@@ -83,6 +83,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_audit_list instead.",
ReadContext: dataSourceComputeGetAuditsRead,
Timeouts: &schema.ResourceTimeout{

View File

@@ -80,6 +80,10 @@ func computeDisksSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"read_only": {
Type: schema.TypeBool,
Computed: true,
},
}
}
func itemComputeSchemaMake() map[string]*schema.Schema {
@@ -156,6 +160,10 @@ func itemComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"clock": {
Type: schema.TypeString,
Computed: true,
},
"clones": {
Type: schema.TypeList,
Computed: true,
@@ -167,6 +175,26 @@ func itemComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"cpu_alignment_profiles": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
},
"model": {
Type: schema.TypeString,
Computed: true,
},
"vendor": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"cpu_pin": {
Type: schema.TypeBool,
Computed: true,
@@ -335,6 +363,10 @@ func itemComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeBool,
Computed: true,
},
"resized_online": {
Type: schema.TypeBool,
Computed: true,
},
"res_name": {
Type: schema.TypeString,
Computed: true,

View File

@@ -50,7 +50,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)
}
@@ -71,32 +72,33 @@ func flattenInterfaces(interfaces compute.ListInterfaces) []map[string]interface
res := make([]map[string]interface{}, 0, len(interfaces))
for _, interfaceItem := range interfaces {
temp := map[string]interface{}{
"bus_number": interfaceItem.BusNumber,
"conn_id": interfaceItem.ConnID,
"conn_type": interfaceItem.ConnType,
"def_gw": interfaceItem.DefGW,
"enabled": interfaceItem.Enabled,
"enable_secgroups": interfaceItem.EnableSecGroups,
"flip_group_id": interfaceItem.FLIPGroupID,
"guid": interfaceItem.GUID,
"ip_address": interfaceItem.IPAddress,
"listen_ssh": interfaceItem.ListenSSH,
"mac": interfaceItem.MAC,
"mtu": interfaceItem.MTU,
"name": interfaceItem.Name,
"net_id": interfaceItem.NetID,
"netmask": interfaceItem.NetMask,
"net_type": interfaceItem.NetType,
"node_id": interfaceItem.NodeID,
"pci_slot": interfaceItem.PCISlot,
"qos": flattenQOS(interfaceItem.QOS),
"security_groups": interfaceItem.SecGroups,
"sdn_interface_id": interfaceItem.SDNInterfaceID,
"target": interfaceItem.Target,
"type": interfaceItem.Type,
"trunk_tags": interfaceItem.TrunkTags,
"vnfs": interfaceItem.VNFs,
"libvirt_settings": flattenLibvirtSettings(interfaceItem.LibvirtSettings),
"bus_number": interfaceItem.BusNumber,
"conn_id": interfaceItem.ConnID,
"conn_type": interfaceItem.ConnType,
"def_gw": interfaceItem.DefGW,
"enabled": interfaceItem.Enabled,
"enable_secgroups": interfaceItem.EnableSecGroups,
"enable_default_gateway": interfaceItem.EnableDefaultGateway,
"flip_group_id": interfaceItem.FLIPGroupID,
"guid": interfaceItem.GUID,
"ip_address": interfaceItem.IPAddress,
"listen_ssh": interfaceItem.ListenSSH,
"mac": interfaceItem.MAC,
"mtu": interfaceItem.MTU,
"name": interfaceItem.Name,
"net_id": interfaceItem.NetID,
"netmask": interfaceItem.NetMask,
"net_type": interfaceItem.NetType,
"node_id": interfaceItem.NodeID,
"pci_slot": interfaceItem.PCISlot,
"qos": flattenQOS(interfaceItem.QOS),
"security_groups": interfaceItem.SecGroups,
"sdn_interface_id": interfaceItem.SDNInterfaceID,
"target": interfaceItem.Target,
"type": interfaceItem.Type,
"trunk_tags": interfaceItem.TrunkTags,
"vnfs": interfaceItem.VNFs,
"libvirt_settings": flattenLibvirtSettings(interfaceItem.LibvirtSettings),
}
res = append(res, temp)
}
@@ -122,10 +124,11 @@ func flattenSnapSets(snapSets compute.ListSnapSets) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(snapSets))
for _, snapSet := range snapSets {
temp := map[string]interface{}{
"disks": snapSet.Disks,
"guid": snapSet.GUID,
"label": snapSet.Label,
"timestamp": snapSet.Timestamp,
"disks": snapSet.Disks,
"guid": snapSet.GUID,
"label": snapSet.Label,
"timestamp": snapSet.Timestamp,
"memory_dump_image": snapSet.MemoryDumpImage,
}
res = append(res, temp)
}
@@ -193,10 +196,12 @@ func flattenComputeList(computes *compute.ListComputes) []map[string]interface{}
"bootdisk_size": compute.BootDiskSize,
"boot_image_id": compute.BootImageID,
"chipset": compute.Chipset,
"clock": compute.Clock,
"cd_image_id": compute.CdImageId,
"clone_reference": compute.CloneReference,
"clones": compute.Clones,
"computeci_id": compute.ComputeCIID,
"cpu_alignment_profiles": flattenCPUAlignmentProfile(compute.CPUAlignmentProfile),
"cpu_pin": compute.CPUPin,
"cpus": compute.CPU,
"created_by": compute.CreatedBy,
@@ -232,6 +237,7 @@ func flattenComputeList(computes *compute.ListComputes) []map[string]interface{}
"registered": compute.Registered,
"res_name": compute.ResName,
"reserved_node_cpus": compute.ReservedNodeCpus,
"resized_online": compute.ResizedOnline,
"rg_id": compute.RGID,
"rg_name": compute.RGName,
"snap_sets": flattenSnapSets(compute.SnapSets),
@@ -278,7 +284,7 @@ func flattenBootDisk(bootDisk *compute.ItemComputeDisk) []map[string]interface{}
"storage_policy_id": bootDisk.StoragePolicyID,
"to_clean": bootDisk.ToClean,
"cache": bootDisk.Cache,
"blk_discard": bootDisk.BLKDiscard,
"discard": bootDisk.Discard,
"block_size": bootDisk.BlockSize,
"bus_number": bootDisk.BusNumber,
"provision": bootDisk.Provision,
@@ -289,6 +295,7 @@ func flattenBootDisk(bootDisk *compute.ItemComputeDisk) []map[string]interface{}
"deleted_time": bootDisk.DeletedTime,
"updated_time": bootDisk.UpdatedTime,
"devicename": bootDisk.DeviceName,
"read_only": bootDisk.ReadOnly,
}
res = append(res, temp)
@@ -346,10 +353,11 @@ func flattenComputeDisksDemo(disksList compute.ListComputeDisks, disksBlocks, ex
"updated_time": disk.UpdatedTime,
"permanently": pernamentlyValue,
"cache": disk.Cache,
"blk_discard": disk.BLKDiscard,
"discard": disk.Discard,
"block_size": disk.BlockSize,
"provision": disk.Provision,
"iotune": flattenIotune(disk.IOTune),
"read_only": disk.ReadOnly,
}
res = append(res, temp)
indexDataDisks++
@@ -363,15 +371,16 @@ func flattenNetwork(networks []interface{}, interfaces compute.ListInterfaces) [
for _, network := range interfaces {
temp := map[string]interface{}{
"net_id": network.NetID,
"net_type": network.NetType,
"ip_address": network.IPAddress,
"mac": network.MAC,
"mtu": network.MTU,
"net_mask": network.NetMask,
"sdn_interface_id": network.SDNInterfaceID,
"weight": flattenNetworkWeight(networks, network.NetID, network.NetType),
"enabled": network.Enabled,
"net_id": network.NetID,
"net_type": network.NetType,
"ip_address": network.IPAddress,
"mac": network.MAC,
"mtu": network.MTU,
"net_mask": network.NetMask,
"sdn_interface_id": network.SDNInterfaceID,
"weight": flattenNetworkWeight(networks, network.NetID, network.NetType),
"enabled": network.Enabled,
"enable_default_gateway": network.EnableDefaultGateway,
}
res = append(res, temp)
}
@@ -440,6 +449,7 @@ func flattenCompute(d *schema.ResourceData, computeRec compute.RecordCompute, pc
d.Set("sep_id", bootDisk.SepID)
d.Set("pool", bootDisk.Pool)
d.Set("chipset", computeRec.Chipset)
d.Set("clock", computeRec.Clock)
d.Set("clone_reference", computeRec.CloneReference)
d.Set("clones", computeRec.Clones)
d.Set("computeci_id", computeRec.ComputeCIID)
@@ -484,6 +494,7 @@ func flattenCompute(d *schema.ResourceData, computeRec compute.RecordCompute, pc
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_id", computeRec.RGID)
d.Set("rg_name", computeRec.RGName)
d.Set("snap_sets", flattenSnapSets(computeRec.SnapSets))
@@ -505,6 +516,7 @@ func flattenCompute(d *schema.ResourceData, computeRec compute.RecordCompute, pc
d.Set("zone_id", computeRec.ZoneID)
d.Set("loader_meta_iso", flattenLoaderMetaIso(computeRec.LoaderMetaIso))
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)
@@ -565,6 +577,20 @@ func flattenAffinityRules(affinityRules compute.ListRules) []map[string]interfac
return res
}
/*func flattenDisksACL(acl compute.ItemDisksACL) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"user_group_id": acl.UserGroupID,
"type": acl.Type,
"right": acl.Right,
"status": acl.Status,
"explicit": acl.Explicit,
}
res = append(res, temp)
return res
}*/
func flattenIotune(iotune compute.IOTune) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
@@ -593,6 +619,7 @@ func flattenSnapshots(snapshots compute.SnapshotExtendList) []map[string]interfa
temp := map[string]interface{}{
"guid": snapshot.GUID,
"label": snapshot.Label,
"pool_name": snapshot.PoolName,
"res_id": snapshot.ResID,
"reference_id": snapshot.ReferenceID,
"snap_set_guid": snapshot.SnapSetGUID,
@@ -607,13 +634,14 @@ func flattenSnapshots(snapshots compute.SnapshotExtendList) []map[string]interfa
func flattenListComputeDisks(disks compute.ListComputeDisks) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(disks))
log.Debug("flattenListComputeDisks:", disks)
for _, disk := range disks {
acl, _ := json.Marshal(disk.ACL)
temp := map[string]interface{}{
"_ckey": disk.CKey,
"acl": string(acl),
//"_ckey": disk.CKey,
// TODO
//"acl": flattenDisksACL(disk.ACL),
"account_id": disk.AccountID,
"blk_discard": disk.BLKDiscard,
"discard": disk.Discard,
"block_size": disk.BlockSize,
"boot_partition": disk.BootPartition,
"bus_number": disk.BusNumber,
@@ -660,6 +688,7 @@ func flattenListComputeDisks(disks compute.ListComputeDisks) []map[string]interf
"to_clean": disk.ToClean,
"provision": disk.Provision,
"updated_time": disk.UpdatedTime,
"read_only": disk.ReadOnly,
}
res = append(res, temp)
}
@@ -713,6 +742,7 @@ func flattenDataCompute(d *schema.ResourceData, computeRec compute.RecordCompute
d.Set("auto_start_w_node", computeRec.AutoStart)
d.Set("arch", computeRec.Architecture)
d.Set("chipset", computeRec.Chipset)
d.Set("clock", computeRec.Clock)
d.Set("boot_order", computeRec.BootOrder)
d.Set("bootdisk_size", computeRec.BootDiskSize)
d.Set("boot_image_id", computeRec.BootImageID)
@@ -729,7 +759,10 @@ func flattenDataCompute(d *schema.ResourceData, computeRec compute.RecordCompute
d.Set("deleted_time", computeRec.DeletedTime)
d.Set("desc", computeRec.Description)
d.Set("devices", string(devices))
d.Set("disks", flattenListComputeDisks(computeRec.Disks))
err := d.Set("disks", flattenListComputeDisks(computeRec.Disks))
if err != nil {
log.Debugf("error in flattenDataCompute: %v", err)
}
d.Set("driver", computeRec.Driver)
d.Set("gid", computeRec.GID)
d.Set("guid", computeRec.GUID)
@@ -762,6 +795,7 @@ func flattenDataCompute(d *schema.ResourceData, computeRec compute.RecordCompute
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_id", computeRec.RGID)
d.Set("rg_name", computeRec.RGName)
d.Set("snap_sets", flattenSnapSets(computeRec.SnapSets))
@@ -785,9 +819,23 @@ func flattenDataCompute(d *schema.ResourceData, computeRec compute.RecordCompute
d.Set("zone_id", computeRec.ZoneID)
d.Set("loader_meta_iso", flattenLoaderMetaIso(computeRec.LoaderMetaIso))
d.Set("os_version", computeRec.OSVersion)
d.Set("cpu_alignment_profiles", flattenCPUAlignmentProfile(computeRec.CPUAlignmentProfile))
d.Set("weight", computeRec.Weight)
}
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))

View File

@@ -185,6 +185,13 @@ func networkSubresourceSchemaMake() map[string]*schema.Schema {
Description: "network enable flag",
},
"enable_default_gateway": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: "Flag indicating whether default gateway is enabled for this interface. Applicable only to VINS network type",
},
"net_mask": {
Type: schema.TypeInt,
Optional: true,

View File

@@ -1427,3 +1427,19 @@ func resourceComputeResourceV2() *schema.Resource {
},
}
}
func resourceComputeResourceV3() *schema.Resource {
s := ResourceComputeSchemaMake()
for _, blockKey := range []string{"disks", "boot_disk"} {
if block, ok := s[blockKey]; ok {
if res, ok := block.Elem.(*schema.Resource); ok {
res.Schema["blk_discard"] = &schema.Schema{
Type: schema.TypeBool,
Computed: true,
}
}
}
}
return &schema.Resource{Schema: s}
}

View File

@@ -135,8 +135,6 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
createReqX86.BootDisk = uint64(bootSize.(int))
}
createReqX86.Interfaces = make([]kvmx86.Interface, 0)
if networks, ok := d.GetOk("network"); ok {
if networks.(*schema.Set).Len() > 0 {
ns := networks.(*schema.Set).List()
@@ -164,6 +162,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))
}
@@ -264,6 +266,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{})
@@ -513,6 +518,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.CloudAPI().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{})
@@ -968,9 +984,9 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
}
}
// 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.
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
}
@@ -1042,6 +1058,7 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
if d.HasChanges("description",
"name",
"clock",
"numa_affinity",
"cpu_pin",
"hp_backed",
@@ -1069,6 +1086,9 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
if d.HasChange("chipset") {
req.Chipset = d.Get("chipset").(string)
}
if d.HasChange("clock") {
req.Clock = d.Get("clock").(string)
}
if d.HasChange("preferred_cpu") {
if preferredCPU, ok := d.GetOk("preferred_cpu"); ok {
preferredList := preferredCPU.([]interface{})
@@ -1242,6 +1262,7 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
if diskConv["image_id"].(int) != 0 {
req.ImageID = uint64(diskConv["image_id"].(int))
}
req.ReadOnly = diskConv["read_only"].(bool)
diskID, err := c.CloudAPI().Compute().DiskAdd(ctx, req)
if err != nil {
return diag.FromErr(err)
@@ -1911,6 +1932,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)
}
}
// we may reuse dataSourceComputeRead here as we maintain similarity
// between Compute resource and Compute data source schemas
@@ -2095,6 +2122,12 @@ func disksSubresourceSchemaMake() map[string]*schema.Schema {
Optional: true,
Description: "Disk deletion status",
},
"read_only": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "Mount disk in read-only mode",
},
"iotune": {
Type: schema.TypeList,
Optional: true,
@@ -2230,8 +2263,8 @@ func disksSubresourceSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"blk_discard": {
Type: schema.TypeBool,
"discard": {
Type: schema.TypeString,
Computed: true,
},
"block_size": {
@@ -2382,6 +2415,13 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema {
ValidateFunc: validation.StringInSlice([]string{"Q35", "i440fx"}, false), // observe case while validating
Description: "Type of the emulated system.",
},
"clock": {
Type: schema.TypeString,
Optional: true,
Default: "default",
ValidateFunc: validation.StringInSlice([]string{"default", "linux", "windows", "none"}, false),
Description: "Clock synchronization mode.",
},
"without_boot_disk": {
Type: schema.TypeBool,
Optional: true,
@@ -2405,6 +2445,11 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema {
Optional: true,
Description: "Set affinity label for compute",
},
"cpu_alignment_profile": {
Type: schema.TypeString,
Optional: true,
Description: "CPU alignment profile name",
},
"affinity_rules": {
Type: schema.TypeList,
Optional: true,
@@ -2931,6 +2976,10 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
},
},
"resized_online": {
Type: schema.TypeBool,
Computed: true,
},
"rg_name": {
Type: schema.TypeString,
Computed: true,
@@ -3095,7 +3144,7 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema {
func ResourceCompute() *schema.Resource {
return &schema.Resource{
SchemaVersion: 3,
SchemaVersion: 4,
CreateContext: resourceComputeCreate,
ReadContext: resourceComputeRead,
@@ -3142,6 +3191,11 @@ func ResourceCompute() *schema.Resource {
Upgrade: resourceComputeStateUpgradeV2,
Version: 2,
},
{
Type: resourceComputeResourceV3().CoreConfigSchema().ImpliedType(),
Upgrade: resourceComputeStateUpgradeV3,
Version: 3,
},
},
}
}

View File

@@ -34,8 +34,31 @@ func resourceCompueteStateUpgradeV1(ctx context.Context, rawState map[string]int
func resourceComputeStateUpgradeV2(ctx context.Context, rawState map[string]interface{}, meta any) (map[string]interface{}, error) {
log.Debug("resourceComputeStateUpgradeV2: upgrading state")
delete(rawState, "with_default_vins")
return rawState, nil
}
func resourceComputeStateUpgradeV3(ctx context.Context, rawState map[string]interface{}, meta any) (map[string]interface{}, error) {
log.Debug("resourceComputeStateUpgradeV3: upgrading state")
for _, blockKey := range []string{"disks", "boot_disk"} {
if items, ok := rawState[blockKey].([]interface{}); ok {
for _, item := range items {
if disk, ok := item.(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

@@ -278,6 +278,10 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
req.Enabled = netData["enabled"].(bool)
}
if req.NetType == "VINS" {
req.EnableDefaultGateway = netData["enable_default_gateway"].(bool)
}
if req.NetType == "DPDK" || req.NetType == "EXTNET" {
req.MTU = uint64(netData["mtu"].(int))
}

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/cloudapi/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.CloudAPI().Compute().DeleteCPUAlignmentProfile(ctx, req)
return err
}
req := compute.SetCPUAlignmentProfileRequest{
ComputeIDs: []int64{int64(computeId)},
CPUAlignmentProfile: profileName,
}
_, err := c.CloudAPI().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.CloudAPI().Compute().GetCPUAlignmentProfile(ctx, req)
}