This commit is contained in:
2025-02-07 11:59:43 +03:00
parent 60e23338ad
commit b8f118097e
177 changed files with 16418 additions and 214 deletions

View File

@@ -2,6 +2,7 @@ package flattens
import (
"context"
"fmt"
"strconv"
"github.com/hashicorp/terraform-plugin-framework/diag"
@@ -35,19 +36,25 @@ func NodeDataSource(ctx context.Context, state *models.DataSourceNode, c *client
Consumption: flattenConsumpion(ctx, &recordNode.Consumption),
CpuInfo: flattenCpuInfo(ctx, &recordNode.CpuInfo),
CPUAllocationRatio: types.Int64Value(int64(recordNode.CPUAllocationRatio)),
DPDK: flattenDPDK(ctx, &recordNode.DPDK),
GID: types.Int64Value(int64(recordNode.GID)),
ID: types.StringValue(strconv.Itoa(int(recordNode.ID))),
IPAddr: flattens.FlattenSimpleTypeToList(ctx, types.StringType, &recordNode.IPAddr),
IsolatedCPUs: flattens.FlattenSimpleTypeToList(ctx, types.StringType, &recordNode.IsolatedCpus),
IsolatedCPUs: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &recordNode.IsolatedCpus),
Name: types.StringValue(recordNode.Name),
NeedReboot: types.BoolValue(recordNode.NeedReboot),
NetworkMode: types.StringValue(recordNode.NetworkMode),
NicInfo: flattenNicInfo(ctx, recordNode.NicInfo),
NumaTopology: flattenNumaTopology(ctx, &recordNode.NumaTopology),
ReservedCPUs: flattens.FlattenSimpleTypeToList(ctx, types.StringType, &recordNode.ReservedCPUs),
ReservedCPUs: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &recordNode.ReservedCPUs),
Roles: flattens.FlattenSimpleTypeToList(ctx, types.StringType, &recordNode.Roles),
SriovEnabled: types.BoolValue(recordNode.SriovEnabled),
StackId: types.Int64Value(int64(recordNode.StackID)),
Status: types.StringValue(recordNode.Status),
ToActive: flattenRole(ctx, &recordNode.ToActive),
ToInstalling: flattenRole(ctx, &recordNode.ToInstalling),
ToMaintenance: flattenRole(ctx, &recordNode.ToMaintenance),
ToRestricted: flattenRole(ctx, &recordNode.ToRestricted),
Version: types.StringValue(recordNode.Version),
}
@@ -125,7 +132,7 @@ func flattenVFList(ctx context.Context, vfMap []interface{}) []models.VFList {
for _, item := range vfMap {
itemMap := item.(map[string]interface{})
vf := models.VFList{
FnID: types.Int64Value(itemMap["fnId"].(int64)),
FnID: types.Int64Value(int64(itemMap["fnId"].(float64))),
PCISlot: types.StringValue(itemMap["pciSlot"].(string)),
}
vfList = append(vfList, vf)
@@ -167,3 +174,37 @@ func flattenNumaTopologyNodes(ctx context.Context, nodes map[string]node.NodeInf
tflog.Info(ctx, "End flattenNumaTopologyNodes")
return res
}
func flattenDPDK(ctx context.Context, dpdk *node.DPDK) *models.DPDKModel {
tflog.Info(ctx, "Start flattenDPDK")
hpMemory, diags := types.MapValueFrom(ctx, types.Int64Type, dpdk.HPMemory)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenDPDK", diags))
}
res := models.DPDKModel{
Bridges: &models.Bridges{
Backplane1: &models.Backplane1{
Interfaces: flattens.FlattenSimpleTypeToList(ctx, types.StringType, &dpdk.Bridges.Backplane1.Interfaces),
NumaNode: types.Int64Value(int64(dpdk.Bridges.Backplane1.NumaNode)),
},
},
HPMemory: hpMemory,
PMDCPU: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &dpdk.PMDCPU),
}
tflog.Info(ctx, "End flattenDPDK")
return &res
}
func flattenRole(ctx context.Context, role *node.Role) *models.Role {
tflog.Info(ctx, "Start flattenRole")
res := models.Role{
Actor: types.StringValue(role.Actor),
Reason: types.StringValue(role.Reason),
Time: types.Int64Value(int64(role.Time)),
}
tflog.Info(ctx, "End flattenRole")
return &res
}

View File

@@ -57,44 +57,46 @@ func flattenItemsList(ctx context.Context, recordList *node.ListNodes) []models.
for _, item := range recordList.Data {
temp := models.ItemNodeModel{
AdditionalPkgs: flattens.FlattenSimpleTypeToList(ctx, types.StringType, &item.AdditionalPkgs),
CpuInfo: flattenCpuInfo(ctx, &item.CpuInfo),
Description: types.StringValue(item.Description),
GID: types.Int64Value(int64(item.GID)),
GUID: types.StringValue(item.GUID),
HostKey: types.StringValue(item.HostKey),
IPAddr: flattens.FlattenSimpleTypeToList(ctx, types.StringType, &item.IPAddr),
IsolatedCPUs: flattens.FlattenSimpleTypeToList(ctx, types.StringType, &item.IsolatedCpus),
LastCheck: types.Int64Value(int64(item.LastCheck)),
MachineGUID: types.StringValue(item.MachineGUID),
MainboardSN: types.StringValue(item.MainboardSN),
Memory: types.Int64Value(int64(item.Memory)),
Milestones: types.Int64Value(int64(item.Milestones)),
Model: types.StringValue(item.Model),
Name: types.StringValue(item.Name),
NeedReboot: types.BoolValue(item.NeedReboot),
NetAddr: flattenNetAddr(ctx, item.NetAddr),
NetworkMode: types.StringValue(item.NetworkMode),
NicInfo: flattenNicInfo(ctx, item.NicInfo),
NodeUUID: types.StringValue(item.NodeUUID),
NodeID: types.Int64Value(int64(item.ID)),
NumaTopology: flattenNumaTopology(ctx, &item.NumaTopology),
PeerBackup: types.Int64Value(int64(item.PeerBackup)),
PeerLog: types.Int64Value(int64(item.PeerLog)),
PeerStats: types.Int64Value(int64(item.PeerStats)),
Pgpus: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &item.Pgpus),
PublicKeys: flattens.FlattenSimpleTypeToList(ctx, types.StringType, &item.PublicKeys),
Release: types.StringValue(item.Release),
ReservedCPUs: flattens.FlattenSimpleTypeToList(ctx, types.StringType, &item.ReservedCPUs),
Roles: flattens.FlattenSimpleTypeToList(ctx, types.StringType, &item.Roles),
SEPs: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &item.Seps),
SerialNum: types.StringValue(item.SerialNum),
SriovEnabled: types.BoolValue(item.SriovEnabled),
StackId: types.Int64Value(int64(item.StackID)),
Status: types.StringValue(item.Status),
Tags: flattens.FlattenSimpleTypeToList(ctx, types.StringType, &item.Tags),
Type: types.StringValue(item.Type),
Version: types.StringValue(item.Version),
AdditionalPkgs: flattens.FlattenSimpleTypeToList(ctx, types.StringType, &item.AdditionalPkgs),
CpuInfo: flattenCpuInfo(ctx, &item.CpuInfo),
Description: types.StringValue(item.Description),
DPDK: flattenDPDK(ctx, &item.DPDK),
GID: types.Int64Value(int64(item.GID)),
GUID: types.StringValue(item.GUID),
HostKey: types.StringValue(item.HostKey),
IPAddr: flattens.FlattenSimpleTypeToList(ctx, types.StringType, &item.IPAddr),
IsolatedCPUs: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &item.IsolatedCpus),
LastCheck: types.Int64Value(int64(item.LastCheck)),
MachineGUID: types.StringValue(item.MachineGUID),
MainboardSN: types.StringValue(item.MainboardSN),
Memory: types.Int64Value(int64(item.Memory)),
Milestones: types.Int64Value(int64(item.Milestones)),
Model: types.StringValue(item.Model),
Name: types.StringValue(item.Name),
NeedReboot: types.BoolValue(item.NeedReboot),
NetAddr: flattenNetAddr(ctx, item.NetAddr),
NetworkMode: types.StringValue(item.NetworkMode),
NicInfo: flattenNicInfo(ctx, item.NicInfo),
NodeUUID: types.StringValue(item.NodeUUID),
NodeID: types.Int64Value(int64(item.ID)),
NumaTopology: flattenNumaTopology(ctx, &item.NumaTopology),
PeerBackup: types.Int64Value(int64(item.PeerBackup)),
PeerLog: types.Int64Value(int64(item.PeerLog)),
PeerStats: types.Int64Value(int64(item.PeerStats)),
Pgpus: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &item.Pgpus),
PublicKeys: flattens.FlattenSimpleTypeToList(ctx, types.StringType, &item.PublicKeys),
Release: types.StringValue(item.Release),
ReservedCPUs: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &item.ReservedCPUs),
Roles: flattens.FlattenSimpleTypeToList(ctx, types.StringType, &item.Roles),
SEPs: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &item.Seps),
SerialNum: types.StringValue(item.SerialNum),
SriovEnabled: types.BoolValue(item.SriovEnabled),
StackId: types.Int64Value(int64(item.StackID)),
Status: types.StringValue(item.Status),
Tags: flattens.FlattenSimpleTypeToList(ctx, types.StringType, &item.Tags),
Type: types.StringValue(item.Type),
UEFIFirmwareFile: types.StringValue(item.UEFIFirmwareFile),
Version: types.StringValue(item.Version),
}
res = append(res, temp)
}