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,367 @@
package flattens
import (
"context"
"encoding/json"
"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/decort-golang-sdk/pkg/cloudapi/compute"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/kvmvm/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/kvmvm/utilities"
)
func DataSourceCompute(ctx context.Context, state *models.RecordComputeModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start FlattenDataSourceCompute")
diags := diag.Diagnostics{}
computeRecord, err := utilities.ComputeCheckPresence(ctx, state, c)
if err != nil {
diags.AddError("Error get compute info", err.Error())
return diags
}
id := uuid.New()
customFields, _ := json.Marshal(computeRecord.CustomFields)
devices, _ := json.Marshal(computeRecord.Devices)
userdata, _ := json.Marshal(computeRecord.Userdata)
*state = models.RecordComputeModel{
Timeouts: state.Timeouts,
Id: types.StringValue(id.String()),
ComputeId: state.ComputeId,
ACL: flattenACL(ctx, &computeRecord.ACL),
AccountID: types.Int64Value(int64(computeRecord.AccountID)),
AccountName: types.StringValue(computeRecord.AccountName),
AffinityLabel: types.StringValue(computeRecord.AffinityLabel),
AffinityRules: flattenAffinityRule(ctx, &computeRecord.AffinityRules),
AffinityWeight: types.Int64Value(int64(computeRecord.AffinityWeight)),
AntiAffinityRules: flattenAffinityRule(ctx, &computeRecord.AntiAffinityRules),
Architecture: types.StringValue(computeRecord.Architecture),
BootDiskSize: types.Int64Value(int64(computeRecord.BootDiskSize)),
CdImageId: types.Int64Value(int64(computeRecord.CdImageId)),
CloneReference: types.Int64Value(int64(computeRecord.CloneReference)),
ComputeCIID: types.Int64Value(int64(computeRecord.ComputeCIID)),
CPU: types.Int64Value(int64(computeRecord.CPU)),
CPUPin: types.BoolValue(computeRecord.CPUPin),
CreatedBy: types.StringValue(computeRecord.CreatedBy),
CreatedTime: types.Int64Value(int64(computeRecord.CreatedTime)),
CustomFields: types.StringValue(string(customFields)),
DeletedBy: types.StringValue(computeRecord.DeletedBy),
DeletedTime: types.Int64Value(int64(computeRecord.DeletedTime)),
Description: types.StringValue(computeRecord.Description),
Devices: types.StringValue(string(devices)),
Disks: flattenDisks(ctx, &computeRecord.Disks),
Driver: types.StringValue(computeRecord.Driver),
GID: types.Int64Value(int64(computeRecord.GID)),
GUID: types.Int64Value(int64(computeRecord.GUID)),
HPBacked: types.BoolValue(computeRecord.HPBacked),
ImageID: types.Int64Value(int64(computeRecord.ImageID)),
ImageName: types.StringValue(computeRecord.ImageName),
Interfaces: flattenInterfaces(ctx, &computeRecord.Interfaces),
LockStatus: types.StringValue(computeRecord.LockStatus),
ManagerID: types.Int64Value(int64(computeRecord.ManagerID)),
ManagerType: types.StringValue(computeRecord.ManagerType),
MigrationJob: types.Int64Value(int64(computeRecord.MigrationJob)),
Milestones: types.Int64Value(int64(computeRecord.Milestones)),
Name: types.StringValue(computeRecord.Name),
NatableVINSID: types.Int64Value(int64(computeRecord.NatableVINSID)),
NatableVINSIP: types.StringValue(computeRecord.NatableVINSIP),
NatableVINSName: types.StringValue(computeRecord.NatableVINSName),
NatableVINSNetwork: types.StringValue(computeRecord.NatableVINSNetwork),
NatableVINSNetworkName: types.StringValue(computeRecord.NatableVINSNetworkName),
NeedReboot: types.BoolValue(computeRecord.NeedReboot),
NumaAffinity: types.StringValue(computeRecord.NumaAffinity),
NumaNodeId: types.Int64Value(int64(computeRecord.NumaNodeId)),
OSUsers: flattenOSUsers(ctx, &computeRecord.OSUsers),
Pinned: types.BoolValue(computeRecord.Pinned),
RAM: types.Int64Value(int64(computeRecord.RAM)),
ReferenceID: types.StringValue(computeRecord.ReferenceID),
Registered: types.BoolValue(computeRecord.Registered),
ResName: types.StringValue(computeRecord.ResName),
RGID: types.Int64Value(int64(computeRecord.RGID)),
RGName: types.StringValue(computeRecord.RGName),
SnapSets: flattenSnapSet(ctx, &computeRecord.SnapSets),
StatelessSepID: types.Int64Value(int64(computeRecord.StatelessSepID)),
StatelessSepType: types.StringValue(computeRecord.StatelessSepType),
Status: types.StringValue(computeRecord.Status),
TechStatus: types.StringValue(computeRecord.TechStatus),
UpdatedBy: types.StringValue(computeRecord.UpdatedBy),
UpdatedTime: types.Int64Value(int64(computeRecord.UpdatedTime)),
UserManaged: types.BoolValue(computeRecord.UserManaged),
Userdata: types.StringValue(string(userdata)),
VirtualImageID: types.Int64Value(int64(computeRecord.VirtualImageID)),
VirtualImageName: types.StringValue(computeRecord.VirtualImageName),
}
state.BootOrder, diags = types.ListValueFrom(ctx, types.StringType, computeRecord.BootOrder)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error FlattenDataSourceCompute", diags))
}
state.Clones, diags = types.ListValueFrom(ctx, types.Int64Type, computeRecord.Clones)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error FlattenDataSourceCompute", diags))
}
state.Tags, diags = types.MapValueFrom(ctx, types.StringType, computeRecord.Tags)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error FlattenDataSourceCompute", diags))
}
state.ReservedNodeCpus, diags = types.ListValueFrom(ctx, types.Int64Type, computeRecord.ReservedNodeCpus)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error FlattenDataSourceCompute", diags))
}
state.VGPUs, diags = types.ListValueFrom(ctx, types.Int64Type, computeRecord.VGPUs)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error FlattenDataSourceCompute", diags))
}
tflog.Info(ctx, "End FlattenDataSourceCompute")
return nil
}
func flattenACL(ctx context.Context, acl *compute.RecordACL) *models.RecordACLModel {
tflog.Info(ctx, "Start flattenACL")
res := models.RecordACLModel{
AccountACL: flattenACLList(ctx, &acl.AccountACL),
ComputeACL: flattenACLList(ctx, &acl.ComputeACL),
RGACL: flattenACLList(ctx, &acl.RGACL),
}
tflog.Info(ctx, "End flattenACL")
return &res
}
func flattenACLList(ctx context.Context, acl *compute.ListACL) []models.ItemACLModel {
tflog.Info(ctx, "Start flattenACLList")
res := make([]models.ItemACLModel, 0, len(*acl))
for _, item := range *acl {
temp := models.ItemACLModel{
Explicit: types.BoolValue(bool(item.Explicit)),
GUID: types.StringValue(item.GUID),
Right: types.StringValue(item.Right),
Status: types.StringValue(item.Status),
Type: types.StringValue(item.Type),
UserGroupID: types.StringValue(item.UserGroupID),
}
res = append(res, temp)
}
tflog.Info(ctx, "End flattenACLList")
return res
}
func flattenAffinityRule(ctx context.Context, rules *compute.ListRules) []models.ItemRuleModel {
tflog.Info(ctx, "Start flattenAffinityRule")
res := make([]models.ItemRuleModel, 0, len(*rules))
for _, item := range *rules {
temp := models.ItemRuleModel{
GUID: types.StringValue(item.GUID),
Key: types.StringValue(item.Key),
Mode: types.StringValue(item.Mode),
Policy: types.StringValue(item.Policy),
Topology: types.StringValue(item.Topology),
Value: types.StringValue(item.Value),
}
res = append(res, temp)
}
tflog.Info(ctx, "End flattenAffinityRule")
return res
}
func flattenDisks(ctx context.Context, disks *compute.ListComputeDisks) []models.ItemDiskModel {
tflog.Info(ctx, "Start flattenDisks")
var diags diag.Diagnostics
res := make([]models.ItemDiskModel, 0, len(*disks))
for _, item := range *disks {
acl, _ := json.Marshal(item.ACL)
temp := models.ItemDiskModel{
CKey: types.StringValue(item.CKey),
ACL: types.StringValue(string(acl)),
AccountID: types.Int64Value(int64(item.AccountID)),
BootPartition: types.Int64Value(int64(item.BootPartition)),
CreatedTime: types.Int64Value(int64(item.CreatedTime)),
DeletedTime: types.Int64Value(int64(item.CreatedTime)),
Description: types.StringValue(item.Description),
DestructionTime: types.Int64Value(int64(item.DestructionTime)),
DiskPath: types.StringValue(item.DiskPath),
GID: types.Int64Value(int64(item.GID)),
GUID: types.Int64Value(int64(item.GUID)),
ID: types.Int64Value(int64(item.ID)),
ImageID: types.Int64Value(int64(item.ImageID)),
IOTune: &models.IOTuneModel{
ReadBytesSec: types.Int64Value(int64(item.IOTune.ReadBytesSec)),
ReadBytesSecMax: types.Int64Value(int64(item.IOTune.ReadBytesSecMax)),
ReadIOPSSec: types.Int64Value(int64(item.IOTune.ReadIOPSSec)),
ReadIOPSSecMax: types.Int64Value(int64(item.IOTune.ReadIOPSSecMax)),
SizeIOPSSec: types.Int64Value(int64(item.IOTune.SizeIOPSSec)),
TotalBytesSec: types.Int64Value(int64(item.IOTune.TotalBytesSec)),
TotalBytesSecMax: types.Int64Value(int64(item.IOTune.TotalBytesSecMax)),
TotalIOPSSec: types.Int64Value(int64(item.IOTune.TotalIOPSSec)),
TotalIOPSSecMax: types.Int64Value(int64(item.IOTune.TotalIOPSSecMax)),
WriteBytesSec: types.Int64Value(int64(item.IOTune.WriteBytesSec)),
WriteBytesSecMax: types.Int64Value(int64(item.IOTune.WriteBytesSecMax)),
WriteIOPSSec: types.Int64Value(int64(item.IOTune.WriteIOPSSec)),
WriteIOPSSecMax: types.Int64Value(int64(item.IOTune.WriteIOPSSecMax)),
},
IQN: types.StringValue(item.IQN),
Login: types.StringValue(item.Login),
Milestones: types.Int64Value(int64(item.Milestones)),
Name: types.StringValue(item.Name),
Order: types.Int64Value(int64(item.Order)),
Params: types.StringValue(item.Params),
ParentID: types.Int64Value(int64(item.ParentID)),
Passwd: types.StringValue(item.Passwd),
Pool: types.StringValue(item.Pool),
PCISlot: types.Int64Value(item.PCISlot),
PurgeTime: types.Int64Value(int64(item.PurgeTime)),
RealityDeviceNumber: types.Int64Value(int64(item.RealityDeviceNumber)),
Replication: &models.ReplicationModel{
DiskID: types.Int64Value(int64(item.Replication.DiskID)),
PoolID: types.StringValue(item.Replication.PoolID),
Role: types.StringValue(item.Replication.Role),
SelfVolumeID: types.StringValue(item.Replication.SelfVolumeID),
StorageID: types.StringValue(item.Replication.StorageID),
VolumeID: types.StringValue(item.Replication.VolumeID),
},
ResID: types.StringValue(item.ResID),
Role: types.StringValue(item.Role),
SepID: types.Int64Value(int64(item.SepID)),
Shareable: types.BoolValue(item.Shareable),
SizeMax: types.Int64Value(int64(item.SizeMax)),
SizeUsed: types.Float64Value(item.SizeUsed),
Snapshots: flattenSnapshotExtend(ctx, &item.Snapshots),
Status: types.StringValue(item.Status),
TechStatus: types.StringValue(item.TechStatus),
Type: types.StringValue(item.Type),
VMID: types.Int64Value(int64(item.VMID)),
}
temp.Images, diags = types.ListValueFrom(ctx, types.Int64Type, item.Images)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenDisks", diags))
}
temp.PresentTo, diags = types.ListValueFrom(ctx, types.Int64Type, item.PresentTo)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenDisks", diags))
}
res = append(res, temp)
}
tflog.Info(ctx, "End flattenDisks")
return res
}
func flattenSnapshotExtend(ctx context.Context, snapshot *compute.SnapshotExtendList) []models.ItemSnapshotExtendModel {
tflog.Info(ctx, "Start flattenSnapshotExtend")
res := make([]models.ItemSnapshotExtendModel, 0, len(*snapshot))
for _, item := range *snapshot {
temp := models.ItemSnapshotExtendModel{
GUID: types.StringValue(item.GUID),
Label: types.StringValue(item.Label),
ReferenceID: types.StringValue(item.ReferenceID),
ResID: types.StringValue(item.ResID),
SnapSetGUID: types.StringValue(item.SnapSetGUID),
SnapSetTime: types.Int64Value(int64(item.SnapSetTime)),
TimeStamp: types.Int64Value(int64(item.TimeStamp)),
}
res = append(res, temp)
}
tflog.Info(ctx, "End flattenSnapshotExtend")
return res
}
func flattenInterfaces(ctx context.Context, interfaces *compute.ListInterfaces) []models.ItemInterfaceModel {
tflog.Info(ctx, "Start flattenInterfaces")
var diags diag.Diagnostics
res := make([]models.ItemInterfaceModel, 0, len(*interfaces))
for _, item := range *interfaces {
temp := models.ItemInterfaceModel{
ConnID: types.Int64Value(int64(item.ConnID)),
ConnType: types.StringValue(item.ConnType),
DefGW: types.StringValue(item.DefGW),
Enabled: types.BoolValue(item.Enabled),
FLIPGroupID: types.Int64Value(int64(item.FLIPGroupID)),
GUID: types.StringValue(item.GUID),
IPAddress: types.StringValue(item.IPAddress),
ListenSSH: types.BoolValue(item.ListenSSH),
MAC: types.StringValue(item.MAC),
Name: types.StringValue(item.Name),
NetID: types.Int64Value(int64(item.NetID)),
NetMask: types.Int64Value(int64(item.NetMask)),
NetType: types.StringValue(item.NetType),
NodeID: types.Int64Value(int64(item.NodeID)),
PCISlot: types.Int64Value(item.PCISlot),
QOS: &models.QOSModel{
ERate: types.Int64Value(int64(item.QOS.ERate)),
GUID: types.StringValue(item.QOS.GUID),
InBurst: types.Int64Value(int64(item.QOS.InBurst)),
InRate: types.Int64Value(int64(item.QOS.InRate)),
},
Target: types.StringValue(item.Target),
Type: types.StringValue(item.Type),
}
temp.VNFs, diags = types.ListValueFrom(ctx, types.Int64Type, item.VNFs)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenInterfaces", diags))
}
res = append(res, temp)
}
tflog.Info(ctx, "End flattenInterfaces")
return res
}
func flattenSnapSet(ctx context.Context, snapSet *compute.ListSnapSets) []models.ItemSnapSetModel {
tflog.Info(ctx, "Start flattenSnapSet")
var diags diag.Diagnostics
res := make([]models.ItemSnapSetModel, 0, len(*snapSet))
for _, item := range *snapSet {
temp := models.ItemSnapSetModel{
GUID: types.StringValue(item.GUID),
Label: types.StringValue(item.Label),
Timestamp: types.Int64Value(int64(item.Timestamp)),
}
temp.Disks, diags = types.ListValueFrom(ctx, types.Int64Type, item.Disks)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenSnapSet", diags))
}
res = append(res, temp)
}
tflog.Info(ctx, "End flattenSnapSet")
return res
}
func flattenOSUsers(ctx context.Context, osUsers *compute.ListOSUser) []models.ItemOSUserModel {
tflog.Info(ctx, "Start flattenOSUsers")
res := make([]models.ItemOSUserModel, 0, len(*osUsers))
for _, item := range *osUsers {
temp := models.ItemOSUserModel{
GUID: types.StringValue(item.GUID),
Login: types.StringValue(item.Login),
Password: types.StringValue(item.Password),
PubKey: types.StringValue(item.PubKey),
}
res = append(res, temp)
}
tflog.Info(ctx, "End flattenOSUsers")
return res
}

View File

@@ -0,0 +1,57 @@
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/cloudapi/compute"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/kvmvm/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/kvmvm/utilities"
)
func DataSourceComputeAudits(ctx context.Context, state *models.ListAuditsModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start FlattenDataSourceComputeAudits")
diags := diag.Diagnostics{}
auditsList, err := utilities.ComputeAuditsCheckPresence(ctx, state, c)
if err != nil {
diags.AddError("Error get compute audits info", err.Error())
return diags
}
id := uuid.New()
*state = models.ListAuditsModel{
ComputeID: state.ComputeID,
Timeouts: state.Timeouts,
Id: types.StringValue(id.String()),
Items: flattenItemsAuditsList(ctx, auditsList),
}
tflog.Info(ctx, "End FlattenDataSourceComputeAudits")
return nil
}
func flattenItemsAuditsList(ctx context.Context, audits *compute.ListAudits) []models.ItemAuditModel {
tflog.Info(ctx, "Start flattenItemsAuditsList")
res := make([]models.ItemAuditModel, 0, len(*audits))
for _, item := range *audits {
temp := models.ItemAuditModel{
Call: types.StringValue(item.Call),
ResponseTime: types.Float64Value(item.ResponseTime),
StatusCode: types.Int64Value(int64(item.StatusCode)),
Timestamp: types.Float64Value(item.Timestamp),
User: types.StringValue(item.User),
}
res = append(res, temp)
}
tflog.Info(ctx, "End flattenItemsAuditsList")
return res
}

View File

@@ -0,0 +1,54 @@
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/cloudapi/compute"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/kvmvm/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/kvmvm/utilities"
)
func DataSourceComputeGetAudits(ctx context.Context, state *models.GetAuditsModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start FlattenDataSourceComputeGetAudits")
diags := diag.Diagnostics{}
auditsShortList, err := utilities.ComputeGetAuditsCheckPresence(ctx, state, c)
if err != nil {
diags.AddError("Error get compute get audits info", err.Error())
return diags
}
id := uuid.New()
*state = models.GetAuditsModel{
ComputeID: state.ComputeID,
Timeouts: state.Timeouts,
Id: types.StringValue(id.String()),
Items: flattenItemsShort(ctx, auditsShortList),
}
tflog.Info(ctx, "End FlattenDataSourceComputeGetAudits")
return nil
}
func flattenItemsShort(ctx context.Context, audits *compute.ListShortAudits) []models.ItemShortAuditModel {
tflog.Info(ctx, "Start flattenItemsShort")
res := make([]models.ItemShortAuditModel, 0, len(*audits))
for _, item := range *audits {
temp := models.ItemShortAuditModel{
Epoch: types.Float64Value(item.Epoch),
Message: types.StringValue(item.Message),
}
res = append(res, temp)
}
tflog.Info(ctx, "End flattenItemsShort")
return res
}

View File

@@ -0,0 +1,37 @@
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/kvmvm/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/kvmvm/utilities"
)
func DataSourceComputeGetConsoleUrl(ctx context.Context, state *models.GetConsoleUrlModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start FlattenDataSourceComputeGetConsoleUrl")
diags := diag.Diagnostics{}
consoleUrl, err := utilities.ComputeGetConsoleUrlCheckPresence(ctx, state, c)
if err != nil {
diags.AddError("Error get compute console url", err.Error())
return diags
}
id := uuid.New()
*state = models.GetConsoleUrlModel{
ComputeID: state.ComputeID,
Timeouts: state.Timeouts,
Id: types.StringValue(id.String()),
ConsoleURL: types.StringValue(consoleUrl),
}
tflog.Info(ctx, "End FlattenDataSourceComputeGetConsoleUrl")
return nil
}

View File

@@ -0,0 +1,38 @@
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/kvmvm/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/kvmvm/utilities"
)
func DataSourceComputeGetLog(ctx context.Context, state *models.GetLogModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start FlattenDataSourceComputeGetLog")
diags := diag.Diagnostics{}
log, err := utilities.ComputeGetLogCheckPresence(ctx, state, c)
if err != nil {
diags.AddError("Error get compute log", err.Error())
return diags
}
id := uuid.New()
*state = models.GetLogModel{
ComputeID: state.ComputeID,
Path: state.Path,
Timeouts: state.Timeouts,
Id: types.StringValue(id.String()),
Log: types.StringValue(log),
}
tflog.Info(ctx, "End FlattenDataSourceComputeGetLog")
return nil
}

View File

@@ -0,0 +1,272 @@
package flattens
import (
"context"
"encoding/json"
"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/decort-golang-sdk/pkg/cloudapi/compute"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/kvmvm/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/kvmvm/utilities"
)
func DataSourceComputeList(ctx context.Context, state *models.ListComputesModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start FlattenDataSourceComputeList")
diags := diag.Diagnostics{}
list, err := utilities.ComputeListCheckPresence(ctx, state, c)
if err != nil {
diags.AddError("Error get compute list info", err.Error())
return diags
}
id := uuid.New()
*state = models.ListComputesModel{
ByID: state.ByID,
Name: state.Name,
AccountID: state.AccountID,
RGName: state.RGName,
RGID: state.RGID,
TechStatus: state.TechStatus,
Status: state.Status,
IPAddress: state.IPAddress,
ExtNetName: state.ExtNetName,
ExtNetID: state.ExtNetID,
IncludeDeleted: state.IncludeDeleted,
SortBy: state.SortBy,
Page: state.Page,
Size: state.Size,
IgnoreK8s: state.IgnoreK8s,
Timeouts: state.Timeouts,
Id: types.StringValue(id.String()),
Items: flattenItemsList(ctx, list),
EntryCount: types.Int64Value(int64(list.EntryCount)),
}
tflog.Info(ctx, "End FlattenDataSourceComputeList")
return nil
}
func flattenItemsList(ctx context.Context, computes *compute.ListComputes) []models.ItemComputeModel {
tflog.Info(ctx, "Start flattenItemsList")
var diags diag.Diagnostics
res := make([]models.ItemComputeModel, 0, len(computes.Data))
for _, item := range computes.Data {
customFields, _ := json.Marshal(item.CustomFields)
devices, _ := json.Marshal(item.Devices)
temp := models.ItemComputeModel{
ACL: flattenACLInList(ctx, &item.ACL),
AccountID: types.Int64Value(int64(item.AccountID)),
AccountName: types.StringValue(item.AccountName),
AffinityLabel: types.StringValue(item.AffinityLabel),
AffinityRules: flattenAffinityRuleInList(ctx, &item.AffinityRules),
AffinityWeight: types.Int64Value(int64(item.AffinityWeight)),
AntiAffinityRules: flattenAffinityRuleInList(ctx, &item.AntiAffinityRules),
Architecture: types.StringValue(item.Architecture),
BootDiskSize: types.Int64Value(int64(item.BootDiskSize)),
CdImageId: types.Int64Value(int64(item.CdImageId)),
CloneReference: types.Int64Value(int64(item.CloneReference)),
ComputeCIID: types.Int64Value(int64(item.ComputeCIID)),
CPU: types.Int64Value(int64(item.CPU)),
CPUPin: types.BoolValue(item.CPUPin),
CreatedBy: types.StringValue(item.CreatedBy),
CreatedTime: types.Int64Value(int64(item.CreatedTime)),
CustomFields: types.StringValue(string(customFields)),
DeletedBy: types.StringValue(item.DeletedBy),
DeletedTime: types.Int64Value(int64(item.DeletedTime)),
Description: types.StringValue(item.Description),
Devices: types.StringValue(string(devices)),
Disks: flattenDisksInList(ctx, &item.Disks),
Driver: types.StringValue(item.Driver),
GID: types.Int64Value(int64(item.GID)),
GUID: types.Int64Value(int64(item.GUID)),
HPBacked: types.BoolValue(item.HPBacked),
ComputeId: types.Int64Value(int64(item.ID)),
ImageID: types.Int64Value(int64(item.ImageID)),
Interfaces: flattenInterfaceInList(ctx, &item.Interfaces),
LockStatus: types.StringValue(item.LockStatus),
ManagerID: types.Int64Value(int64(item.ManagerID)),
ManagerType: types.StringValue(item.ManagerType),
MigrationJob: types.Int64Value(int64(item.MigrationJob)),
Milestones: types.Int64Value(int64(item.Milestones)),
Name: types.StringValue(item.Name),
NeedReboot: types.BoolValue(item.NeedReboot),
NumaAffinity: types.StringValue(item.NumaAffinity),
NumaNodeId: types.Int64Value(int64(item.NumaNodeId)),
Pinned: types.BoolValue(item.Pinned),
RAM: types.Int64Value(int64(item.RAM)),
ReferenceID: types.StringValue(item.ReferenceID),
Registered: types.BoolValue(item.Registered),
ResName: types.StringValue(item.ResName),
RGID: types.Int64Value(int64(item.RGID)),
RGName: types.StringValue(item.RGName),
SnapSets: flattenSnapSetInList(ctx, &item.SnapSets),
StatelessSepID: types.Int64Value(int64(item.StatelessSepID)),
StatelessSepType: types.StringValue(item.StatelessSepType),
Status: types.StringValue(item.Status),
TechStatus: types.StringValue(item.TechStatus),
TotalDiskSize: types.Int64Value(int64(item.TotalDiskSize)),
UpdatedBy: types.StringValue(item.UpdatedBy),
UpdatedTime: types.Int64Value(int64(item.UpdatedTime)),
UserManaged: types.BoolValue(item.UserManaged),
VINSConnected: types.Int64Value(int64(item.VINSConnected)),
VirtualImageID: types.Int64Value(int64(item.VirtualImageID)),
}
temp.BootOrder, diags = types.ListValueFrom(ctx, types.StringType, item.BootOrder)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenItemsList", diags))
}
temp.Clones, diags = types.ListValueFrom(ctx, types.Int64Type, item.Clones)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenItemsList", diags))
}
temp.Tags, diags = types.MapValueFrom(ctx, types.StringType, item.Tags)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenItemsList", diags))
}
temp.ReservedNodeCpus, diags = types.ListValueFrom(ctx, types.Int64Type, item.ReservedNodeCpus)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenItemsList", diags))
}
temp.VGPUs, diags = types.ListValueFrom(ctx, types.Int64Type, item.VGPUs)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenItemsList", diags))
}
res = append(res, temp)
}
tflog.Info(ctx, "End flattenItemsList")
return res
}
func flattenACLInList(ctx context.Context, acl *compute.ListACL) []models.ItemACLInListModel {
tflog.Info(ctx, "Start flattenACLInList")
res := make([]models.ItemACLInListModel, 0, len(*acl))
for _, item := range *acl {
temp := models.ItemACLInListModel{
Explicit: types.BoolValue(bool(item.Explicit)),
GUID: types.StringValue(item.GUID),
Right: types.StringValue(item.Right),
Status: types.StringValue(item.Status),
Type: types.StringValue(item.Type),
UserGroupID: types.StringValue(item.UserGroupID),
}
res = append(res, temp)
}
tflog.Info(ctx, "End flattenACLInList")
return res
}
func flattenAffinityRuleInList(ctx context.Context, rules *compute.ListRules) []models.ItemRuleInListModel {
tflog.Info(ctx, "Start flattenAffinityRuleInList")
res := make([]models.ItemRuleInListModel, 0, len(*rules))
for _, item := range *rules {
temp := models.ItemRuleInListModel{
GUID: types.StringValue(item.GUID),
Key: types.StringValue(item.Key),
Mode: types.StringValue(item.Mode),
Policy: types.StringValue(item.Policy),
Topology: types.StringValue(item.Topology),
Value: types.StringValue(item.Value),
}
res = append(res, temp)
}
tflog.Info(ctx, "End flattenAffinityRuleInList")
return res
}
func flattenDisksInList(ctx context.Context, disks *compute.ListInfoDisks) []models.DiskInListModel {
tflog.Info(ctx, "Start flattenDisksInList")
res := make([]models.DiskInListModel, 0, len(*disks))
for _, item := range *disks {
temp := models.DiskInListModel{
DiskId: types.Int64Value(int64(item.ID)),
PCISlot: types.Int64Value(item.PCISlot),
}
res = append(res, temp)
}
tflog.Info(ctx, "End flattenDisksInList")
return res
}
func flattenInterfaceInList(ctx context.Context, interfaces *compute.ListInterfaces) []models.ItemVNFInterfaceInListModel {
tflog.Info(ctx, "Start flattenInterfaceInList")
var diags diag.Diagnostics
res := make([]models.ItemVNFInterfaceInListModel, 0, len(*interfaces))
for _, item := range *interfaces {
temp := models.ItemVNFInterfaceInListModel{
ConnID: types.Int64Value(int64(item.ConnID)),
ConnType: types.StringValue(item.ConnType),
DefGW: types.StringValue(item.DefGW),
Enabled: types.BoolValue(item.Enabled),
FLIPGroupID: types.Int64Value(int64(item.FLIPGroupID)),
GUID: types.StringValue(item.GUID),
IPAddress: types.StringValue(item.IPAddress),
ListenSSH: types.BoolValue(item.ListenSSH),
MAC: types.StringValue(item.MAC),
Name: types.StringValue(item.Name),
NetID: types.Int64Value(int64(item.NetID)),
NetMask: types.Int64Value(int64(item.NetMask)),
NetType: types.StringValue(item.NetType),
NodeID: types.Int64Value(int64(item.NodeID)),
PCISlot: types.Int64Value(item.PCISlot),
QOS: &models.QOSInListModel{
ERate: types.Int64Value(int64(item.QOS.ERate)),
GUID: types.StringValue(item.QOS.GUID),
InBurst: types.Int64Value(int64(item.QOS.InBurst)),
InRate: types.Int64Value(int64(item.QOS.InRate)),
},
Target: types.StringValue(item.Target),
Type: types.StringValue(item.Type),
}
temp.VNFs, diags = types.ListValueFrom(ctx, types.Int64Type, item.VNFs)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenInterfaceInList", diags))
}
res = append(res, temp)
}
tflog.Info(ctx, "End flattenInterfaceInList")
return res
}
func flattenSnapSetInList(ctx context.Context, snapSet *compute.ListSnapSets) []models.ItemSnapSetInListModel {
tflog.Info(ctx, "Start flattenSnapSetInList")
var diags diag.Diagnostics
res := make([]models.ItemSnapSetInListModel, 0, len(*snapSet))
for _, item := range *snapSet {
temp := models.ItemSnapSetInListModel{
GUID: types.StringValue(item.GUID),
Label: types.StringValue(item.Label),
Timestamp: types.Int64Value(int64(item.Timestamp)),
}
temp.Disks, diags = types.ListValueFrom(ctx, types.Int64Type, item.Disks)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenSnapSetInList", diags))
}
res = append(res, temp)
}
tflog.Info(ctx, "End flattenSnapSetInList")
return res
}

View File

@@ -0,0 +1,270 @@
package flattens
import (
"context"
"encoding/json"
"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/decort-golang-sdk/pkg/cloudapi/compute"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/kvmvm/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/kvmvm/utilities"
)
func DataSourceComputeListDeleted(ctx context.Context, state *models.ListDeletedComputesModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start FlattenDataSourceComputeListDeleted")
diags := diag.Diagnostics{}
listDeleted, err := utilities.ComputeListDeletedCheckPresence(ctx, state, c)
if err != nil {
diags.AddError("Error get compute list deleted info", err.Error())
return diags
}
id := uuid.New()
*state = models.ListDeletedComputesModel{
ByID: state.ByID,
Name: state.Name,
AccountID: state.AccountID,
RGName: state.RGName,
RGID: state.RGID,
TechStatus: state.TechStatus,
IPAddress: state.IPAddress,
ExtNetName: state.ExtNetName,
ExtNetID: state.ExtNetID,
SortBy: state.SortBy,
Page: state.Page,
Size: state.Size,
IgnoreK8s: state.IgnoreK8s,
Timeouts: state.Timeouts,
Id: types.StringValue(id.String()),
Items: flattenItemsListDeleted(ctx, listDeleted),
EntryCount: types.Int64Value(int64(listDeleted.EntryCount)),
}
tflog.Info(ctx, "End FlattenDataSourceComputeListDeleted")
return nil
}
func flattenItemsListDeleted(ctx context.Context, computes *compute.ListComputes) []models.ItemListDeletedComputeModel {
tflog.Info(ctx, "Start flattenItemsListDeleted")
var diags diag.Diagnostics
res := make([]models.ItemListDeletedComputeModel, 0, len(computes.Data))
for _, item := range computes.Data {
customFields, _ := json.Marshal(item.CustomFields)
devices, _ := json.Marshal(item.Devices)
temp := models.ItemListDeletedComputeModel{
ACL: flattenACLInListDeleted(ctx, &item.ACL),
AccountID: types.Int64Value(int64(item.AccountID)),
AccountName: types.StringValue(item.AccountName),
AffinityLabel: types.StringValue(item.AffinityLabel),
AffinityRules: flattenAffinityRuleInListDeleted(ctx, &item.AffinityRules),
AffinityWeight: types.Int64Value(int64(item.AffinityWeight)),
AntiAffinityRules: flattenAffinityRuleInListDeleted(ctx, &item.AntiAffinityRules),
Architecture: types.StringValue(item.Architecture),
BootDiskSize: types.Int64Value(int64(item.BootDiskSize)),
CdImageId: types.Int64Value(int64(item.CdImageId)),
CloneReference: types.Int64Value(int64(item.CloneReference)),
ComputeCIID: types.Int64Value(int64(item.ComputeCIID)),
CPU: types.Int64Value(int64(item.CPU)),
CPUPin: types.BoolValue(item.CPUPin),
CreatedBy: types.StringValue(item.CreatedBy),
CreatedTime: types.Int64Value(int64(item.CreatedTime)),
CustomFields: types.StringValue(string(customFields)),
DeletedBy: types.StringValue(item.DeletedBy),
DeletedTime: types.Int64Value(int64(item.DeletedTime)),
Description: types.StringValue(item.Description),
Devices: types.StringValue(string(devices)),
Disks: flattenDisksInListDeleted(ctx, &item.Disks),
Driver: types.StringValue(item.Driver),
GID: types.Int64Value(int64(item.GID)),
GUID: types.Int64Value(int64(item.GUID)),
HPBacked: types.BoolValue(item.HPBacked),
ComputeId: types.Int64Value(int64(item.ID)),
ImageID: types.Int64Value(int64(item.ImageID)),
Interfaces: flattenInterfaceInListDeleted(ctx, &item.Interfaces),
LockStatus: types.StringValue(item.LockStatus),
ManagerID: types.Int64Value(int64(item.ManagerID)),
ManagerType: types.StringValue(item.ManagerType),
MigrationJob: types.Int64Value(int64(item.MigrationJob)),
Milestones: types.Int64Value(int64(item.Milestones)),
Name: types.StringValue(item.Name),
NeedReboot: types.BoolValue(item.NeedReboot),
NumaAffinity: types.StringValue(item.NumaAffinity),
NumaNodeId: types.Int64Value(int64(item.NumaNodeId)),
Pinned: types.BoolValue(item.Pinned),
RAM: types.Int64Value(int64(item.RAM)),
ReferenceID: types.StringValue(item.ReferenceID),
Registered: types.BoolValue(item.Registered),
ResName: types.StringValue(item.ResName),
RGID: types.Int64Value(int64(item.RGID)),
RGName: types.StringValue(item.RGName),
SnapSets: flattenSnapSetInListDeleted(ctx, &item.SnapSets),
StatelessSepID: types.Int64Value(int64(item.StatelessSepID)),
StatelessSepType: types.StringValue(item.StatelessSepType),
Status: types.StringValue(item.Status),
TechStatus: types.StringValue(item.TechStatus),
TotalDiskSize: types.Int64Value(int64(item.TotalDiskSize)),
UpdatedBy: types.StringValue(item.UpdatedBy),
UpdatedTime: types.Int64Value(int64(item.UpdatedTime)),
UserManaged: types.BoolValue(item.UserManaged),
VINSConnected: types.Int64Value(int64(item.VINSConnected)),
VirtualImageID: types.Int64Value(int64(item.VirtualImageID)),
}
temp.BootOrder, diags = types.ListValueFrom(ctx, types.StringType, item.BootOrder)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenItemsListDeleted", diags))
}
temp.Clones, diags = types.ListValueFrom(ctx, types.Int64Type, item.Clones)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenItemsListDeleted", diags))
}
temp.Tags, diags = types.MapValueFrom(ctx, types.StringType, item.Tags)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenItemsListDeleted", diags))
}
temp.ReservedNodeCpus, diags = types.ListValueFrom(ctx, types.Int64Type, item.ReservedNodeCpus)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenItemsList", diags))
}
temp.VGPUs, diags = types.ListValueFrom(ctx, types.Int64Type, item.VGPUs)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenItemsListDeleted", diags))
}
res = append(res, temp)
}
tflog.Info(ctx, "End flattenItemsListDeleted")
return res
}
func flattenACLInListDeleted(ctx context.Context, acl *compute.ListACL) []models.ItemACLInListDeletedModel {
tflog.Info(ctx, "Start flattenACLInListDeleted")
res := make([]models.ItemACLInListDeletedModel, 0, len(*acl))
for _, item := range *acl {
temp := models.ItemACLInListDeletedModel{
Explicit: types.BoolValue(bool(item.Explicit)),
GUID: types.StringValue(item.GUID),
Right: types.StringValue(item.Right),
Status: types.StringValue(item.Status),
Type: types.StringValue(item.Type),
UserGroupID: types.StringValue(item.UserGroupID),
}
res = append(res, temp)
}
tflog.Info(ctx, "End flattenACLInListDeleted")
return res
}
func flattenAffinityRuleInListDeleted(ctx context.Context, rules *compute.ListRules) []models.ItemRuleInListDeletedModel {
tflog.Info(ctx, "Start flattenAffinityRuleInListDeleted")
res := make([]models.ItemRuleInListDeletedModel, 0, len(*rules))
for _, item := range *rules {
temp := models.ItemRuleInListDeletedModel{
GUID: types.StringValue(item.GUID),
Key: types.StringValue(item.Key),
Mode: types.StringValue(item.Mode),
Policy: types.StringValue(item.Policy),
Topology: types.StringValue(item.Topology),
Value: types.StringValue(item.Value),
}
res = append(res, temp)
}
tflog.Info(ctx, "End flattenAffinityRuleInListDeleted")
return res
}
func flattenDisksInListDeleted(ctx context.Context, disks *compute.ListInfoDisks) []models.DiskInListDeletedModel {
tflog.Info(ctx, "Start flattenDisksInListDeleted")
res := make([]models.DiskInListDeletedModel, 0, len(*disks))
for _, item := range *disks {
temp := models.DiskInListDeletedModel{
DiskId: types.Int64Value(int64(item.ID)),
PCISlot: types.Int64Value(item.PCISlot),
}
res = append(res, temp)
}
tflog.Info(ctx, "End flattenDisksInListDeleted")
return res
}
func flattenInterfaceInListDeleted(ctx context.Context, interfaces *compute.ListInterfaces) []models.ItemVNFInterfaceInListDeletedModel {
tflog.Info(ctx, "Start flattenInterfaceInListDeleted")
var diags diag.Diagnostics
res := make([]models.ItemVNFInterfaceInListDeletedModel, 0, len(*interfaces))
for _, item := range *interfaces {
temp := models.ItemVNFInterfaceInListDeletedModel{
ConnID: types.Int64Value(int64(item.ConnID)),
ConnType: types.StringValue(item.ConnType),
DefGW: types.StringValue(item.DefGW),
Enabled: types.BoolValue(item.Enabled),
FLIPGroupID: types.Int64Value(int64(item.FLIPGroupID)),
GUID: types.StringValue(item.GUID),
IPAddress: types.StringValue(item.IPAddress),
ListenSSH: types.BoolValue(item.ListenSSH),
MAC: types.StringValue(item.MAC),
Name: types.StringValue(item.Name),
NetID: types.Int64Value(int64(item.NetID)),
NetMask: types.Int64Value(int64(item.NetMask)),
NetType: types.StringValue(item.NetType),
NodeID: types.Int64Value(int64(item.NodeID)),
PCISlot: types.Int64Value(item.PCISlot),
QOS: &models.QOSInListModel{
ERate: types.Int64Value(int64(item.QOS.ERate)),
GUID: types.StringValue(item.QOS.GUID),
InBurst: types.Int64Value(int64(item.QOS.InBurst)),
InRate: types.Int64Value(int64(item.QOS.InRate)),
},
Target: types.StringValue(item.Target),
Type: types.StringValue(item.Type),
}
temp.VNFs, diags = types.ListValueFrom(ctx, types.Int64Type, item.VNFs)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenInterfaceInListDeleted", diags))
}
res = append(res, temp)
}
tflog.Info(ctx, "End flattenInterfaceInListDeleted")
return res
}
func flattenSnapSetInListDeleted(ctx context.Context, snapSet *compute.ListSnapSets) []models.ItemSnapSetInListDeletedModel {
tflog.Info(ctx, "Start flattenSnapSetInListDeleted")
var diags diag.Diagnostics
res := make([]models.ItemSnapSetInListDeletedModel, 0, len(*snapSet))
for _, item := range *snapSet {
temp := models.ItemSnapSetInListDeletedModel{
GUID: types.StringValue(item.GUID),
Label: types.StringValue(item.Label),
Timestamp: types.Int64Value(int64(item.Timestamp)),
}
temp.Disks, diags = types.ListValueFrom(ctx, types.Int64Type, item.Disks)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenSnapSetInListDeleted", diags))
}
res = append(res, temp)
}
tflog.Info(ctx, "End flattenSnapSetInListDeleted")
return res
}

View File

@@ -0,0 +1,71 @@
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/cloudapi/compute"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/kvmvm/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/kvmvm/utilities"
)
func DataSourceComputePciDeviceList(ctx context.Context, state *models.ListPCIDevicesModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start FlattenDataSourceComputePciDeviceList")
diags := diag.Diagnostics{}
pciDeviceList, err := utilities.ComputePciDeviceListCheckPresence(ctx, state, c)
if err != nil {
diags.AddError("Error get compute pci device list info", err.Error())
return diags
}
id := uuid.New()
*state = models.ListPCIDevicesModel{
ComputeID: state.ComputeID,
RGID: state.RGID,
DevID: state.DevID,
Name: state.Name,
Status: state.Status,
SortBy: state.SortBy,
Page: state.Page,
Size: state.Size,
Timeouts: state.Timeouts,
Id: types.StringValue(id.String()),
Items: flattenPCIDevice(ctx, pciDeviceList.Data),
EntryCount: types.Int64Value(int64(pciDeviceList.EntryCount)),
}
tflog.Info(ctx, "End FlattenDataSourceComputePciDeviceList")
return nil
}
func flattenPCIDevice(ctx context.Context, deviceList []compute.ItemPCIDevice) []models.ItemPCIDevice {
tflog.Info(ctx, "Start flattenPCIDevice")
res := make([]models.ItemPCIDevice, 0, len(deviceList))
for _, item := range deviceList {
temp := models.ItemPCIDevice{
ComputeID: types.Int64Value(int64(item.ComputeID)),
Description: types.StringValue(item.Description),
GUID: types.Int64Value(int64(item.GUID)),
HwPath: types.StringValue(item.HwPath),
ID: types.Int64Value(int64(item.ID)),
Name: types.StringValue(item.Name),
RGID: types.Int64Value(int64(item.RGID)),
StackID: types.Int64Value(int64(item.StackID)),
Status: types.StringValue(item.Status),
SystemName: types.StringValue(item.SystemName),
}
res = append(res, temp)
}
tflog.Info(ctx, "End flattenPCIDevice")
return res
}

View File

@@ -0,0 +1,60 @@
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/cloudapi/compute"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/kvmvm/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/kvmvm/utilities"
)
func DataSourceComputePFWList(ctx context.Context, state *models.ListPFWsModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start FlattenDataSourceComputePFWList")
diags := diag.Diagnostics{}
pfwList, err := utilities.ComputePFWListCheckPresence(ctx, state, c)
if err != nil {
diags.AddError("Error get compute pfw list info", err.Error())
return diags
}
id := uuid.New()
*state = models.ListPFWsModel{
ComputeID: state.ComputeID,
Timeouts: state.Timeouts,
Id: types.StringValue(id.String()),
Items: flattenItemsPFWList(ctx, pfwList),
EntryCount: types.Int64Value(int64(pfwList.EntryCount)),
}
tflog.Info(ctx, "End FlattenDataSourceComputePFWList")
return nil
}
func flattenItemsPFWList(ctx context.Context, pfw *compute.ListPFWs) []models.ItemPFWModel {
tflog.Info(ctx, "Start flattenItemsPFWList")
res := make([]models.ItemPFWModel, 0, len(pfw.Data))
for _, item := range pfw.Data {
temp := models.ItemPFWModel{
PFWId: types.Int64Value(int64(item.ID)),
LocalIP: types.StringValue(item.LocalIP),
LocalPort: types.Int64Value(int64(item.LocalPort)),
Protocol: types.StringValue(item.Protocol),
PublicPortEnd: types.Int64Value(int64(item.PublicPortEnd)),
PublicPortStart: types.Int64Value(int64(item.PublicPortStart)),
VMID: types.Int64Value(int64(item.VMID)),
}
res = append(res, temp)
}
tflog.Info(ctx, "End flattenItemsPFWList")
return res
}

View File

@@ -0,0 +1,57 @@
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/cloudapi/compute"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/kvmvm/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/kvmvm/utilities"
)
func DataSourceComputeSnapshotUsage(ctx context.Context, state *models.ListSnapShotsModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start FlattenDataSourceComputeSnapshotUsage")
diags := diag.Diagnostics{}
snapshotUsage, err := utilities.ComputeSnapshotUsageCheckPresence(ctx, state, c)
if err != nil {
diags.AddError("Error get compute snapshot usage info", err.Error())
return diags
}
id := uuid.New()
*state = models.ListSnapShotsModel{
ComputeID: state.ComputeID,
Label: state.Label,
Timeouts: state.Timeouts,
Id: types.StringValue(id.String()),
Items: flattenItemsSnapshotUsage(ctx, snapshotUsage),
}
tflog.Info(ctx, "End FlattenDataSourceComputeSnapshotUsage")
return nil
}
func flattenItemsSnapshotUsage(ctx context.Context, snapshot *compute.ListUsageSnapshots) []models.ItemUsageSnapshotModel {
tflog.Info(ctx, "Start flattenItemsSnapshotUsage")
res := make([]models.ItemUsageSnapshotModel, 0, len(*snapshot))
for _, item := range *snapshot {
temp := models.ItemUsageSnapshotModel{
Count: types.Int64Value(int64(item.Count)),
Stored: types.Float64Value(float64(item.Stored)),
Label: types.StringValue(item.Label),
Timestamp: types.Int64Value(int64(item.Timestamp)),
}
res = append(res, temp)
}
tflog.Info(ctx, "End flattenItemsSnapshotUsage")
return res
}

View File

@@ -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/decort-golang-sdk/pkg/cloudapi/compute"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/kvmvm/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/kvmvm/utilities"
)
func DataSourceComputeUserList(ctx context.Context, state *models.ListUsersModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start FlattenDataSourceComputeUserList")
diags := diag.Diagnostics{}
userList, err := utilities.ComputeUserListCheckPresence(ctx, state, c)
if err != nil {
diags.AddError("Error get compute user list info", err.Error())
return diags
}
id := uuid.New()
*state = models.ListUsersModel{
ComputeID: state.ComputeID,
Timeouts: state.Timeouts,
Id: types.StringValue(id.String()),
Items: flattenUserList(ctx, userList),
EntryCount: types.Int64Value(int64(userList.EntryCount)),
}
tflog.Info(ctx, "End FlattenDataSourceComputeUserList")
return nil
}
func flattenUserList(ctx context.Context, users *compute.ListUsers) *models.RecordACLInListUsersModel {
tflog.Info(ctx, "Start flattenUserList")
res := models.RecordACLInListUsersModel{
AccountACL: flattenACLInUserList(ctx, &users.Data.AccountACL),
ComputeACL: flattenACLInUserList(ctx, &users.Data.ComputeACL),
RGACL: flattenACLInUserList(ctx, &users.Data.RGACL),
}
tflog.Info(ctx, "End flattenUserList")
return &res
}
func flattenACLInUserList(ctx context.Context, acl *compute.ListACL) []models.ItemACLInListUsersModel {
tflog.Info(ctx, "Start flattenACLInUserList")
res := make([]models.ItemACLInListUsersModel, 0, len(*acl))
for _, item := range *acl {
temp := models.ItemACLInListUsersModel{
Explicit: types.BoolValue(bool(item.Explicit)),
GUID: types.StringValue(item.GUID),
Right: types.StringValue(item.Right),
Status: types.StringValue(item.Status),
Type: types.StringValue(item.Type),
UserGroupID: types.StringValue(item.UserGroupID),
}
res = append(res, temp)
}
tflog.Info(ctx, "End flattenACLInUserList")
return res
}

View File

@@ -0,0 +1,78 @@
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/cloudapi/compute"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/kvmvm/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/kvmvm/utilities"
)
func DataSourceComputeVGPUList(ctx context.Context, state *models.ListVGPUsModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start FlattenDataSourceComputeVGPUList")
diags := diag.Diagnostics{}
vgpuList, err := utilities.ComputeVGPUListCheckPresence(ctx, state, c)
if err != nil {
diags.AddError("Error get compute vgpu list info", err.Error())
return diags
}
id := uuid.New()
*state = models.ListVGPUsModel{
ComputeID: state.ComputeID,
GPUID: state.GPUID,
Type: state.Type,
Status: state.Status,
SortBy: state.SortBy,
Page: state.Page,
Size: state.Size,
IncludeDeleted: state.IncludeDeleted,
Timeouts: state.Timeouts,
Id: types.StringValue(id.String()),
Items: flattenVGPU(ctx, vgpuList.Data),
EntryCount: types.Int64Value(int64(vgpuList.EntryCount)),
}
tflog.Info(ctx, "End FlattenDataSourceComputeVGPUList")
return nil
}
func flattenVGPU(ctx context.Context, vgpuList []compute.ItemVGPU) []models.ItemVGPU {
tflog.Info(ctx, "Start flattenVGPUItems")
res := make([]models.ItemVGPU, 0, len(vgpuList))
for _, item := range vgpuList {
temp := models.ItemVGPU{
AccountID: types.Int64Value(int64(item.AccountID)),
CreatedTime: types.Int64Value(int64(item.CreatedTime)),
DeletedTime: types.Int64Value(int64(item.DeletedTime)),
GID: types.Int64Value(int64(item.GID)),
GUID: types.Int64Value(int64(item.GUID)),
ID: types.Int64Value(int64(item.ID)),
LastClaimedBy: types.Int64Value(int64(item.LastClaimedBy)),
LastUpdateTime: types.Int64Value(int64(item.LastUpdateTime)),
Mode: types.StringValue(item.Mode),
PCISlot: types.Int64Value(int64(item.PCISlot)),
PGPUID: types.Int64Value(int64(item.PGPUID)),
ProfileID: types.Int64Value(int64(item.ProfileID)),
RAM: types.Int64Value(int64(item.RAM)),
ReferenceID: types.StringValue(item.ReferenceID),
RGID: types.Int64Value(int64(item.RGID)),
Status: types.StringValue(item.Status),
Type: types.StringValue(item.Type),
VMID: types.Int64Value(int64(item.VMID)),
}
res = append(res, temp)
}
tflog.Info(ctx, "End flattenVGPUItems")
return res
}

View File

@@ -0,0 +1,494 @@
package flattens
import (
"context"
"encoding/json"
"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/decort-golang-sdk/pkg/cloudapi/compute"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/flattens"
disks "repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/disks/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/kvmvm/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/kvmvm/utilities"
)
func ComputeResource(ctx context.Context, plan *models.ResourceComputeModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start flattens.ComputeResource")
diags := diag.Diagnostics{}
recordItemCompute, diags := utilities.ComputeResourceCheckPresence(ctx, plan, c)
if diags.HasError() {
return diags
}
bootdisk := findBootDisk(recordItemCompute.Disks)
devices, _ := json.Marshal(recordItemCompute.Devices)
userdata, _ := json.Marshal(recordItemCompute.Userdata)
customFields, _ := json.Marshal(recordItemCompute.CustomFields)
*plan = models.ResourceComputeModel{
// required fields
Name: plan.Name,
RGID: plan.RGID,
Driver: plan.Driver,
CPU: plan.CPU,
RAM: plan.RAM,
ID: plan.ID,
Timeouts: plan.Timeouts,
// optional fields
ImageID: plan.ImageID,
WithoutBootDisk: plan.WithoutBootDisk,
// we intentionally use the SizeMax field, do not change it until the BootDiskSize field is fixed on the platform
BootDiskSize: types.Int64Value(int64(bootdisk.SizeMax)),
AffinityLabel: types.StringValue(recordItemCompute.AffinityLabel),
AffinityRules: plan.AffinityRules,
AntiAffinityRules: plan.AntiAffinityRules,
CustomFields: types.StringValue(string(customFields)),
Stateless: plan.Stateless,
SepId: types.Int64Value(int64(bootdisk.SepID)),
Pool: types.StringValue(bootdisk.Pool),
ExtraDisks: plan.ExtraDisks,
Network: flattenNetwork(ctx, &recordItemCompute.Interfaces),
Tags: plan.Tags,
PortForwarding: plan.PortForwarding,
UserAccess: plan.UserAccess,
Snapshot: plan.Snapshot,
Rollback: plan.Rollback,
CD: plan.CD,
PinToStack: plan.PinToStack,
Description: types.StringValue(recordItemCompute.Description),
CloudInit: plan.CloudInit,
Enabled: plan.Enabled,
Pause: plan.Pause,
Reset: plan.Reset,
Restore: plan.Restore,
AutoStart: plan.AutoStart,
ForceStop: plan.ForceStop,
ForceResize: plan.ForceResize,
DataDisks: plan.DataDisks,
Started: plan.Started,
DetachDisks: plan.DetachDisks,
Permanently: plan.Permanently,
IS: plan.IS,
IpaType: plan.IpaType,
NumaAffinity: plan.NumaAffinity,
CPUPin: plan.CPUPin,
HPBacked: plan.HPBacked,
//computed fields
AccountId: types.Int64Value(int64(recordItemCompute.AccountID)),
AccountName: types.StringValue(recordItemCompute.AccountName),
ACL: flattenResourceACL(ctx, &recordItemCompute.ACL),
AffinityWeight: types.Int64Value(int64(recordItemCompute.AffinityWeight)),
Architecture: types.StringValue(recordItemCompute.Architecture),
BootOrder: flattens.FlattenSimpleTypeToList(ctx, types.StringType, recordItemCompute.BootOrder),
BootDisk: flattenDisk(ctx, bootdisk),
BootDiskId: types.Int64Value(int64(bootdisk.ID)),
CdImageId: types.Int64Value(int64(recordItemCompute.CdImageId)),
CloneReference: types.Int64Value(int64(recordItemCompute.CloneReference)),
Clones: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, recordItemCompute.Clones),
ComputeCIID: types.Int64Value(int64(recordItemCompute.ComputeCIID)),
ComputeId: types.Int64Value(int64(recordItemCompute.ID)),
CreatedBy: types.StringValue(recordItemCompute.CreatedBy),
CreatedTime: types.Int64Value(int64(recordItemCompute.CreatedTime)),
DeletedBy: types.StringValue(recordItemCompute.DeletedBy),
DeletedTime: types.Int64Value(int64(recordItemCompute.DeletedTime)),
Devices: types.StringValue(string(devices)),
Disks: flattenResourceDisks(ctx, &recordItemCompute.Disks),
GID: types.Int64Value(int64(recordItemCompute.GID)),
GUID: types.Int64Value(int64(recordItemCompute.GUID)),
ImageName: types.StringValue(recordItemCompute.ImageName),
Interfaces: flattenResourceInterfaces(ctx, &recordItemCompute.Interfaces),
LockStatus: types.StringValue(recordItemCompute.LockStatus),
ManagerID: types.Int64Value(int64(recordItemCompute.ManagerID)),
ManagerType: types.StringValue(recordItemCompute.ManagerType),
MigrationJob: types.Int64Value(int64(recordItemCompute.MigrationJob)),
Milestones: types.Int64Value(int64(recordItemCompute.Milestones)),
NatableVINSID: types.Int64Value(int64(recordItemCompute.NatableVINSID)),
NatableVINSIP: types.StringValue(recordItemCompute.NatableVINSIP),
NatableVINSName: types.StringValue(recordItemCompute.NatableVINSName),
NatableVINSNetwork: types.StringValue(recordItemCompute.NatableVINSNetwork),
NatableVINSNetworkName: types.StringValue(recordItemCompute.NatableVINSNetworkName),
NeedReboot: types.BoolValue(recordItemCompute.NeedReboot),
NumaNodeId: types.Int64Value(int64(recordItemCompute.NumaNodeId)),
OSUsers: flattenResourceOSUsers(ctx, &recordItemCompute.OSUsers),
Pinned: types.BoolValue(recordItemCompute.Pinned),
ReferenceID: types.StringValue(recordItemCompute.ReferenceID),
Registered: types.BoolValue(recordItemCompute.Registered),
ResName: types.StringValue(recordItemCompute.ResName),
ReservedNodeCpus: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, recordItemCompute.ReservedNodeCpus),
RGName: types.StringValue(recordItemCompute.RGName),
SnapSets: flattenSnapSets(ctx, &recordItemCompute.SnapSets),
StatelessSepID: types.Int64Value(int64(recordItemCompute.StatelessSepID)),
StatelessSepType: types.StringValue(recordItemCompute.StatelessSepType),
Status: types.StringValue(recordItemCompute.Status),
TechStatus: types.StringValue(recordItemCompute.TechStatus),
UpdatedBy: types.StringValue(recordItemCompute.UpdatedBy),
UpdatedTime: types.Int64Value(int64(recordItemCompute.UpdatedTime)),
UserManaged: types.BoolValue(recordItemCompute.UserManaged),
Userdata: types.StringValue(string(userdata)),
VGPUs: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, recordItemCompute.VGPUs),
VirtualImageID: types.Int64Value(int64(recordItemCompute.VirtualImageID)),
VirtualImageName: types.StringValue(recordItemCompute.VirtualImageName),
}
tflog.Info(ctx, "End flattens.ComputeResource", map[string]any{"id": plan.ID.ValueString()})
return nil
}
func findBootDisk(disks compute.ListComputeDisks) *compute.ItemComputeDisk {
for _, disk := range disks {
if disk.Type == "B" {
return &disk
}
}
return &compute.ItemComputeDisk{}
}
func flattenResourceACL(ctx context.Context, acl *compute.RecordACL) types.Object {
tflog.Info(ctx, "Start flattenACL")
temp := models.RecordResourceACLModel{
AccountACL: flattenACLItems(ctx, &acl.AccountACL),
ComputeACL: flattenACLItems(ctx, &acl.ComputeACL),
RGACL: flattenACLItems(ctx, &acl.RGACL),
}
res, err := types.ObjectValueFrom(ctx, models.ListACL, temp)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenACL struct to obj", err))
}
tflog.Info(ctx, "End flattenACL")
return res
}
func flattenACLItems(ctx context.Context, item *compute.ListACL) types.List {
tflog.Info(ctx, "Start flattenACLItems")
tempSlice := make([]types.Object, 0, len(*item))
for _, aclItem := range *item {
temp := models.ItemACLModel{
Explicit: types.BoolValue(bool(aclItem.Explicit)),
GUID: types.StringValue(aclItem.GUID),
Right: types.StringValue(aclItem.Right),
Status: types.StringValue(aclItem.Status),
Type: types.StringValue(aclItem.Type),
UserGroupID: types.StringValue(aclItem.UserGroupID),
}
obj, err := types.ObjectValueFrom(ctx, models.ItemACL, temp)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenACLItems struct to obj", err))
}
tempSlice = append(tempSlice, obj)
}
res, err := types.ListValueFrom(ctx, types.ObjectType{AttrTypes: models.ItemACL}, tempSlice)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenACLItems", err))
}
tflog.Info(ctx, "End flattenACLItems")
return res
}
func flattenDisk(ctx context.Context, disk *compute.ItemComputeDisk) types.Object {
tflog.Info(ctx, fmt.Sprintf("flattenDisk: start flatten disk with ID - %v", disk.ID))
acl, _ := json.Marshal(disk.ACL)
temp := models.ItemResourceDiskModel{
CKey: types.StringValue(disk.CKey),
ACL: types.StringValue(string(acl)),
AccountID: types.Int64Value(int64(disk.AccountID)),
BootPartition: types.Int64Value(int64(disk.BootPartition)),
CreatedTime: types.Int64Value(int64(disk.CreatedTime)),
DeletedTime: types.Int64Value(int64(disk.DeletedTime)),
Description: types.StringValue(disk.Description),
DestructionTime: types.Int64Value(int64(disk.DestructionTime)),
DiskPath: types.StringValue(disk.DiskPath),
GID: types.Int64Value(int64(disk.GID)),
GUID: types.Int64Value(int64(disk.GUID)),
ID: types.Int64Value(int64(disk.ID)),
ImageID: types.Int64Value(int64(disk.ImageID)),
Images: flattens.FlattenSimpleTypeToList(ctx, types.StringType, disk.Images),
IOTune: flattensIOTune(ctx, &disk.IOTune),
IQN: types.StringValue(disk.IQN),
Login: types.StringValue(disk.Login),
Milestones: types.Int64Value(int64(disk.Milestones)),
Name: types.StringValue(disk.Name),
Order: types.Int64Value(int64(disk.Order)),
Params: types.StringValue(disk.Params),
ParentID: types.Int64Value(int64(disk.ParentID)),
Passwd: types.StringValue(disk.Passwd),
Pool: types.StringValue(disk.Pool),
PCISlot: types.Int64Value(disk.PCISlot),
PresentTo: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, disk.PresentTo),
PurgeTime: types.Int64Value(int64(disk.PurgeTime)),
RealityDeviceNumber: types.Int64Value(int64(disk.RealityDeviceNumber)),
Replication: flattenDiskReplication(ctx, &disk.Replication),
ResID: types.StringValue(disk.ResID),
Role: types.StringValue(disk.Role),
SepID: types.Int64Value(int64(disk.SepID)),
Shareable: types.BoolValue(disk.Shareable),
SizeMax: types.Int64Value(int64(disk.SizeMax)),
SizeUsed: types.Float64Value(disk.SizeUsed),
Snapshots: flattenResourceSnapshotExtend(ctx, &disk.Snapshots),
Status: types.StringValue(disk.Status),
TechStatus: types.StringValue(disk.TechStatus),
Type: types.StringValue(disk.Type),
VMID: types.Int64Value(int64(disk.VMID)),
}
res, err := types.ObjectValueFrom(ctx, models.ItemDisk, temp)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenDisk struct to obj", err))
}
tflog.Info(ctx, fmt.Sprintf("flattenDisk: end flatten disk with ID - %v", disk.ID))
return res
}
func flattensIOTune(ctx context.Context, ioTune *compute.IOTune) types.Object {
tflog.Info(ctx, "Start flattensIOTune")
temp := models.IOTuneModel{
ReadBytesSec: types.Int64Value(int64(ioTune.ReadBytesSec)),
ReadBytesSecMax: types.Int64Value(int64(ioTune.ReadBytesSecMax)),
ReadIOPSSec: types.Int64Value(int64(ioTune.ReadIOPSSec)),
ReadIOPSSecMax: types.Int64Value(int64(ioTune.ReadIOPSSecMax)),
SizeIOPSSec: types.Int64Value(int64(ioTune.SizeIOPSSec)),
TotalBytesSec: types.Int64Value(int64(ioTune.TotalBytesSec)),
TotalBytesSecMax: types.Int64Value(int64(ioTune.TotalBytesSecMax)),
TotalIOPSSec: types.Int64Value(int64(ioTune.TotalIOPSSec)),
TotalIOPSSecMax: types.Int64Value(int64(ioTune.TotalIOPSSecMax)),
WriteBytesSec: types.Int64Value(int64(ioTune.WriteBytesSec)),
WriteBytesSecMax: types.Int64Value(int64(ioTune.WriteBytesSecMax)),
WriteIOPSSec: types.Int64Value(int64(ioTune.WriteIOPSSec)),
WriteIOPSSecMax: types.Int64Value(int64(ioTune.WriteIOPSSecMax)),
}
res, err := types.ObjectValueFrom(ctx, disks.ItemIOTune, temp)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattensIOTune struct to obj", err))
}
tflog.Info(ctx, "End flattensIOTune")
return res
}
func flattenDiskReplication(ctx context.Context, replication *compute.ItemReplication) types.Object {
tflog.Info(ctx, "Start flattenDiskReplication")
temp := models.ReplicationModel{
DiskID: types.Int64Value(int64(replication.DiskID)),
PoolID: types.StringValue(replication.PoolID),
Role: types.StringValue(replication.Role),
SelfVolumeID: types.StringValue(replication.SelfVolumeID),
StorageID: types.StringValue(replication.StorageID),
VolumeID: types.StringValue(replication.VolumeID),
}
res, err := types.ObjectValueFrom(ctx, models.ItemReplication, temp)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenDiskReplication struct to obj", err))
}
tflog.Info(ctx, "End flattenDiskReplication")
return res
}
func flattenResourceSnapshotExtend(ctx context.Context, snapshotList *compute.SnapshotExtendList) types.List {
tflog.Info(ctx, "Start flattenResourceSnapshotExtend")
tempSlice := make([]types.Object, 0, len(*snapshotList))
for _, snapshot := range *snapshotList {
temp := models.ItemSnapshotExtendModel{
GUID: types.StringValue(snapshot.GUID),
Label: types.StringValue(snapshot.Label),
ReferenceID: types.StringValue(snapshot.ReferenceID),
ResID: types.StringValue(snapshot.ResID),
SnapSetGUID: types.StringValue(snapshot.SnapSetGUID),
SnapSetTime: types.Int64Value(int64(snapshot.SnapSetTime)),
TimeStamp: types.Int64Value(int64(snapshot.TimeStamp)),
}
obj, err := types.ObjectValueFrom(ctx, models.ItemSnapshot, temp)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenResourceSnapshotExtend struct to obj", err))
}
tempSlice = append(tempSlice, obj)
}
res, err := types.ListValueFrom(ctx, types.ObjectType{AttrTypes: models.ItemSnapshot}, tempSlice)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenResourceSnapshotExtend", err))
}
tflog.Info(ctx, "End flattenResourceSnapshotExtend")
return res
}
func flattenResourceOSUsers(ctx context.Context, osUsersList *compute.ListOSUser) types.List {
tflog.Info(ctx, "Start flattensOSUsers")
tempSlice := make([]types.Object, 0, len(*osUsersList))
for _, osUser := range *osUsersList {
temp := models.ItemOSUserModel{
GUID: types.StringValue(osUser.GUID),
Login: types.StringValue(osUser.Login),
Password: types.StringValue(osUser.Password),
PubKey: types.StringValue(osUser.PubKey),
}
obj, err := types.ObjectValueFrom(ctx, models.ItemOSUsers, temp)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattensOSUsers struct to obj", err))
}
tempSlice = append(tempSlice, obj)
}
res, err := types.ListValueFrom(ctx, types.ObjectType{AttrTypes: models.ItemOSUsers}, tempSlice)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattensOSUsers", err))
}
tflog.Info(ctx, "End flattensOSUsers")
return res
}
func flattenResourceDisks(ctx context.Context, disksList *compute.ListComputeDisks) types.List {
tflog.Info(ctx, "Start flattenResourceDisks")
tempSlice := make([]types.Object, 0, len(*disksList))
for _, disk := range *disksList {
if disk.Type == "B" {
continue
}
temp := flattenDisk(ctx, &disk)
obj, err := types.ObjectValueFrom(ctx, models.ItemDisk, temp)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenResourceDisks struct to obj", err))
}
tempSlice = append(tempSlice, obj)
}
res, err := types.ListValueFrom(ctx, types.ObjectType{AttrTypes: models.ItemDisk}, tempSlice)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenResourceDisks", err))
}
tflog.Info(ctx, "End flattenResourceDisks")
return res
}
func flattenResourceInterfaces(ctx context.Context, interfaces *compute.ListInterfaces) types.List {
tflog.Info(ctx, "Start flattenResourceInterfaces")
tempSlice := make([]types.Object, 0, len(*interfaces))
for _, item := range *interfaces {
temp := models.ItemResourceInterfacesModel{
ConnID: types.Int64Value(int64(item.ConnID)),
ConnType: types.StringValue(item.ConnType),
GetGW: types.StringValue(item.DefGW),
Enabled: types.BoolValue(item.Enabled),
FLIPGroupID: types.Int64Value(int64(item.FLIPGroupID)),
GUID: types.StringValue(item.GUID),
IPAddress: types.StringValue(item.IPAddress),
ListenSSH: types.BoolValue(item.ListenSSH),
MAC: types.StringValue(item.MAC),
Name: types.StringValue(item.Name),
NetID: types.Int64Value(int64(item.NetID)),
NetMask: types.Int64Value(int64(item.NetMask)),
NetType: types.StringValue(item.NetType),
NodeID: types.Int64Value(int64(item.NodeID)),
PCISlot: types.Int64Value(item.PCISlot),
QOS: flattenQOS(ctx, &item.QOS),
Target: types.StringValue(item.Target),
Type: types.StringValue(item.Type),
VNFs: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, item.VNFs),
}
obj, err := types.ObjectValueFrom(ctx, models.ItemInterfaces, temp)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenResourceInterfaces struct to obj", err))
}
tempSlice = append(tempSlice, obj)
}
res, err := types.ListValueFrom(ctx, types.ObjectType{AttrTypes: models.ItemInterfaces}, tempSlice)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenResourceInterfaces", err))
}
tflog.Info(ctx, "End flattenInterfaces")
return res
}
func flattenQOS(ctx context.Context, QOS *compute.QOS) types.Object {
tflog.Info(ctx, "Start flattenQOS")
temp := models.QOSModel{
ERate: types.Int64Value(int64(QOS.ERate)),
GUID: types.StringValue(QOS.GUID),
InBurst: types.Int64Value(int64(QOS.InBurst)),
InRate: types.Int64Value(int64(QOS.InRate)),
}
res, err := types.ObjectValueFrom(ctx, models.ItemQos, temp)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenQOS struct to obj", err))
}
tflog.Info(ctx, "End flattenQOS")
return res
}
func flattenSnapSets(ctx context.Context, snapSets *compute.ListSnapSets) types.List {
tflog.Info(ctx, "Start flattenSnapSets")
tempSlice := make([]types.Object, 0, len(*snapSets))
for _, snapSet := range *snapSets {
temp := models.ItemSnapSetModel{
Disks: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, snapSet.Disks),
GUID: types.StringValue(snapSet.GUID),
Label: types.StringValue(snapSet.Label),
Timestamp: types.Int64Value(int64(snapSet.Timestamp)),
}
obj, err := types.ObjectValueFrom(ctx, models.ItemSnapSets, temp)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenSnapSets struct to obj", err))
}
tempSlice = append(tempSlice, obj)
}
res, err := types.ListValueFrom(ctx, types.ObjectType{AttrTypes: models.ItemSnapSets}, tempSlice)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenSnapSets", err))
}
tflog.Info(ctx, "End flattenSnapSets")
return res
}
func flattenNetwork(ctx context.Context, interfaces *compute.ListInterfaces) types.Set {
tflog.Info(ctx, "Start flattenNetwork")
tempSlice := make([]types.Object, 0, len(*interfaces))
for _, item := range *interfaces {
temp := models.ItemNetworkModel{
NetType: types.StringValue(item.NetType),
NetId: types.Int64Value(int64(item.NetID)),
IpAddress: types.StringValue(item.IPAddress),
Mac: types.StringValue(item.MAC),
}
obj, err := types.ObjectValueFrom(ctx, models.ItemNetwork, temp)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenNetwork struct to obj", err))
}
tempSlice = append(tempSlice, obj)
}
res, err := types.SetValueFrom(ctx, types.ObjectType{AttrTypes: models.ItemNetwork}, tempSlice)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenNetwork", err))
}
tflog.Info(ctx, "End flattenNetwork")
return res
}