1.0.1
This commit is contained in:
91
internal/service/cloudbroker/node/data_source_cb_node.go
Normal file
91
internal/service/cloudbroker/node/data_source_cb_node.go
Normal file
@@ -0,0 +1,91 @@
|
||||
package node
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/client"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/node/flattens"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/node/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/node/schemas"
|
||||
)
|
||||
|
||||
// Ensure the implementation satisfies the expected interfaces.
|
||||
var (
|
||||
_ datasource.DataSource = &dataSourceNode{}
|
||||
)
|
||||
|
||||
func NewDataSourceNode() datasource.DataSource {
|
||||
return &dataSourceNode{}
|
||||
}
|
||||
|
||||
// dataSourceNode is the data source implementation.
|
||||
type dataSourceNode struct {
|
||||
client *decort.DecortClient
|
||||
}
|
||||
|
||||
func (d *dataSourceNode) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
||||
// Read Terraform configuration data into the model
|
||||
var state models.DataSourceNode
|
||||
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceNode: Error get state")
|
||||
return
|
||||
}
|
||||
nodeID := uint64(state.NodeID.ValueInt64())
|
||||
tflog.Info(ctx, "Read dataSourceNode: got state successfully", map[string]any{"node_id": nodeID})
|
||||
|
||||
// Set timeouts
|
||||
readTimeout, diags := state.Timeouts.Read(ctx, constants.Timeout180s)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceNode: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read dataSourceNode: set timeouts successfully", map[string]any{
|
||||
"node_id": nodeID,
|
||||
"readTimeout": readTimeout})
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, readTimeout)
|
||||
defer cancel()
|
||||
|
||||
// Map response body to schema
|
||||
resp.Diagnostics.Append(flattens.NodeDataSource(ctx, &state, d.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceNode: Error flatten")
|
||||
return
|
||||
}
|
||||
|
||||
// Set refreshed state
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceNode: Error set state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "End read dataSourceNode", map[string]any{"node_id": nodeID})
|
||||
}
|
||||
|
||||
func (d *dataSourceNode) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
Attributes: schemas.MakeSchemaDataSourceNode(),
|
||||
Blocks: map[string]schema.Block{
|
||||
"timeouts": timeouts.Block(ctx),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (d *dataSourceNode) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_cb_node"
|
||||
}
|
||||
|
||||
// Configure adds the provider configured client to the data source.
|
||||
func (d *dataSourceNode) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
|
||||
tflog.Info(ctx, "Get Configure dataSourceNode")
|
||||
d.client = client.DataSource(ctx, &req, resp)
|
||||
tflog.Info(ctx, "Getting Configure dataSourceNode successfully")
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package node
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/client"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/node/flattens"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/node/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/node/schemas"
|
||||
)
|
||||
|
||||
// Ensure the implementation satisfies the expected interfaces.
|
||||
var (
|
||||
_ datasource.DataSource = &dataSourceNodeList{}
|
||||
)
|
||||
|
||||
func NewDataSourceNodeList() datasource.DataSource {
|
||||
return &dataSourceNodeList{}
|
||||
}
|
||||
|
||||
// dataSourceNodeList is the data source implementation.
|
||||
type dataSourceNodeList struct {
|
||||
client *decort.DecortClient
|
||||
}
|
||||
|
||||
func (d *dataSourceNodeList) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
||||
// Read Terraform configuration data into the model
|
||||
var state models.DataSourceNodeList
|
||||
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceNodeList: Error get state")
|
||||
return
|
||||
}
|
||||
|
||||
// Set timeouts
|
||||
readTimeout, diags := state.Timeouts.Read(ctx, constants.Timeout180s)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceNodeList: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read dataSourceNodeList: set timeouts successfully")
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, readTimeout)
|
||||
defer cancel()
|
||||
|
||||
// Map response body to schema
|
||||
resp.Diagnostics.Append(flattens.NodeListDataSource(ctx, &state, d.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceNodeList: Error flatten")
|
||||
return
|
||||
}
|
||||
|
||||
// Set refreshed state
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceNodeList: Error set state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "End read dataSourceNodeList")
|
||||
}
|
||||
|
||||
func (d *dataSourceNodeList) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
Attributes: schemas.MakeSchemaDataSourceNodeList(),
|
||||
Blocks: map[string]schema.Block{
|
||||
"timeouts": timeouts.Block(ctx),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (d *dataSourceNodeList) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_cb_node_list"
|
||||
}
|
||||
|
||||
// Configure adds the provider configured client to the data source.
|
||||
func (d *dataSourceNodeList) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
|
||||
tflog.Info(ctx, "Get Configure dataSourceNodeList")
|
||||
d.client = client.DataSource(ctx, &req, resp)
|
||||
tflog.Info(ctx, "Getting Configure dataSourceNodeList successfully")
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/node"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/flattens"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/node/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/node/utilities"
|
||||
)
|
||||
|
||||
func NodeDataSource(ctx context.Context, state *models.DataSourceNode, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.NodeDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
nodeID := uint64(state.NodeID.ValueInt64())
|
||||
|
||||
recordNode, diags := utilities.NodeDataSourceCheckPresence(ctx, nodeID, c)
|
||||
if diags.HasError() {
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.NodeDataSource: before flatten", map[string]any{"node_id": nodeID})
|
||||
|
||||
*state = models.DataSourceNode{
|
||||
NodeID: state.NodeID,
|
||||
Timeouts: state.Timeouts,
|
||||
|
||||
Consumption: flattenConsumpion(ctx, &recordNode.Consumption),
|
||||
CpuInfo: flattenCpuInfo(ctx, &recordNode.CpuInfo),
|
||||
CPUAllocationRatio: types.Int64Value(int64(recordNode.CPUAllocationRatio)),
|
||||
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),
|
||||
Name: types.StringValue(recordNode.Name),
|
||||
NeedReboot: types.BoolValue(recordNode.NeedReboot),
|
||||
NicInfo: flattenNicInfo(ctx, recordNode.NicInfo),
|
||||
NumaTopology: flattenNumaTopology(ctx, &recordNode.NumaTopology),
|
||||
ReservedCPUs: flattens.FlattenSimpleTypeToList(ctx, types.StringType, &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),
|
||||
Version: types.StringValue(recordNode.Version),
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattens.NodeDataSource", map[string]any{"Node_id": state.NodeID.ValueInt64()})
|
||||
return nil
|
||||
}
|
||||
|
||||
func flattenConsumpion(ctx context.Context, consumpion *node.ConsumptionInfo) *models.ConsumptionModel {
|
||||
tflog.Info(ctx, "Start flattenConsumpion")
|
||||
|
||||
res := models.ConsumptionModel{
|
||||
Consumed: &models.ConsumedModel{
|
||||
RAM: types.Int64Value(int64(consumpion.Consumed.RAM)),
|
||||
Computes: types.Int64Value(int64(consumpion.Consumed.Computes)),
|
||||
Routers: types.Int64Value(int64(consumpion.Consumed.Routers)),
|
||||
VCPU: types.Int64Value(int64(consumpion.Consumed.VCPU)),
|
||||
},
|
||||
Free: &models.ResourcesInfo{
|
||||
RAM: types.Int64Value(int64(consumpion.Free.RAM)),
|
||||
},
|
||||
Reserved: &models.ResourcesInfo{
|
||||
RAM: types.Int64Value(int64(consumpion.Reserved.RAM)),
|
||||
},
|
||||
Total: &models.ResourcesInfo{
|
||||
RAM: types.Int64Value(int64(consumpion.Total.RAM)),
|
||||
},
|
||||
Hostname: types.StringValue(consumpion.Hostname),
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattenConsumpion")
|
||||
return &res
|
||||
}
|
||||
|
||||
func flattenCpuInfo(ctx context.Context, cpuInfo *node.CpuInfo) *models.CpuInfoModel {
|
||||
tflog.Info(ctx, "Start flattenCpuInfo")
|
||||
|
||||
res := models.CpuInfoModel{
|
||||
ClockSpeed: types.Int64Value(int64(cpuInfo.ClockSpeed)),
|
||||
CoreCount: types.Int64Value(int64(cpuInfo.CoreCount)),
|
||||
PhysCount: types.Int64Value(int64(cpuInfo.PhysCount)),
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattenCpuInfo")
|
||||
return &res
|
||||
}
|
||||
|
||||
func flattenNicInfo(ctx context.Context, nicInfo []node.ItemNicInfo) []models.NicInfoModel {
|
||||
tflog.Info(ctx, "Start flattenNicInfo")
|
||||
|
||||
res := make([]models.NicInfoModel, 0, len(nicInfo))
|
||||
|
||||
for _, item := range nicInfo {
|
||||
temp := models.NicInfoModel{
|
||||
Driver: types.StringValue(item.Driver),
|
||||
MaxVFS: types.Int64Value(int64(item.MaxVFS)),
|
||||
NumaNode: types.Int64Value(int64(item.NumaNode)),
|
||||
NumVFS: types.Int64Value(int64(item.NumVFS)),
|
||||
OSName: types.StringValue(item.OSName),
|
||||
PCISlot: types.StringValue(item.PCISlot),
|
||||
VFList: flattenVFList(ctx, item.VFList),
|
||||
}
|
||||
|
||||
res = append(res, temp)
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattenNicInfo")
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenVFList(ctx context.Context, vfMap []interface{}) []models.VFList {
|
||||
tflog.Info(ctx, "Start flattenVFList")
|
||||
|
||||
vfList := make([]models.VFList, 0, len(vfMap))
|
||||
|
||||
for _, item := range vfMap {
|
||||
itemMap := item.(map[string]interface{})
|
||||
vf := models.VFList{
|
||||
FnID: types.Int64Value(itemMap["fnId"].(int64)),
|
||||
PCISlot: types.StringValue(itemMap["pciSlot"].(string)),
|
||||
}
|
||||
vfList = append(vfList, vf)
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattenVFList")
|
||||
return vfList
|
||||
}
|
||||
|
||||
func flattenNumaTopology(ctx context.Context, numaTopolpgy *node.NumaTopologyInfo) *models.NumaTopologyModel {
|
||||
tflog.Info(ctx, "Start flattenNumaTopology")
|
||||
|
||||
res := models.NumaTopologyModel{
|
||||
NodeNum: types.Int64Value(int64(numaTopolpgy.NodeNum)),
|
||||
Nodes: flattenNumaTopologyNodes(ctx, numaTopolpgy.Nodes),
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattenNumaTopology")
|
||||
return &res
|
||||
}
|
||||
|
||||
func flattenNumaTopologyNodes(ctx context.Context, nodes map[string]node.NodeInfo) []models.NumaTopologyNodes {
|
||||
tflog.Info(ctx, "Start flattenNumaTopologyNodes")
|
||||
|
||||
res := make([]models.NumaTopologyNodes, 0, len(nodes))
|
||||
|
||||
for _, item := range nodes {
|
||||
temp := models.NumaTopologyNodes{
|
||||
CPUList: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &item.CPUList),
|
||||
Memory: &models.NumaTopologyNodesMemory{
|
||||
OneG: types.Int64Value(int64(item.Memory.OneG)),
|
||||
TwoM: types.Int64Value(int64(item.Memory.TwoM)),
|
||||
Total: types.Int64Value(int64(item.Memory.Total)),
|
||||
},
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattenNumaTopologyNodes")
|
||||
return res
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/node"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/flattens"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/node/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/node/utilities"
|
||||
)
|
||||
|
||||
func NodeListDataSource(ctx context.Context, state *models.DataSourceNodeList, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.NodeDataListSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
recordList, diags := utilities.NodeListDataSourceCheckPresence(ctx, state, c)
|
||||
if diags.HasError() {
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.NodeListDataSource: before flatten")
|
||||
|
||||
id := uuid.New()
|
||||
|
||||
*state = models.DataSourceNodeList{
|
||||
ByID: state.ByID,
|
||||
Name: state.Name,
|
||||
Version: state.Version,
|
||||
Release: state.Release,
|
||||
SepID: state.SepID,
|
||||
Role: state.Role,
|
||||
Status: state.Status,
|
||||
SortBy: state.SortBy,
|
||||
Page: state.Page,
|
||||
Size: state.Size,
|
||||
Timeouts: state.Timeouts,
|
||||
|
||||
Id: types.StringValue(id.String()),
|
||||
Items: flattenItemsList(ctx, recordList),
|
||||
EntryCount: types.Int64Value(int64(recordList.EntryCount)),
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattens.NodeListDataSource")
|
||||
return nil
|
||||
}
|
||||
|
||||
func flattenItemsList(ctx context.Context, recordList *node.ListNodes) []models.ItemNodeModel {
|
||||
tflog.Info(ctx, "Start flattenItemsList")
|
||||
|
||||
res := make([]models.ItemNodeModel, 0, len(recordList.Data))
|
||||
|
||||
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),
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattenItemsList")
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenNetAddr(ctx context.Context, netAddr node.ListNetAddr) []models.NetAddrModel {
|
||||
tflog.Info(ctx, "Start flattenNetAddr")
|
||||
|
||||
res := make([]models.NetAddrModel, 0, len(netAddr))
|
||||
|
||||
for _, item := range netAddr {
|
||||
temp := models.NetAddrModel{
|
||||
CIDR: flattens.FlattenSimpleTypeToList(ctx, types.StringType, &item.CIDR),
|
||||
Index: types.Int64Value(int64(item.Index)),
|
||||
IP: flattens.FlattenSimpleTypeToList(ctx, types.StringType, &item.IP),
|
||||
MAC: types.StringValue(item.Mac),
|
||||
MTU: types.Int64Value(int64(item.MTU)),
|
||||
Name: types.StringValue(item.Name),
|
||||
}
|
||||
|
||||
res = append(res, temp)
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattenNetAddr")
|
||||
return res
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
type DataSourceNode struct {
|
||||
//required field
|
||||
NodeID types.Int64 `tfsdk:"node_id"`
|
||||
Timeouts timeouts.Value `tfsdk:"timeouts"`
|
||||
|
||||
//response field
|
||||
Consumption *ConsumptionModel `tfsdk:"consumption"`
|
||||
CpuInfo *CpuInfoModel `tfsdk:"cpu_info"`
|
||||
CPUAllocationRatio types.Int64 `tfsdk:"cpu_allocation_ratio"`
|
||||
GID types.Int64 `tfsdk:"gid"`
|
||||
ID types.String `tfsdk:"id"`
|
||||
IPAddr types.List `tfsdk:"ipaddr"`
|
||||
IsolatedCPUs types.List `tfsdk:"isolated_cpus"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
NeedReboot types.Bool `tfsdk:"need_reboot"`
|
||||
NicInfo []NicInfoModel `tfsdk:"nic_info"`
|
||||
NumaTopology *NumaTopologyModel `tfsdk:"numa_topology"`
|
||||
ReservedCPUs types.List `tfsdk:"reserved_cpus"`
|
||||
Roles types.List `tfsdk:"roles"`
|
||||
SriovEnabled types.Bool `tfsdk:"sriov_enabled"`
|
||||
StackId types.Int64 `tfsdk:"stack_id"`
|
||||
Status types.String `tfsdk:"status"`
|
||||
Version types.String `tfsdk:"version"`
|
||||
}
|
||||
|
||||
type ConsumptionModel struct {
|
||||
Consumed *ConsumedModel `tfsdk:"consumed"`
|
||||
Free *ResourcesInfo `tfsdk:"free"`
|
||||
Reserved *ResourcesInfo `tfsdk:"reserved"`
|
||||
Total *ResourcesInfo `tfsdk:"total"`
|
||||
Hostname types.String `tfsdk:"hostname"`
|
||||
}
|
||||
|
||||
type ConsumedModel struct {
|
||||
RAM types.Int64 `tfsdk:"ram"`
|
||||
Computes types.Int64 `tfsdk:"computes"`
|
||||
Routers types.Int64 `tfsdk:"routers"`
|
||||
VCPU types.Int64 `tfsdk:"vcpu"`
|
||||
}
|
||||
|
||||
type ResourcesInfo struct {
|
||||
RAM types.Int64 `tfsdk:"ram"`
|
||||
}
|
||||
|
||||
type CpuInfoModel struct {
|
||||
ClockSpeed types.Int64 `tfsdk:"clock_speed"`
|
||||
CoreCount types.Int64 `tfsdk:"core_count"`
|
||||
PhysCount types.Int64 `tfsdk:"phys_count"`
|
||||
}
|
||||
|
||||
type NicInfoModel struct {
|
||||
Driver types.String `tfsdk:"driver"`
|
||||
MaxVFS types.Int64 `tfsdk:"max_vfs"`
|
||||
NumaNode types.Int64 `tfsdk:"numa_node"`
|
||||
NumVFS types.Int64 `tfsdk:"num_vfs"`
|
||||
OSName types.String `tfsdk:"os_name"`
|
||||
PCISlot types.String `tfsdk:"pci_slot"`
|
||||
VFList []VFList `tfsdk:"vf_list"`
|
||||
}
|
||||
|
||||
type VFList struct {
|
||||
FnID types.Int64 `tfsdk:"fn_id"`
|
||||
PCISlot types.String `tfsdk:"pci_slot"`
|
||||
}
|
||||
|
||||
type NumaTopologyModel struct {
|
||||
NodeNum types.Int64 `tfsdk:"node_num"`
|
||||
Nodes []NumaTopologyNodes `tfsdk:"nodes"`
|
||||
}
|
||||
|
||||
type NumaTopologyNodes struct {
|
||||
CPUList types.List `tfsdk:"cpu_list"`
|
||||
Memory *NumaTopologyNodesMemory `tfsdk:"memory"`
|
||||
}
|
||||
|
||||
type NumaTopologyNodesMemory struct {
|
||||
OneG types.Int64 `tfsdk:"one_g"`
|
||||
TwoM types.Int64 `tfsdk:"two_m"`
|
||||
Total types.Int64 `tfsdk:"total"`
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
type DataSourceNodeList struct {
|
||||
// request fields
|
||||
ByID types.Int64 `tfsdk:"by_id"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
Version types.String `tfsdk:"version"`
|
||||
Release types.String `tfsdk:"release"`
|
||||
SepID types.Int64 `tfsdk:"sep_id"`
|
||||
Role types.String `tfsdk:"role"`
|
||||
Status types.String `tfsdk:"status"`
|
||||
SortBy types.String `tfsdk:"sort_by"`
|
||||
Page types.Int64 `tfsdk:"page"`
|
||||
Size types.Int64 `tfsdk:"size"`
|
||||
Timeouts timeouts.Value `tfsdk:"timeouts"`
|
||||
// response fields
|
||||
Id types.String `tfsdk:"id"`
|
||||
Items []ItemNodeModel `tfsdk:"items"`
|
||||
EntryCount types.Int64 `tfsdk:"entry_count"`
|
||||
}
|
||||
|
||||
type ItemNodeModel struct {
|
||||
AdditionalPkgs types.List `tfsdk:"additional_pkgs"`
|
||||
CpuInfo *CpuInfoModel `tfsdk:"cpu_info"`
|
||||
Description types.String `tfsdk:"description"`
|
||||
GID types.Int64 `tfsdk:"gid"`
|
||||
GUID types.String `tfsdk:"guid"`
|
||||
HostKey types.String `tfsdk:"hostkey"`
|
||||
IPAddr types.List `tfsdk:"ipaddr"`
|
||||
IsolatedCPUs types.List `tfsdk:"isolated_cpus"`
|
||||
LastCheck types.Int64 `tfsdk:"lastcheck"`
|
||||
MachineGUID types.String `tfsdk:"machine_guid"`
|
||||
MainboardSN types.String `tfsdk:"mainboard_sn"`
|
||||
Memory types.Int64 `tfsdk:"memory"`
|
||||
Milestones types.Int64 `tfsdk:"milestones"`
|
||||
Model types.String `tfsdk:"model"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
NeedReboot types.Bool `tfsdk:"need_reboot"`
|
||||
NetAddr []NetAddrModel `tfsdk:"net_addr"`
|
||||
NetworkMode types.String `tfsdk:"network_mode"`
|
||||
NicInfo []NicInfoModel `tfsdk:"nic_info"`
|
||||
NodeUUID types.String `tfsdk:"node_uuid"`
|
||||
NodeID types.Int64 `tfsdk:"node_id"`
|
||||
NumaTopology *NumaTopologyModel `tfsdk:"numa_topology"`
|
||||
PeerBackup types.Int64 `tfsdk:"peer_backup"`
|
||||
PeerLog types.Int64 `tfsdk:"peer_log"`
|
||||
PeerStats types.Int64 `tfsdk:"peer_stats"`
|
||||
Pgpus types.List `tfsdk:"pgpus"`
|
||||
PublicKeys types.List `tfsdk:"public_keys"`
|
||||
Release types.String `tfsdk:"release"`
|
||||
ReservedCPUs types.List `tfsdk:"reserved_cpus"`
|
||||
Roles types.List `tfsdk:"roles"`
|
||||
SEPs types.List `tfsdk:"seps"`
|
||||
SerialNum types.String `tfsdk:"serial_num"`
|
||||
SriovEnabled types.Bool `tfsdk:"sriov_enabled"`
|
||||
StackId types.Int64 `tfsdk:"stack_id"`
|
||||
Status types.String `tfsdk:"status"`
|
||||
Tags types.List `tfsdk:"tags"`
|
||||
Type types.String `tfsdk:"type"`
|
||||
Version types.String `tfsdk:"version"`
|
||||
}
|
||||
|
||||
type NetAddrModel struct {
|
||||
CIDR types.List `tfsdk:"cidr"`
|
||||
Index types.Int64 `tfsdk:"index"`
|
||||
IP types.List `tfsdk:"ip"`
|
||||
MAC types.String `tfsdk:"mac"`
|
||||
MTU types.Int64 `tfsdk:"mtu"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
package schemas
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
func MakeSchemaDataSourceNode() map[string]schema.Attribute {
|
||||
return map[string]schema.Attribute{
|
||||
"node_id": schema.Int64Attribute{
|
||||
Required: true,
|
||||
},
|
||||
"consumption": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"consumed": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"ram": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"computes": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"routers": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"vcpu": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
"free": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"ram": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
"reserved": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"ram": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
"total": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"ram": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
"hostname": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
"cpu_info": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"clock_speed": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"core_count": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"phys_count": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
"cpu_allocation_ratio": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"gid": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"id": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"ipaddr": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.StringType,
|
||||
},
|
||||
"isolated_cpus": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.StringType,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"need_reboot": schema.BoolAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"nic_info": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"driver": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"max_vfs": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"numa_node": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"num_vfs": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"os_name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"pci_slot": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"vf_list": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"fn_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"pci_slot": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"numa_topology": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"node_num": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"nodes": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"cpu_list": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.Int64Type,
|
||||
},
|
||||
"memory": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"one_g": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"two_m": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"total": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"reserved_cpus": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.StringType,
|
||||
},
|
||||
"roles": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.StringType,
|
||||
},
|
||||
"sriov_enabled": schema.BoolAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"stack_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"status": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"version": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,287 @@
|
||||
package schemas
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
func MakeSchemaDataSourceNodeList() map[string]schema.Attribute {
|
||||
return map[string]schema.Attribute{
|
||||
"by_id": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Description: "find node by id",
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Description: "find node by name",
|
||||
},
|
||||
"version": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Description: "find node by version",
|
||||
},
|
||||
"release": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Description: "find node by release version",
|
||||
},
|
||||
"sep_id": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Description: "find node by sepID",
|
||||
},
|
||||
"role": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Description: "find node by node roles",
|
||||
},
|
||||
"status": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Description: "find node by node status",
|
||||
},
|
||||
"sort_by": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Description: "sort by one of supported fields, format +|-(field)",
|
||||
},
|
||||
"page": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Description: "page number",
|
||||
},
|
||||
"size": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Description: "page size, maximum - 100",
|
||||
},
|
||||
"id": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"items": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"additional_pkgs": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.StringType,
|
||||
},
|
||||
"cpu_info": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"clock_speed": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"core_count": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"phys_count": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
"description": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"gid": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"hostkey": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"node_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"ipaddr": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.StringType,
|
||||
},
|
||||
"isolated_cpus": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.StringType,
|
||||
},
|
||||
"lastcheck": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"machine_guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"mainboard_sn": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"memory": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"milestones": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"model": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"need_reboot": schema.BoolAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"net_addr": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"cidr": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.StringType,
|
||||
},
|
||||
"index": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"ip": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.StringType,
|
||||
},
|
||||
"mac": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"mtu": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"network_mode": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"nic_info": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"driver": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"max_vfs": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"numa_node": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"num_vfs": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"os_name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"pci_slot": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"vf_list": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"fn_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"pci_slot": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"node_uuid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"numa_topology": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"node_num": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"nodes": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"cpu_list": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.Int64Type,
|
||||
},
|
||||
"memory": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"one_g": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"two_m": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"total": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"peer_backup": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"peer_log": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"peer_stats": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"pgpus": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.Int64Type,
|
||||
},
|
||||
"public_keys": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.StringType,
|
||||
},
|
||||
"release": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"reserved_cpus": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.StringType,
|
||||
},
|
||||
"roles": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.StringType,
|
||||
},
|
||||
"seps": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.Int64Type,
|
||||
},
|
||||
"serial_num": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"sriov_enabled": schema.BoolAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"stack_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"status": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"tags": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.StringType,
|
||||
},
|
||||
"type": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"version": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"entry_count": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package utilities
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/node"
|
||||
)
|
||||
|
||||
func NodeDataSourceCheckPresence(ctx context.Context, nodeId uint64, c *decort.DecortClient) (*node.RecordNode, diag.Diagnostics) {
|
||||
tflog.Info(ctx, fmt.Sprintf("NodeDataSourceCheckPresence: Get info about Node with ID - %v", nodeId))
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
recordNode, err := c.CloudBroker().Node().Get(ctx, node.GetRequest{NID: nodeId})
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot get info about Node with ID %v", nodeId), err.Error())
|
||||
return nil, diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "NodeDataSourceCheckPresence: response from loudBroker().Node().Get", map[string]any{"node_id": nodeId, "response": recordNode})
|
||||
|
||||
return recordNode, nil
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package utilities
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/node"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/node/models"
|
||||
)
|
||||
|
||||
func NodeListDataSourceCheckPresence(ctx context.Context, state *models.DataSourceNodeList, c *decort.DecortClient) (*node.ListNodes, diag.Diagnostics) {
|
||||
tflog.Info(ctx, "NodeListDataSourceCheckPresence: Get node list info")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
req := node.ListRequest{}
|
||||
|
||||
if !state.ByID.IsNull() {
|
||||
req.ByID = uint64(state.ByID.ValueInt64())
|
||||
}
|
||||
if !state.Name.IsNull() {
|
||||
req.Name = state.Name.ValueString()
|
||||
}
|
||||
if !state.Version.IsNull() {
|
||||
req.Version = state.Version.ValueString()
|
||||
}
|
||||
if !state.Release.IsNull() {
|
||||
req.Release = state.Release.ValueString()
|
||||
}
|
||||
if !state.SepID.IsNull() {
|
||||
req.SepID = uint64(state.SepID.ValueInt64())
|
||||
}
|
||||
if !state.Role.IsNull() {
|
||||
req.Role = state.Role.ValueString()
|
||||
}
|
||||
if !state.Status.IsNull() {
|
||||
req.Status = state.Status.ValueString()
|
||||
}
|
||||
if !state.SortBy.IsNull() {
|
||||
req.SortBy = state.SortBy.ValueString()
|
||||
}
|
||||
if !state.Page.IsNull() {
|
||||
req.Page = uint64(state.Page.ValueInt64())
|
||||
}
|
||||
if !state.Size.IsNull() {
|
||||
req.Size = uint64(state.Size.ValueInt64())
|
||||
}
|
||||
|
||||
recordNodeList, err := c.CloudBroker().Node().List(ctx, req)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about Node list", err.Error())
|
||||
return nil, diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "NodeListDataSourceCheckPresence: response from CloudBroker().Node().List")
|
||||
|
||||
return recordNodeList, nil
|
||||
}
|
||||
Reference in New Issue
Block a user