This commit is contained in:
asteam
2024-12-04 13:18:58 +03:00
parent 003e4d656e
commit 76ea459b3d
417 changed files with 30051 additions and 975 deletions

View File

@@ -11,6 +11,7 @@ import (
"github.com/hashicorp/terraform-plugin-log/tflog"
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/compute"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/kvmvm/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/kvmvm/utilities"
)
@@ -26,6 +27,8 @@ func DataSourceCompute(ctx context.Context, state *models.RecordComputeModel, c
return diags
}
pciDevicesList, err := utilities.ComputePCIDevicesListCheckPresence(ctx, state, c)
id := uuid.New()
customFields, _ := json.Marshal(computeRecord.CustomFields)
@@ -44,6 +47,7 @@ func DataSourceCompute(ctx context.Context, state *models.RecordComputeModel, c
AffinityWeight: types.Int64Value(int64(computeRecord.AffinityWeight)),
AntiAffinityRules: flattenAffinityRule(ctx, &computeRecord.AntiAffinityRules),
Architecture: types.StringValue(computeRecord.Architecture),
Chipset: types.StringValue(computeRecord.Chipset),
BootDiskSize: types.Int64Value(int64(computeRecord.BootDiskSize)),
CdImageId: types.Int64Value(int64(computeRecord.CdImageId)),
CloneReference: types.Int64Value(int64(computeRecord.CloneReference)),
@@ -81,6 +85,7 @@ func DataSourceCompute(ctx context.Context, state *models.RecordComputeModel, c
NumaNodeId: types.Int64Value(int64(computeRecord.NumaNodeId)),
OSUsers: flattenOSUsers(ctx, &computeRecord.OSUsers),
Pinned: types.BoolValue(computeRecord.Pinned),
PCIDevices: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, flattenPCI(ctx, pciDevicesList)),
RAM: types.Int64Value(int64(computeRecord.RAM)),
ReferenceID: types.StringValue(computeRecord.ReferenceID),
Registered: types.BoolValue(computeRecord.Registered),
@@ -189,6 +194,7 @@ func flattenDisks(ctx context.Context, disks *compute.ListComputeDisks) []models
ACL: types.StringValue(string(acl)),
AccountID: types.Int64Value(int64(item.AccountID)),
BootPartition: types.Int64Value(int64(item.BootPartition)),
BusNumber: types.Int64Value(int64(item.BusNumber)),
CreatedTime: types.Int64Value(int64(item.CreatedTime)),
DeletedTime: types.Int64Value(int64(item.CreatedTime)),
Description: types.StringValue(item.Description),
@@ -290,6 +296,7 @@ func flattenInterfaces(ctx context.Context, interfaces *compute.ListInterfaces)
res := make([]models.ItemInterfaceModel, 0, len(*interfaces))
for _, item := range *interfaces {
temp := models.ItemInterfaceModel{
BusNumber: types.Int64Value(int64(item.BusNumber)),
ConnID: types.Int64Value(int64(item.ConnID)),
ConnType: types.StringValue(item.ConnType),
DefGW: types.StringValue(item.DefGW),
@@ -297,14 +304,24 @@ func flattenInterfaces(ctx context.Context, interfaces *compute.ListInterfaces)
FLIPGroupID: types.Int64Value(int64(item.FLIPGroupID)),
GUID: types.StringValue(item.GUID),
IPAddress: types.StringValue(item.IPAddress),
ListenSSH: types.BoolValue(item.ListenSSH),
MAC: types.StringValue(item.MAC),
Name: types.StringValue(item.Name),
NetID: types.Int64Value(int64(item.NetID)),
NetMask: types.Int64Value(int64(item.NetMask)),
NetType: types.StringValue(item.NetType),
NodeID: types.Int64Value(int64(item.NodeID)),
PCISlot: types.Int64Value(item.PCISlot),
LibvirtSettings: &models.LibvirtModel{
GUID: types.StringValue(item.LibvirtSettings.GUID),
TXMode: types.StringValue(item.LibvirtSettings.TXMode),
IOEventFD: types.StringValue(item.LibvirtSettings.IOEventFD),
EventIDx: types.StringValue(item.LibvirtSettings.EventIDx),
Queues: types.Int64Value(int64(item.LibvirtSettings.Queues)),
RXQueueSize: types.Int64Value(int64(item.LibvirtSettings.RXQueueSize)),
TXQueueSize: types.Int64Value(int64(item.LibvirtSettings.TXQueueSize)),
},
ListenSSH: types.BoolValue(item.ListenSSH),
MAC: types.StringValue(item.MAC),
MTU: types.Int64Value(int64(item.MTU)),
Name: types.StringValue(item.Name),
NetID: types.Int64Value(int64(item.NetID)),
NetMask: types.Int64Value(int64(item.NetMask)),
NetType: types.StringValue(item.NetType),
NodeID: types.Int64Value(int64(item.NodeID)),
PCISlot: types.Int64Value(item.PCISlot),
QOS: &models.QOSModel{
ERate: types.Int64Value(int64(item.QOS.ERate)),
GUID: types.StringValue(item.QOS.GUID),
@@ -365,3 +382,15 @@ func flattenOSUsers(ctx context.Context, osUsers *compute.ListOSUser) []models.I
tflog.Info(ctx, "End flattenOSUsers")
return res
}
func flattenPCI(ctx context.Context, pciList *compute.ListPCIDevices) []uint64 {
tflog.Info(ctx, "Start flattenPCI")
res := make([]uint64, 0, len(pciList.Data))
for _, v := range pciList.Data {
res = append(res, v.ID)
}
tflog.Info(ctx, "End flattenPCI")
return res
}

View File

@@ -75,6 +75,7 @@ func flattenItemsList(ctx context.Context, computes *compute.ListComputes) []mod
BootDiskSize: types.Int64Value(int64(item.BootDiskSize)),
CdImageId: types.Int64Value(int64(item.CdImageId)),
CloneReference: types.Int64Value(int64(item.CloneReference)),
Chipset: types.StringValue(item.Chipset),
ComputeCIID: types.Int64Value(int64(item.ComputeCIID)),
CPU: types.Int64Value(int64(item.CPU)),
CPUPin: types.BoolValue(item.CPUPin),
@@ -195,8 +196,9 @@ func flattenDisksInList(ctx context.Context, disks *compute.ListInfoDisks) []mod
res := make([]models.DiskInListModel, 0, len(*disks))
for _, item := range *disks {
temp := models.DiskInListModel{
DiskId: types.Int64Value(int64(item.ID)),
PCISlot: types.Int64Value(item.PCISlot),
BusNumber: types.Int64Value(int64(item.BusNumber)),
DiskId: types.Int64Value(int64(item.ID)),
PCISlot: types.Int64Value(item.PCISlot),
}
res = append(res, temp)
}
@@ -213,6 +215,7 @@ func flattenInterfaceInList(ctx context.Context, interfaces *compute.ListInterfa
res := make([]models.ItemVNFInterfaceInListModel, 0, len(*interfaces))
for _, item := range *interfaces {
temp := models.ItemVNFInterfaceInListModel{
BusNumber: types.Int64Value(int64(item.BusNumber)),
ConnID: types.Int64Value(int64(item.ConnID)),
ConnType: types.StringValue(item.ConnType),
DefGW: types.StringValue(item.DefGW),
@@ -220,14 +223,23 @@ func flattenInterfaceInList(ctx context.Context, interfaces *compute.ListInterfa
FLIPGroupID: types.Int64Value(int64(item.FLIPGroupID)),
GUID: types.StringValue(item.GUID),
IPAddress: types.StringValue(item.IPAddress),
ListenSSH: types.BoolValue(item.ListenSSH),
MAC: types.StringValue(item.MAC),
Name: types.StringValue(item.Name),
NetID: types.Int64Value(int64(item.NetID)),
NetMask: types.Int64Value(int64(item.NetMask)),
NetType: types.StringValue(item.NetType),
NodeID: types.Int64Value(int64(item.NodeID)),
PCISlot: types.Int64Value(item.PCISlot),
LibvirtSettings: &models.LibvirtModel{
GUID: types.StringValue(item.LibvirtSettings.GUID),
TXMode: types.StringValue(item.LibvirtSettings.TXMode),
IOEventFD: types.StringValue(item.LibvirtSettings.IOEventFD),
EventIDx: types.StringValue(item.LibvirtSettings.EventIDx),
Queues: types.Int64Value(int64(item.LibvirtSettings.Queues)),
RXQueueSize: types.Int64Value(int64(item.LibvirtSettings.RXQueueSize)),
TXQueueSize: types.Int64Value(int64(item.LibvirtSettings.TXQueueSize)),
},
ListenSSH: types.BoolValue(item.ListenSSH),
MAC: types.StringValue(item.MAC),
Name: types.StringValue(item.Name),
NetID: types.Int64Value(int64(item.NetID)),
NetMask: types.Int64Value(int64(item.NetMask)),
NetType: types.StringValue(item.NetType),
NodeID: types.Int64Value(int64(item.NodeID)),
PCISlot: types.Int64Value(item.PCISlot),
QOS: &models.QOSInListModel{
ERate: types.Int64Value(int64(item.QOS.ERate)),
GUID: types.StringValue(item.QOS.GUID),

View File

@@ -72,6 +72,7 @@ func flattenItemsListDeleted(ctx context.Context, computes *compute.ListComputes
Architecture: types.StringValue(item.Architecture),
BootDiskSize: types.Int64Value(int64(item.BootDiskSize)),
CdImageId: types.Int64Value(int64(item.CdImageId)),
Chipset: types.StringValue(item.Chipset),
CloneReference: types.Int64Value(int64(item.CloneReference)),
ComputeCIID: types.Int64Value(int64(item.ComputeCIID)),
CPU: types.Int64Value(int64(item.CPU)),
@@ -193,8 +194,9 @@ func flattenDisksInListDeleted(ctx context.Context, disks *compute.ListInfoDisks
res := make([]models.DiskInListDeletedModel, 0, len(*disks))
for _, item := range *disks {
temp := models.DiskInListDeletedModel{
DiskId: types.Int64Value(int64(item.ID)),
PCISlot: types.Int64Value(item.PCISlot),
BusNumber: types.Int64Value(int64(item.BusNumber)),
DiskId: types.Int64Value(int64(item.ID)),
PCISlot: types.Int64Value(item.PCISlot),
}
res = append(res, temp)
}
@@ -211,6 +213,7 @@ func flattenInterfaceInListDeleted(ctx context.Context, interfaces *compute.List
res := make([]models.ItemVNFInterfaceInListDeletedModel, 0, len(*interfaces))
for _, item := range *interfaces {
temp := models.ItemVNFInterfaceInListDeletedModel{
BusNumber: types.Int64Value(int64(item.BusNumber)),
ConnID: types.Int64Value(int64(item.ConnID)),
ConnType: types.StringValue(item.ConnType),
DefGW: types.StringValue(item.DefGW),
@@ -218,14 +221,23 @@ func flattenInterfaceInListDeleted(ctx context.Context, interfaces *compute.List
FLIPGroupID: types.Int64Value(int64(item.FLIPGroupID)),
GUID: types.StringValue(item.GUID),
IPAddress: types.StringValue(item.IPAddress),
ListenSSH: types.BoolValue(item.ListenSSH),
MAC: types.StringValue(item.MAC),
Name: types.StringValue(item.Name),
NetID: types.Int64Value(int64(item.NetID)),
NetMask: types.Int64Value(int64(item.NetMask)),
NetType: types.StringValue(item.NetType),
NodeID: types.Int64Value(int64(item.NodeID)),
PCISlot: types.Int64Value(item.PCISlot),
LibvirtSettings: &models.LibvirtModel{
GUID: types.StringValue(item.LibvirtSettings.GUID),
TXMode: types.StringValue(item.LibvirtSettings.TXMode),
IOEventFD: types.StringValue(item.LibvirtSettings.IOEventFD),
EventIDx: types.StringValue(item.LibvirtSettings.EventIDx),
Queues: types.Int64Value(int64(item.LibvirtSettings.Queues)),
RXQueueSize: types.Int64Value(int64(item.LibvirtSettings.RXQueueSize)),
TXQueueSize: types.Int64Value(int64(item.LibvirtSettings.TXQueueSize)),
},
ListenSSH: types.BoolValue(item.ListenSSH),
MAC: types.StringValue(item.MAC),
Name: types.StringValue(item.Name),
NetID: types.Int64Value(int64(item.NetID)),
NetMask: types.Int64Value(int64(item.NetMask)),
NetType: types.StringValue(item.NetType),
NodeID: types.Int64Value(int64(item.NodeID)),
PCISlot: types.Int64Value(item.PCISlot),
QOS: &models.QOSInListModel{
ERate: types.Int64Value(int64(item.QOS.ERate)),
GUID: types.StringValue(item.QOS.GUID),

View File

@@ -49,15 +49,17 @@ func ComputeResource(ctx context.Context, plan *models.ResourceComputeModel, c *
AffinityRules: plan.AffinityRules,
AntiAffinityRules: plan.AntiAffinityRules,
CustomFields: types.StringValue(string(customFields)),
Chipset: types.StringValue(recordItemCompute.Chipset),
Stateless: plan.Stateless,
SepId: types.Int64Value(int64(bootdisk.SepID)),
Pool: types.StringValue(bootdisk.Pool),
ExtraDisks: plan.ExtraDisks,
Network: flattenNetwork(ctx, &recordItemCompute.Interfaces),
Network: flattenNetwork(ctx, plan.Network, &recordItemCompute.Interfaces),
Tags: plan.Tags,
PortForwarding: plan.PortForwarding,
UserAccess: plan.UserAccess,
Snapshot: plan.Snapshot,
PCIDevices: plan.PCIDevices,
Rollback: plan.Rollback,
CD: plan.CD,
PinToStack: plan.PinToStack,
@@ -205,6 +207,7 @@ func flattenDisk(ctx context.Context, disk *compute.ItemComputeDisk) types.Objec
ACL: types.StringValue(string(acl)),
AccountID: types.Int64Value(int64(disk.AccountID)),
BootPartition: types.Int64Value(int64(disk.BootPartition)),
BusNumber: types.Int64Value(int64(disk.BusNumber)),
CreatedTime: types.Int64Value(int64(disk.CreatedTime)),
DeletedTime: types.Int64Value(int64(disk.DeletedTime)),
Description: types.StringValue(disk.Description),
@@ -385,25 +388,28 @@ func flattenResourceInterfaces(ctx context.Context, interfaces *compute.ListInte
for _, item := range *interfaces {
temp := models.ItemResourceInterfacesModel{
ConnID: types.Int64Value(int64(item.ConnID)),
ConnType: types.StringValue(item.ConnType),
GetGW: types.StringValue(item.DefGW),
Enabled: types.BoolValue(item.Enabled),
FLIPGroupID: types.Int64Value(int64(item.FLIPGroupID)),
GUID: types.StringValue(item.GUID),
IPAddress: types.StringValue(item.IPAddress),
ListenSSH: types.BoolValue(item.ListenSSH),
MAC: types.StringValue(item.MAC),
Name: types.StringValue(item.Name),
NetID: types.Int64Value(int64(item.NetID)),
NetMask: types.Int64Value(int64(item.NetMask)),
NetType: types.StringValue(item.NetType),
NodeID: types.Int64Value(int64(item.NodeID)),
PCISlot: types.Int64Value(item.PCISlot),
QOS: flattenQOS(ctx, &item.QOS),
Target: types.StringValue(item.Target),
Type: types.StringValue(item.Type),
VNFs: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, item.VNFs),
BusNumber: types.Int64Value(int64(item.BusNumber)),
ConnID: types.Int64Value(int64(item.ConnID)),
ConnType: types.StringValue(item.ConnType),
GetGW: types.StringValue(item.DefGW),
Enabled: types.BoolValue(item.Enabled),
FLIPGroupID: types.Int64Value(int64(item.FLIPGroupID)),
GUID: types.StringValue(item.GUID),
IPAddress: types.StringValue(item.IPAddress),
ListenSSH: types.BoolValue(item.ListenSSH),
MAC: types.StringValue(item.MAC),
MTU: types.Int64Value(int64(item.MTU)),
Name: types.StringValue(item.Name),
NetID: types.Int64Value(int64(item.NetID)),
NetMask: types.Int64Value(int64(item.NetMask)),
NetType: types.StringValue(item.NetType),
NodeID: types.Int64Value(int64(item.NodeID)),
PCISlot: types.Int64Value(item.PCISlot),
QOS: flattenQOS(ctx, &item.QOS),
LibvirtSettings: flattenLibvirtSetttings(ctx, &item.LibvirtSettings),
Target: types.StringValue(item.Target),
Type: types.StringValue(item.Type),
VNFs: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, item.VNFs),
}
obj, err := types.ObjectValueFrom(ctx, models.ItemInterfaces, temp)
if err != nil {
@@ -439,6 +445,27 @@ func flattenQOS(ctx context.Context, QOS *compute.QOS) types.Object {
return res
}
func flattenLibvirtSetttings(ctx context.Context, settings *compute.LibvirtSettings) types.Object {
tflog.Info(ctx, "Start flattenLibvirtSetttings")
temp := models.LibvirtModel{
GUID: types.StringValue(settings.GUID),
TXMode: types.StringValue(settings.TXMode),
IOEventFD: types.StringValue(settings.IOEventFD),
EventIDx: types.StringValue(settings.EventIDx),
Queues: types.Int64Value(int64(settings.Queues)),
RXQueueSize: types.Int64Value(int64(settings.RXQueueSize)),
TXQueueSize: types.Int64Value(int64(settings.TXQueueSize)),
}
res, err := types.ObjectValueFrom(ctx, models.ItemLibvirtSettings, temp)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenLibvirtSetttings struct to obj", err))
}
tflog.Info(ctx, "End flattenLibvirtSetttings")
return res
}
func flattenSnapSets(ctx context.Context, snapSets *compute.ListSnapSets) types.List {
tflog.Info(ctx, "Start flattenSnapSets")
tempSlice := make([]types.Object, 0, len(*snapSets))
@@ -465,7 +492,7 @@ func flattenSnapSets(ctx context.Context, snapSets *compute.ListSnapSets) types.
return res
}
func flattenNetwork(ctx context.Context, interfaces *compute.ListInterfaces) types.Set {
func flattenNetwork(ctx context.Context, networks types.Set, interfaces *compute.ListInterfaces) types.Set {
tflog.Info(ctx, "Start flattenNetwork")
tempSlice := make([]types.Object, 0, len(*interfaces))
@@ -476,6 +503,8 @@ func flattenNetwork(ctx context.Context, interfaces *compute.ListInterfaces) typ
NetId: types.Int64Value(int64(item.NetID)),
IpAddress: types.StringValue(item.IPAddress),
Mac: types.StringValue(item.MAC),
Weight: flattenNetworkWeight(ctx, networks, item),
MTU: types.Int64Value(int64(item.MTU)),
}
obj, err := types.ObjectValueFrom(ctx, models.ItemNetwork, temp)
if err != nil {
@@ -492,3 +521,16 @@ func flattenNetwork(ctx context.Context, interfaces *compute.ListInterfaces) typ
tflog.Info(ctx, "End flattenNetwork")
return res
}
func flattenNetworkWeight(ctx context.Context, networks types.Set, item compute.ItemVNFInterface) types.Int64 {
tflog.Info(ctx, "Start flattenNetworkWeight")
networkList := networks.Elements()
for _, network := range networkList {
networkMap := network.(types.Object).Attributes()
if uint64(networkMap["net_id"].(types.Int64).ValueInt64()) == item.NetID && networkMap["net_type"].(types.String).ValueString() == item.NetType {
return types.Int64Value(networkMap["weight"].(types.Int64).ValueInt64())
}
}
tflog.Info(ctx, "End flattenNetworkWeight")
return types.Int64Value(0)
}