This commit is contained in:
asteam
2024-07-25 14:33:38 +03:00
commit 6f40af6a5f
946 changed files with 98335 additions and 0 deletions

View File

@@ -0,0 +1,92 @@
package flattens
import (
"context"
"fmt"
"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/vfpool/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/vfpool/utilities"
)
// VFPoolDataSource flattens data source for vfpool.
// Return error in case data source is not found on the platform.
// Flatten errors are added to tflog.
func VFPoolDataSource(ctx context.Context, state *models.ItemVFPoolModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start flattens.VFPoolDataSource")
diags := diag.Diagnostics{}
vfPoolID := uint64(state.VFPoolID.ValueInt64())
record, err := utilities.VFPoolCheckPresence(ctx, vfPoolID, c)
if err != nil {
diags.AddError(fmt.Sprintf("Cannot get info about VFpool with ID %v", vfPoolID), err.Error())
return diags
}
tflog.Info(ctx, "flattens.VFPoolDataSource: before flatten", map[string]any{"record": record})
*state = models.ItemVFPoolModel{
//required fields
VFPoolID: state.VFPoolID,
//optional fields
Timeouts: state.Timeouts,
//compute fields
AccountAccess: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, record.AccountAccess),
CreatedTime: types.Int64Value(int64(record.CreatedTime)),
Description: types.StringValue(record.Description),
GID: types.Int64Value(int64(record.GID)),
GUID: types.Int64Value(int64(record.GUID)),
Name: types.StringValue(record.Name),
RGAccess: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, record.RGAccess),
Status: types.StringValue(record.Status),
UpdatedTime: types.Int64Value(int64(record.UpdatedTime)),
}
items := make([]models.VFSModel, 0, len(record.VFS))
for _, vfsItem := range record.VFS {
i := models.VFSModel{
NodeID: types.Int64Value(int64(vfsItem.NodeID)),
}
vfList := make([]models.VFItemModel, 0, len(vfsItem.VFList))
for _, vfItem := range vfsItem.VFList {
vfI := models.VFItemModel{
NicName: types.StringValue(vfItem.NicName),
}
vfInfoList := make([]models.VFSInfoItemModel, 0, len(vfItem.VFSInfo))
for _, vfsInfoItem := range vfItem.VFSInfo {
vfsInfoI := models.VFSInfoItemModel{
ID: types.Int64Value(int64(vfsInfoItem.ID)),
Claimed: types.BoolValue(vfsInfoItem.Claimed),
VMID: types.Int64Value(int64(vfsInfoItem.VMID)),
}
vfInfoList = append(vfInfoList, vfsInfoI)
}
vfI.VFSInfo = vfInfoList
vfList = append(vfList, vfI)
}
i.VFList = vfList
items = append(items, i)
}
state.VFS = items
tflog.Info(ctx, "flattens.VFPoolDataSource: after flatten")
tflog.Info(ctx, "End flattens.VFPoolDataSource")
return nil
}

View File

@@ -0,0 +1,104 @@
package flattens
import (
"context"
"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/vfpool/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/vfpool/utilities"
)
// VFPoolListDataSource flattens data source for vfpool list.
// Return error in case data source is not found on the platform.
// Flatten errors are added to tflog.
func VFPoolListDataSource(ctx context.Context, state *models.ListVFPoolModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start flattens.VFPoolListDataSource")
diags := diag.Diagnostics{}
record, err := utilities.VFPoolListCheckPresence(ctx, state, c)
if err != nil {
diags.AddError("Cannot get info about fvpool list", err.Error())
return diags
}
tflog.Info(ctx, "flattens.VFPoolListDataSource: before flatten", map[string]any{"record": record})
*state = models.ListVFPoolModel{
//optional fields
Timeouts: state.Timeouts,
ByID: state.ByID,
Name: state.Name,
Description: state.Description,
Status: state.Status,
AccountAccess: state.AccountAccess,
RgAccess: state.RgAccess,
SortBy: state.SortBy,
Page: state.Page,
Size: state.Size,
//compute fields
EntryCount: types.Int64Value(int64(record.EntryCount)),
}
data := make([]models.ItemVFPoolListModel, 0, len(record.Data))
for _, item := range record.Data {
i := models.ItemVFPoolListModel{
VFPoolID: types.Int64Value(int64(item.ID)),
AccountAccess: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, item.AccountAccess),
CreatedTime: types.Int64Value(int64(item.CreatedTime)),
Description: types.StringValue(item.Description),
GID: types.Int64Value(int64(item.GID)),
GUID: types.Int64Value(int64(item.GUID)),
Name: types.StringValue(item.Name),
RGAccess: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, item.RGAccess),
Status: types.StringValue(item.Status),
UpdatedTime: types.Int64Value(int64(item.UpdatedTime)),
}
items := make([]models.VFSListModel, 0, len(item.VFS))
for _, item := range item.VFS {
i := models.VFSListModel{
NodeID: types.Int64Value(int64(item.NodeID)),
}
vfList := make([]models.VFItemListModel, 0, len(item.VFList))
for _, vfItem := range item.VFList {
vfI := models.VFItemListModel{
NicName: types.StringValue(vfItem.NicName),
}
vfInfoList := make([]models.VFSInfoItemListModel, 0, len(vfItem.VFSInfo))
for _, vfInfoItem := range vfItem.VFSInfo {
vfInfoI := models.VFSInfoItemListModel{
ID: types.Int64Value(int64(vfInfoItem.ID)),
Claimed: types.BoolValue(vfInfoItem.Claimed),
VMID: types.Int64Value(int64(vfInfoItem.VMID)),
}
vfInfoList = append(vfInfoList, vfInfoI)
}
vfI.VFSInfo = vfInfoList
vfList = append(vfList, vfI)
}
i.VFList = vfList
items = append(items, i)
}
i.VFS = items
data = append(data, i)
}
state.Items = data
tflog.Info(ctx, "flattens.VFPoolListDataSource: after flatten")
tflog.Info(ctx, "End flattens.VFPoolListDataSource")
return nil
}