1.1.0
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
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/terraform-provider-dynamix/internal/flattens"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/dpdknet/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/dpdknet/utilities"
|
||||
)
|
||||
|
||||
func DPDKDataSource(ctx context.Context, state *models.DataSourceDPDKModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.DPDKDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
dpdkId := uint64(state.DPDKID.ValueInt64())
|
||||
|
||||
recordDPDK, diags := utilities.DPDKDataSourceCheckPresence(ctx, dpdkId, c)
|
||||
if diags.HasError() {
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.DPDKDataSource: before flatten", map[string]any{"dpdk_id": dpdkId})
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceDPDKModel{
|
||||
DPDKID: state.DPDKID,
|
||||
Timeouts: state.Timeouts,
|
||||
|
||||
Id: types.StringValue(id.String()),
|
||||
AccountAccess: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, recordDPDK.AccountAccess),
|
||||
CreatedTime: types.Int64Value(int64(recordDPDK.CreatedTime)),
|
||||
Desc: types.StringValue(recordDPDK.Description),
|
||||
GID: types.Int64Value(int64(recordDPDK.GID)),
|
||||
GUID: types.Int64Value(int64(recordDPDK.GUID)),
|
||||
Name: types.StringValue(recordDPDK.Name),
|
||||
RGAccess: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, recordDPDK.RGAccess),
|
||||
Status: types.StringValue(recordDPDK.Status),
|
||||
OVSBridge: types.StringValue(recordDPDK.OVSBridge),
|
||||
VlanID: types.Int64Value(int64(recordDPDK.VlanID)),
|
||||
ComputeIDs: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, recordDPDK.ComputeIDs),
|
||||
UpdatedTime: types.Int64Value(int64(recordDPDK.UpdatedTime)),
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattens.DPDKDataSource", map[string]any{"dpdk_id": dpdkId})
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
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/terraform-provider-dynamix/internal/flattens"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/dpdknet/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/dpdknet/utilities"
|
||||
)
|
||||
|
||||
func DPDKListDataSource(ctx context.Context, state *models.DataSourceDPDKListModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.DPDKListDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
dpdkList, err := utilities.DPDKListDataSourceCheckPresence(ctx, state, c)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about list DPDK", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.DPDKListDataSource: before flatten")
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceDPDKListModel{
|
||||
ByID: state.ByID,
|
||||
GID: state.GID,
|
||||
Name: state.Name,
|
||||
Desc: state.Desc,
|
||||
Status: state.Status,
|
||||
ComputeIDs: state.ComputeIDs,
|
||||
SortBy: state.SortBy,
|
||||
Page: state.Page,
|
||||
Size: state.Size,
|
||||
Timeouts: state.Timeouts,
|
||||
|
||||
Id: types.StringValue(id.String()),
|
||||
}
|
||||
|
||||
items := make([]models.ItemDPDKListModel, 0, len(dpdkList.Data))
|
||||
for _, dpdkItem := range dpdkList.Data {
|
||||
|
||||
item := models.ItemDPDKListModel{
|
||||
AccountAccess: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, dpdkItem.AccountAccess),
|
||||
CreatedTime: types.Int64Value(int64(dpdkItem.CreatedTime)),
|
||||
Desc: types.StringValue(dpdkItem.Description),
|
||||
DPDKID: types.Int64Value(int64(dpdkItem.ID)),
|
||||
GID: types.Int64Value(int64(dpdkItem.GID)),
|
||||
GUID: types.Int64Value(int64(dpdkItem.GUID)),
|
||||
Name: types.StringValue(dpdkItem.Name),
|
||||
RGAccess: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, dpdkItem.RGAccess),
|
||||
Status: types.StringValue(dpdkItem.Status),
|
||||
OVSBridge: types.StringValue(dpdkItem.OVSBridge),
|
||||
VlanID: types.Int64Value(int64(dpdkItem.VlanID)),
|
||||
ComputeIDs: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, dpdkItem.ComputeIDs),
|
||||
UpdatedTime: types.Int64Value(int64(dpdkItem.UpdatedTime)),
|
||||
}
|
||||
|
||||
items = append(items, item)
|
||||
}
|
||||
|
||||
state.Items = items
|
||||
state.EntryCount = types.Int64Value(int64(dpdkList.EntryCount))
|
||||
|
||||
tflog.Info(ctx, "End flattens.DPDKListDataSource")
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user