1.0.0
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"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/extnet/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/extnet/utilities"
|
||||
)
|
||||
|
||||
// ExtNetDataSource flattens data source for extnet.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func ExtNetDataSource(ctx context.Context, state *models.DataSourceExtNetModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.ExtNetDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
netId := uint64(state.NetID.ValueInt64())
|
||||
|
||||
recordExtNet, err := utilities.ExtNetCheckPresence(ctx, netId, c)
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot get info about extnet with ID %v", netId), err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.ExtNetDataSource: before flatten", map[string]any{"net_id": netId, "recordExtNet": recordExtNet})
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceExtNetModel{
|
||||
NetID: state.NetID,
|
||||
Timeouts: state.Timeouts,
|
||||
|
||||
Id: types.StringValue(id.String()),
|
||||
CKey: types.StringValue(recordExtNet.CKey),
|
||||
Meta: flattens.Meta(ctx, recordExtNet.Meta),
|
||||
Default: types.BoolValue(recordExtNet.Default),
|
||||
DefaultQOS: &models.QOSModel{
|
||||
EBurst: types.Int64Value(int64(recordExtNet.DefaultQOS.EBurst)),
|
||||
ERate: types.Int64Value(int64(recordExtNet.DefaultQOS.ERate)),
|
||||
GUID: types.StringValue(recordExtNet.DefaultQOS.GUID),
|
||||
InBurst: types.Int64Value(int64(recordExtNet.DefaultQOS.InBurst)),
|
||||
InRate: types.Int64Value(int64(recordExtNet.DefaultQOS.InRate)),
|
||||
},
|
||||
Description: types.StringValue(recordExtNet.Description),
|
||||
FreeIPs: types.Int64Value(int64(recordExtNet.FreeIPs)),
|
||||
Gateway: types.StringValue(recordExtNet.Gateway),
|
||||
GID: types.Int64Value(int64(recordExtNet.GID)),
|
||||
GUID: types.Int64Value(int64(recordExtNet.GUID)),
|
||||
IPCIDR: types.StringValue(recordExtNet.IPCIDR),
|
||||
Milestones: types.Int64Value(int64(recordExtNet.Milestones)),
|
||||
NetName: types.StringValue(recordExtNet.Name),
|
||||
Network: types.StringValue(recordExtNet.Network),
|
||||
NetworkID: types.Int64Value(int64(recordExtNet.NetworkID)),
|
||||
PreReservationsNum: types.Int64Value(int64(recordExtNet.PreReservationsNum)),
|
||||
Prefix: types.Int64Value(int64(recordExtNet.Prefix)),
|
||||
PriVNFDevID: types.Int64Value(int64(recordExtNet.PriVNFDevID)),
|
||||
Status: types.StringValue(recordExtNet.Status),
|
||||
VLANID: types.Int64Value(int64(recordExtNet.VLANID)),
|
||||
VNFs: &models.VNFsModel{
|
||||
DHCP: types.Int64Value(int64(recordExtNet.VNFs.DHCP)),
|
||||
},
|
||||
}
|
||||
|
||||
reservations := make([]models.ItemReservationModel, 0, len(recordExtNet.Reservations))
|
||||
for _, item := range recordExtNet.Reservations {
|
||||
r := models.ItemReservationModel{
|
||||
ClientType: types.StringValue(item.ClientType),
|
||||
Description: types.StringValue(item.Description),
|
||||
DomainName: types.StringValue(item.DomainName),
|
||||
Hostname: types.StringValue(item.Hostname),
|
||||
IP: types.StringValue(item.IP),
|
||||
MAC: types.StringValue(item.MAC),
|
||||
Type: types.StringValue(item.Type),
|
||||
VMID: types.Int64Value(int64(item.VMID)),
|
||||
}
|
||||
reservations = append(reservations, r)
|
||||
}
|
||||
state.Reservations = reservations
|
||||
|
||||
excluded := make([]models.ExcludedModel, 0, len(recordExtNet.Excluded))
|
||||
for _, item := range recordExtNet.Excluded {
|
||||
e := models.ExcludedModel{
|
||||
ClientType: types.StringValue(item.ClientType),
|
||||
DomainName: types.StringValue(item.DomainName),
|
||||
HostName: types.StringValue(item.HostName),
|
||||
IP: types.StringValue(item.IP),
|
||||
MAC: types.StringValue(item.MAC),
|
||||
Type: types.StringValue(item.Type),
|
||||
VMID: types.Int64Value(int64(item.VMID)),
|
||||
}
|
||||
excluded = append(excluded, e)
|
||||
}
|
||||
state.Excluded = excluded
|
||||
|
||||
var diagsItem diag.Diagnostics
|
||||
state.CheckIPs, diagsItem = types.ListValueFrom(ctx, types.StringType, recordExtNet.CheckIPs)
|
||||
if diagsItem.HasError() {
|
||||
tflog.Error(ctx, fmt.Sprint("flattens.ExtNetDataSource: cannot flatten recordExtNet.CheckIPs to state.CheckIPs", diags))
|
||||
}
|
||||
state.DNS, diagsItem = types.ListValueFrom(ctx, types.StringType, recordExtNet.DNS)
|
||||
if diagsItem.HasError() {
|
||||
tflog.Error(ctx, fmt.Sprint("flattens.ExtNetDataSource: cannot flatten recordExtNet.DNS to state.DNS", diags))
|
||||
}
|
||||
state.SharedWith, diagsItem = types.ListValueFrom(ctx, types.Int64Type, recordExtNet.SharedWith)
|
||||
if diagsItem.HasError() {
|
||||
tflog.Error(ctx, fmt.Sprint("flattens.ExtNetDataSource: cannot flatten recordExtNet.SharedWith to state.SharedWith", diags))
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.ExtNetDataSource: after flatten", map[string]any{"net_id": state.Id.ValueString()})
|
||||
|
||||
tflog.Info(ctx, "End flattens.ExtNetDataSource", map[string]any{"net_id": state.Id.ValueString()})
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
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/service/cloudapi/extnet/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/extnet/utilities"
|
||||
)
|
||||
|
||||
// ExtNetComputesListDataSource flattens data source for extnet computes list.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func ExtNetComputesListDataSource(ctx context.Context, state *models.DataSourceExtNetComputesListModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.ExtNetComputesListDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
compsList, err := utilities.ExtNetComputesListCheckPresence(ctx, state, c)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about extnet list", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.ExtNetComputesListDataSource: before flatten")
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceExtNetComputesListModel{
|
||||
AccountID: state.AccountID,
|
||||
RGID: state.RGID,
|
||||
ComputeID: state.ComputeID,
|
||||
Page: state.Page,
|
||||
Size: state.Size,
|
||||
Timeouts: state.Timeouts,
|
||||
SortBy: state.SortBy,
|
||||
|
||||
Id: types.StringValue(id.String()),
|
||||
EntryCount: types.Int64Value(int64(compsList.EntryCount)),
|
||||
}
|
||||
|
||||
items := make([]models.ItemComputeModel, 0, len(compsList.Data))
|
||||
for _, item := range compsList.Data {
|
||||
i := models.ItemComputeModel{
|
||||
AccountID: types.Int64Value(int64(item.AccountID)),
|
||||
AccountName: types.StringValue(item.AccountName),
|
||||
ID: types.Int64Value(int64(item.ID)),
|
||||
Name: types.StringValue(item.Name),
|
||||
RGID: types.Int64Value(int64(item.RGID)),
|
||||
RGName: types.StringValue(item.RGName),
|
||||
}
|
||||
|
||||
extnets := make([]models.ItemComputeExtNetModel, 0, len(item.ExtNets))
|
||||
for _, en := range item.ExtNets {
|
||||
e := models.ItemComputeExtNetModel{
|
||||
NetId: types.Int64Value(int64(en.ID)),
|
||||
IpAddr: types.StringValue(en.IPAddr),
|
||||
IPCIDR: types.StringValue(en.IPCIDR),
|
||||
Name: types.StringValue(en.Name),
|
||||
}
|
||||
extnets = append(extnets, e)
|
||||
}
|
||||
i.ExtNets = extnets
|
||||
items = append(items, i)
|
||||
}
|
||||
|
||||
state.Items = items
|
||||
|
||||
tflog.Info(ctx, "flattens.ExtNetComputesListDataSource: after flatten")
|
||||
|
||||
tflog.Info(ctx, "End flattens.ExtNetComputesListDataSource")
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
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/service/cloudapi/extnet/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/extnet/utilities"
|
||||
)
|
||||
|
||||
// ExtNetDefaultDataSource flattens data source for extnet default.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func ExtNetDefaultDataSource(ctx context.Context, state *models.DataSourceExtNetDefaultModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.ExtNetDefaultDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
netId, err := utilities.ExtNetDefaultCheckPresence(ctx, c)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about default extnet ID %v", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.ExtNetDefaultDataSource: before flatten")
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceExtNetDefaultModel{
|
||||
Timeouts: state.Timeouts,
|
||||
|
||||
Id: types.StringValue(id.String()),
|
||||
NetId: types.Int64Value(int64(netId)),
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.ExtNetDefaultDataSource: after flatten")
|
||||
|
||||
tflog.Info(ctx, "End flattens.ExtNetDefaultDataSource")
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
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/service/cloudapi/extnet/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/extnet/utilities"
|
||||
)
|
||||
|
||||
// ExtNetListDataSource flattens data source for extnet list.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func ExtNetListDataSource(ctx context.Context, state *models.DataSourceExtNetListModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.ExtNetListDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
extNetList, err := utilities.ExtNetListCheckPresence(ctx, state, c)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about extnet list", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.ExtNetListDataSource: before flatten")
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceExtNetListModel{
|
||||
AccountID: state.AccountID,
|
||||
ByID: state.ByID,
|
||||
Name: state.Name,
|
||||
Network: state.Network,
|
||||
VLANID: state.VLANID,
|
||||
VNFDevID: state.VNFDevID,
|
||||
Status: state.Status,
|
||||
Page: state.Page,
|
||||
Size: state.Size,
|
||||
Timeouts: state.Timeouts,
|
||||
SortBy: state.SortBy,
|
||||
|
||||
Id: types.StringValue(id.String()),
|
||||
EntryCount: types.Int64Value(int64(extNetList.EntryCount)),
|
||||
}
|
||||
|
||||
items := make([]models.ItemExtNetModel, 0, len(extNetList.Data))
|
||||
for _, item := range extNetList.Data {
|
||||
i := models.ItemExtNetModel{
|
||||
ID: types.Int64Value(int64(item.ID)),
|
||||
IPCIDR: types.StringValue(item.IPCIDR),
|
||||
Name: types.StringValue(item.Name),
|
||||
Status: types.StringValue(item.Status),
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
state.Items = items
|
||||
|
||||
tflog.Info(ctx, "flattens.ExtNetListDataSource: after flatten")
|
||||
|
||||
tflog.Info(ctx, "End flattens.ExtNetListDataSource")
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user