This commit is contained in:
asteam
2025-07-01 13:44:09 +03:00
parent 5382579a5f
commit ddbb12996d
1041 changed files with 2842 additions and 96448 deletions

View File

@@ -51,6 +51,7 @@ func DataSourceCompute(ctx context.Context, state *models.RecordComputeModel, c
Chipset: types.StringValue(computeRecord.Chipset),
BootDiskSize: types.Int64Value(int64(computeRecord.BootDiskSize)),
BootOrder: flattens.FlattenSimpleTypeToList(ctx, types.StringType, &computeRecord.BootOrder),
BootType: types.StringValue(computeRecord.BootType),
CdImageId: types.Int64Value(int64(computeRecord.CdImageId)),
Clones: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &computeRecord.Clones),
CloneReference: types.Int64Value(int64(computeRecord.CloneReference)),
@@ -69,10 +70,12 @@ func DataSourceCompute(ctx context.Context, state *models.RecordComputeModel, c
GID: types.Int64Value(int64(computeRecord.GID)),
GUID: types.Int64Value(int64(computeRecord.GUID)),
HPBacked: types.BoolValue(computeRecord.HPBacked),
HotResize: types.BoolValue(computeRecord.HotResize),
ImageID: types.Int64Value(int64(computeRecord.ImageID)),
ImageName: types.StringValue(computeRecord.ImageName),
Interfaces: flattenInterfaces(ctx, &computeRecord.Interfaces),
LockStatus: types.StringValue(computeRecord.LockStatus),
LoaderType: types.StringValue(computeRecord.LoaderType),
ManagerID: types.Int64Value(int64(computeRecord.ManagerID)),
ManagerType: types.StringValue(computeRecord.ManagerType),
MigrationJob: types.Int64Value(int64(computeRecord.MigrationJob)),
@@ -84,32 +87,33 @@ func DataSourceCompute(ctx context.Context, state *models.RecordComputeModel, c
NatableVINSNetwork: types.StringValue(computeRecord.NatableVINSNetwork),
NatableVINSNetworkName: types.StringValue(computeRecord.NatableVINSNetworkName),
NeedReboot: types.BoolValue(computeRecord.NeedReboot),
NetworkInterfaceNaming: types.StringValue(computeRecord.NetworkInterfaceNaming),
NumaAffinity: types.StringValue(computeRecord.NumaAffinity),
NumaNodeId: types.Int64Value(int64(computeRecord.NumaNodeId)),
OSUsers: flattenOSUsers(ctx, &computeRecord.OSUsers),
Pinned: types.BoolValue(computeRecord.Pinned),
PreferredCPU: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &computeRecord.PreferredCPU),
PCIDevices: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, flattenPCI(ctx, pciDevicesList)),
RAM: types.Int64Value(int64(computeRecord.RAM)),
ReferenceID: types.StringValue(computeRecord.ReferenceID),
Registered: types.BoolValue(computeRecord.Registered),
ResName: types.StringValue(computeRecord.ResName),
ReservedNodeCpus: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &computeRecord.ReservedNodeCpus),
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),
VNCPassword: types.StringValue(computeRecord.VNCPassword),
VGPUs: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &computeRecord.VGPUs),
//Pinned: types.BoolValue(computeRecord.Pinned),
PreferredCPU: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &computeRecord.PreferredCPU),
PCIDevices: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, flattenPCI(ctx, pciDevicesList)),
RAM: types.Int64Value(int64(computeRecord.RAM)),
ReferenceID: types.StringValue(computeRecord.ReferenceID),
Registered: types.BoolValue(computeRecord.Registered),
ResName: types.StringValue(computeRecord.ResName),
ReservedNodeCpus: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &computeRecord.ReservedNodeCpus),
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),
VNCPassword: types.StringValue(computeRecord.VNCPassword),
VGPUs: flattenComputeVGPU(ctx, computeRecord.VGPUs),
}
state.Tags, diags = types.MapValueFrom(ctx, types.StringType, computeRecord.Tags)
@@ -232,23 +236,24 @@ func flattenDisks(ctx context.Context, disks *compute.ListComputeDisks) []models
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)),
ResID: types.StringValue(item.ResID),
Role: types.StringValue(item.Role),
SepID: types.Int64Value(int64(item.SepID)),
Shareable: types.BoolValue(item.Shareable),
SizeAvailable: types.Float64Value(item.SizeAvailable),
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)
temp.PresentTo, diags = types.MapValueFrom(ctx, types.Int64Type, item.PresentTo)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenDisks", diags))
}
@@ -387,3 +392,36 @@ func flattenPCI(ctx context.Context, pciList *compute.ListPCIDevices) []uint64 {
tflog.Info(ctx, "End flattenPCI")
return res
}
func flattenComputeVGPU(ctx context.Context, vgpuList []compute.VGPUItem) []models.VGPUModel {
tflog.Info(ctx, "Start flattenVGPU")
res := make([]models.VGPUModel, 0, len(vgpuList))
for _, item := range vgpuList {
temp := models.VGPUModel{
ID: types.Int64Value(int64(item.ID)),
GID: types.Int64Value(int64(item.GID)),
Type: types.StringValue(item.Type),
Mode: types.StringValue(item.Mode),
Status: types.StringValue(item.Status),
ProfileID: types.Int64Value(int64(item.ProfileID)),
RAM: types.Int64Value(int64(item.RAM)),
LastUpdateTime: types.Int64Value(int64(item.LastUpdateTime)),
CreatedTime: types.Int64Value(int64(item.CreatedTime)),
DeletedTime: types.Int64Value(int64(item.DeletedTime)),
VMID: types.Int64Value(int64(item.VMID)),
PGPUID: types.Int64Value(int64(item.PGPuid)),
ReferenceID: types.StringValue(item.ReferenceID),
AccountID: types.Int64Value(int64(item.AccountID)),
RGID: types.Int64Value(int64(item.RgID)),
LastClaimedBy: types.Int64Value(int64(item.LastClaimedBy)),
PCISlot: types.Int64Value(int64(item.PCISlot)),
BusNumber: types.Int64Value(int64(item.BusNumber)),
GUID: types.Int64Value(int64(item.GUID)),
}
res = append(res, temp)
}
tflog.Info(ctx, "End flattenVGPU")
return res
}

View File

@@ -65,69 +65,73 @@ func flattenItemsList(ctx context.Context, computes *compute.ListComputes) []mod
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),
AutoStartWithNode: types.BoolValue(item.AutoStart),
BootDiskSize: types.Int64Value(int64(item.BootDiskSize)),
BootOrder: flattens.FlattenSimpleTypeToList(ctx, types.StringType, &item.BootOrder),
CdImageId: types.Int64Value(int64(item.CdImageId)),
Clones: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &item.Clones),
CloneReference: types.Int64Value(int64(item.CloneReference)),
Chipset: types.StringValue(item.Chipset),
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),
PreferredCPU: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &item.PreferredCPU),
RAM: types.Int64Value(int64(item.RAM)),
ReferenceID: types.StringValue(item.ReferenceID),
Registered: types.BoolValue(item.Registered),
ResName: types.StringValue(item.ResName),
ReservedNodeCpus: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &item.ReservedNodeCpus),
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)),
VGPUs: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &item.VGPUs),
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),
AutoStartWithNode: types.BoolValue(item.AutoStart),
BootDiskSize: types.Int64Value(int64(item.BootDiskSize)),
BootOrder: flattens.FlattenSimpleTypeToList(ctx, types.StringType, &item.BootOrder),
BootType: types.StringValue(item.BootType),
CdImageId: types.Int64Value(int64(item.CdImageId)),
Clones: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &item.Clones),
CloneReference: types.Int64Value(int64(item.CloneReference)),
Chipset: types.StringValue(item.Chipset),
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),
HotResize: types.BoolValue(item.HotResize),
ComputeId: types.Int64Value(int64(item.ID)),
ImageID: types.Int64Value(int64(item.ImageID)),
Interfaces: flattenInterfaceInList(ctx, &item.Interfaces),
LockStatus: types.StringValue(item.LockStatus),
LoaderType: types.StringValue(item.LoaderType),
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),
NetworkInterfaceNaming: types.StringValue(item.NetworkInterfaceNaming),
NumaAffinity: types.StringValue(item.NumaAffinity),
NumaNodeId: types.Int64Value(int64(item.NumaNodeId)),
//Pinned: types.BoolValue(item.Pinned),
PreferredCPU: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &item.PreferredCPU),
RAM: types.Int64Value(int64(item.RAM)),
ReferenceID: types.StringValue(item.ReferenceID),
Registered: types.BoolValue(item.Registered),
ResName: types.StringValue(item.ResName),
ReservedNodeCpus: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &item.ReservedNodeCpus),
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)),
VGPUs: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &item.VGPUs),
}
temp.Tags, diags = types.MapValueFrom(ctx, types.StringType, item.Tags)
@@ -187,9 +191,9 @@ func flattenDisksInList(ctx context.Context, disks *compute.ListInfoDisks) []mod
res := make([]models.DiskInListModel, 0, len(*disks))
for _, item := range *disks {
temp := models.DiskInListModel{
BusNumber: types.Int64Value(int64(item.BusNumber)),
DiskId: types.Int64Value(int64(item.ID)),
PCISlot: types.Int64Value(item.PCISlot),
//BusNumber: types.Int64Value(int64(item.BusNumber)),
DiskId: types.Int64Value(int64(item.ID)),
//PCISlot: types.Int64Value(item.PCISlot),
}
res = append(res, temp)
}

View File

@@ -63,69 +63,73 @@ func flattenItemsListDeleted(ctx context.Context, computes *compute.ListComputes
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),
AutoStartWithNode: types.BoolValue(item.AutoStart),
BootDiskSize: types.Int64Value(int64(item.BootDiskSize)),
BootOrder: flattens.FlattenSimpleTypeToList(ctx, types.StringType, &item.BootOrder),
CdImageId: types.Int64Value(int64(item.CdImageId)),
Clones: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &item.Clones),
Chipset: types.StringValue(item.Chipset),
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),
PreferredCPU: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &item.PreferredCPU),
RAM: types.Int64Value(int64(item.RAM)),
ReferenceID: types.StringValue(item.ReferenceID),
Registered: types.BoolValue(item.Registered),
ResName: types.StringValue(item.ResName),
ReservedNodeCpus: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &item.ReservedNodeCpus),
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)),
VGPUs: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &item.VGPUs),
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),
AutoStartWithNode: types.BoolValue(item.AutoStart),
BootDiskSize: types.Int64Value(int64(item.BootDiskSize)),
BootOrder: flattens.FlattenSimpleTypeToList(ctx, types.StringType, &item.BootOrder),
BootType: types.StringValue(item.BootType),
CdImageId: types.Int64Value(int64(item.CdImageId)),
Clones: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &item.Clones),
Chipset: types.StringValue(item.Chipset),
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),
HotResize: types.BoolValue(item.HotResize),
ComputeId: types.Int64Value(int64(item.ID)),
ImageID: types.Int64Value(int64(item.ImageID)),
Interfaces: flattenInterfaceInListDeleted(ctx, &item.Interfaces),
LockStatus: types.StringValue(item.LockStatus),
LoaderType: types.StringValue(item.LoaderType),
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),
NetworkInterfaceNaming: types.StringValue(item.NetworkInterfaceNaming),
NumaAffinity: types.StringValue(item.NumaAffinity),
NumaNodeId: types.Int64Value(int64(item.NumaNodeId)),
//Pinned: types.BoolValue(item.Pinned),
PreferredCPU: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &item.PreferredCPU),
RAM: types.Int64Value(int64(item.RAM)),
ReferenceID: types.StringValue(item.ReferenceID),
Registered: types.BoolValue(item.Registered),
ResName: types.StringValue(item.ResName),
ReservedNodeCpus: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &item.ReservedNodeCpus),
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)),
VGPUs: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &item.VGPUs),
}
temp.Tags, diags = types.MapValueFrom(ctx, types.StringType, item.Tags)
@@ -185,9 +189,9 @@ func flattenDisksInListDeleted(ctx context.Context, disks *compute.ListInfoDisks
res := make([]models.DiskInListDeletedModel, 0, len(*disks))
for _, item := range *disks {
temp := models.DiskInListDeletedModel{
BusNumber: types.Int64Value(int64(item.BusNumber)),
DiskId: types.Int64Value(int64(item.ID)),
PCISlot: types.Int64Value(item.PCISlot),
//BusNumber: types.Int64Value(int64(item.BusNumber)),
DiskId: types.Int64Value(int64(item.ID)),
//PCISlot: types.Int64Value(item.PCISlot),
}
res = append(res, temp)
}

View File

@@ -25,6 +25,24 @@ func ComputeResource(ctx context.Context, plan *models.ResourceComputeModel, c *
if diags.HasError() {
return diags
}
pfwList, err := utilities.ComputeResourcePFWListGet(ctx, recordItemCompute.ID, c)
if err != nil {
if err != nil {
diags.AddError("ComputeResourcePFWListGet error: ", err.Error())
tflog.Error(ctx, fmt.Sprint("ComputeResourcePFWListGet error ", err))
}
}
userList, err := utilities.ComputeResourceUserAccessGet(ctx, recordItemCompute.ID, c)
if err != nil {
tflog.Error(ctx, fmt.Sprintf("Error getting user list: %v", err))
}
pciDevicesList, err := utilities.ResourceComputePCIDevicesListCheckPresence(ctx, recordItemCompute.ID, c)
if err != nil {
tflog.Error(ctx, fmt.Sprintf("Error getting pci list: %v", err))
}
bootdisk := findBootDisk(recordItemCompute.Disks)
devices, _ := json.Marshal(recordItemCompute.Devices)
userdata, _ := json.Marshal(recordItemCompute.Userdata)
@@ -32,57 +50,58 @@ func ComputeResource(ctx context.Context, plan *models.ResourceComputeModel, c *
*plan = models.ResourceComputeModel{
// required fields
Name: plan.Name,
RGID: plan.RGID,
Driver: plan.Driver,
CPU: plan.CPU,
RAM: plan.RAM,
ID: plan.ID,
Name: types.StringValue(recordItemCompute.Name),
RGID: types.Int64Value(int64(recordItemCompute.RGID)),
Driver: types.StringValue(recordItemCompute.Driver),
CPU: types.Int64Value(int64(recordItemCompute.CPU)),
RAM: types.Int64Value(int64(recordItemCompute.RAM)),
Timeouts: plan.Timeouts,
// optional fields
ImageID: plan.ImageID,
ImageID: types.Int64Value(int64(bootdisk.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,
AutoStartWithNode: types.BoolValue(recordItemCompute.AutoStart),
CustomFields: types.StringValue(string(customFields)),
Chipset: types.StringValue(recordItemCompute.Chipset),
Stateless: plan.Stateless,
SepId: types.Int64Value(int64(bootdisk.SepID)),
Pool: types.StringValue(bootdisk.Pool),
ExtraDisks: plan.ExtraDisks,
Network: flattenNetwork(ctx, plan.Network, &recordItemCompute.Interfaces),
Tags: plan.Tags,
PortForwarding: plan.PortForwarding,
UserAccess: plan.UserAccess,
Snapshot: plan.Snapshot,
PCIDevices: plan.PCIDevices,
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,
BootDiskSize: types.Int64Value(int64(bootdisk.SizeMax)),
AffinityLabel: types.StringValue(recordItemCompute.AffinityLabel),
AffinityRules: flattenComputeAffinityRule(ctx, &recordItemCompute.AffinityRules),
AntiAffinityRules: flattenComputeAffinityRule(ctx, &recordItemCompute.AntiAffinityRules),
AutoStartWithNode: types.BoolValue(recordItemCompute.AutoStart),
CustomFields: types.StringValue(string(customFields)),
Chipset: types.StringValue(recordItemCompute.Chipset),
SepId: types.Int64Value(int64(bootdisk.SepID)),
Pool: types.StringValue(bootdisk.Pool),
ExtraDisks: plan.ExtraDisks,
Network: flattenNetwork(ctx, plan.Network, &recordItemCompute.Interfaces),
Tags: flattenComputeTags(ctx, recordItemCompute.Tags),
PortForwarding: flattenComputePortForwarding(ctx, pfwList.Data),
UserAccess: flattenUserAccess(ctx, userList),
Snapshot: plan.Snapshot,
PCIDevices: flattens.FlattenSimpleTypeToSet(ctx, types.Int64Type, flattenPCIDevices(ctx, pciDevicesList)),
Rollback: plan.Rollback,
CDImageID: types.Int64Value(int64(recordItemCompute.CdImageId)),
PinToStack: types.BoolValue(recordItemCompute.PinnedToStack),
Description: types.StringValue(recordItemCompute.Description),
CloudInit: plan.CloudInit,
Enabled: types.BoolValue(recordItemCompute.Status == "ENABLED"),
Pause: types.BoolValue(recordItemCompute.TechStatus == "PAUSED"),
Reset: plan.Reset,
Restore: plan.Restore,
ForceStop: plan.ForceStop,
ForceResize: plan.ForceResize,
Started: types.BoolValue(recordItemCompute.TechStatus == "STARTED"),
DetachDisks: plan.DetachDisks,
Permanently: plan.Permanently,
IS: plan.IS,
IpaType: plan.IpaType,
NumaAffinity: types.StringValue(recordItemCompute.NumaAffinity),
CPUPin: types.BoolValue(recordItemCompute.CPUPin),
HPBacked: types.BoolValue(recordItemCompute.HPBacked),
SnapshotDeleteAsync: plan.SnapshotDeleteAsync,
LoaderType: types.StringValue(recordItemCompute.LoaderType),
BootType: types.StringValue(recordItemCompute.BootType),
HotResize: types.BoolValue(recordItemCompute.HotResize),
NetworkInterfaceNaming: types.StringValue(recordItemCompute.NetworkInterfaceNaming),
//computed fields
AccountId: types.Int64Value(int64(recordItemCompute.AccountID)),
AccountName: types.StringValue(recordItemCompute.AccountName),
@@ -92,7 +111,6 @@ func ComputeResource(ctx context.Context, plan *models.ResourceComputeModel, c *
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)),
@@ -105,6 +123,7 @@ func ComputeResource(ctx context.Context, plan *models.ResourceComputeModel, c *
Disks: flattenResourceDisks(ctx, &recordItemCompute.Disks),
GID: types.Int64Value(int64(recordItemCompute.GID)),
GUID: types.Int64Value(int64(recordItemCompute.GUID)),
ID: plan.ID,
ImageName: types.StringValue(recordItemCompute.ImageName),
Interfaces: flattenResourceInterfaces(ctx, &recordItemCompute.Interfaces),
LockStatus: types.StringValue(recordItemCompute.LockStatus),
@@ -120,7 +139,7 @@ func ComputeResource(ctx context.Context, plan *models.ResourceComputeModel, c *
NeedReboot: types.BoolValue(recordItemCompute.NeedReboot),
NumaNodeId: types.Int64Value(int64(recordItemCompute.NumaNodeId)),
OSUsers: flattenResourceOSUsers(ctx, &recordItemCompute.OSUsers),
Pinned: types.BoolValue(recordItemCompute.Pinned),
Pinned: types.BoolValue(recordItemCompute.PinnedToStack),
PreferredCPU: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, recordItemCompute.PreferredCPU),
ReferenceID: types.StringValue(recordItemCompute.ReferenceID),
Registered: types.BoolValue(recordItemCompute.Registered),
@@ -136,7 +155,7 @@ func ComputeResource(ctx context.Context, plan *models.ResourceComputeModel, c *
UpdatedTime: types.Int64Value(int64(recordItemCompute.UpdatedTime)),
UserManaged: types.BoolValue(recordItemCompute.UserManaged),
Userdata: types.StringValue(string(userdata)),
VGPUs: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, recordItemCompute.VGPUs),
VGPUs: flattenResourceComputeVGPU(ctx, recordItemCompute.VGPUs),
VirtualImageID: types.Int64Value(int64(recordItemCompute.VirtualImageID)),
VirtualImageName: types.StringValue(recordItemCompute.VirtualImageName),
VNCPassword: types.StringValue(recordItemCompute.VNCPassword),
@@ -204,9 +223,10 @@ func flattenACLItems(ctx context.Context, item *compute.ListACL) types.List {
func flattenDisk(ctx context.Context, disk *compute.ItemComputeDisk) types.Object {
tflog.Info(ctx, fmt.Sprintf("flattenDisk: start flatten disk with ID - %v", disk.ID))
diags := diag.Diagnostics{}
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)),
@@ -220,7 +240,7 @@ func flattenDisk(ctx context.Context, disk *compute.ItemComputeDisk) types.Objec
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),
Images: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, disk.Images),
IOTune: flattensIOTune(ctx, &disk.IOTune),
IQN: types.StringValue(disk.IQN),
Login: types.StringValue(disk.Login),
@@ -232,7 +252,6 @@ func flattenDisk(ctx context.Context, disk *compute.ItemComputeDisk) types.Objec
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),
@@ -249,9 +268,14 @@ func flattenDisk(ctx context.Context, disk *compute.ItemComputeDisk) types.Objec
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))
temp.PresentTo, diags = types.MapValueFrom(ctx, types.Int64Type, disk.PresentTo)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenPresentTo", diags))
}
res, diags := types.ObjectValueFrom(ctx, models.ItemDisk, temp)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenDisk struct to obj", diags))
}
tflog.Info(ctx, fmt.Sprintf("flattenDisk: end flatten disk with ID - %v", disk.ID))
@@ -537,3 +561,165 @@ func flattenNetworkWeight(ctx context.Context, networks types.Set, item compute.
tflog.Info(ctx, "End flattenNetworkWeight")
return types.Int64Value(0)
}
func flattenComputeAffinityRule(ctx context.Context, rules *compute.ListRules) types.Set {
tflog.Info(ctx, "Start flattenAffinityRule")
tempSlice := make([]types.Object, 0, len(*rules))
for _, item := range *rules {
temp := models.ItemResourceRulesModel{
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),
}
obj, err := types.ObjectValueFrom(ctx, models.ItemResourceRules, temp)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenComputeAffinityRule struct to obj", err))
}
tempSlice = append(tempSlice, obj)
}
res, err := types.SetValueFrom(ctx, types.ObjectType{AttrTypes: models.ItemResourceRules}, tempSlice)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenComputeAffinityRule", err))
}
tflog.Info(ctx, "End flattenAffinityRule")
return res
}
func flattenComputeTags(ctx context.Context, tags map[string]string) types.Set {
tflog.Info(ctx, "Start flattenComputeTags")
tempSlice := make([]types.Object, 0, len(tags))
for key, value := range tags {
temp := models.ItemTagModel{
Key: types.StringValue(key),
Value: types.StringValue(value),
}
obj, err := types.ObjectValueFrom(ctx, models.ItemTag, temp)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenComputeTags struct to obj", err))
}
tempSlice = append(tempSlice, obj)
}
res, err := types.SetValueFrom(ctx, types.ObjectType{AttrTypes: models.ItemTag}, tempSlice)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenComputeTags", err))
}
tflog.Info(ctx, "End flattenComputeTags")
return res
}
func flattenComputePortForwarding(ctx context.Context, list []compute.ItemPFW) types.Set {
tflog.Info(ctx, "Start flattenComputePortForwarding")
tempSlice := make([]types.Object, 0, len(list))
for _, item := range list {
temp := models.ItemPortForfardingModel{
PublicPortStart: types.Int64Value(int64(item.PublicPortStart)),
PublicPortEnd: types.Int64Value(int64(item.PublicPortEnd)),
LocalPort: types.Int64Value(int64(item.LocalPort)),
Proto: types.StringValue(item.Protocol),
}
obj, err := types.ObjectValueFrom(ctx, models.ItemPortForfarding, temp)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenComputePortForwarding struct to obj", err))
}
tempSlice = append(tempSlice, obj)
}
res, err := types.SetValueFrom(ctx, types.ObjectType{AttrTypes: models.ItemPortForfarding}, tempSlice)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenComputePortForwarding", err))
}
tflog.Info(ctx, "End flattenComputePortForwarding")
return res
}
func flattenUserAccess(ctx context.Context, userList *compute.ListUsers) types.Set {
tflog.Info(ctx, "Start flattenUserAccess")
tempSlice := make([]types.Object, 0)
// Process compute ACL
for _, item := range userList.Data.ComputeACL {
temp := models.UserAccessModel{
Username: types.StringValue(item.UserGroupID),
AccessType: types.StringValue(item.Right),
}
obj, diags := types.ObjectValueFrom(ctx, models.ItemUserAccess, temp)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenUserAccess struct to obj", diags))
continue
}
tempSlice = append(tempSlice, obj)
}
res, diags := types.SetValueFrom(ctx, types.ObjectType{AttrTypes: models.ItemUserAccess}, tempSlice)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenUserAccess", diags))
}
tflog.Info(ctx, "End flattenUserAccess")
return res
}
func flattenPCIDevices(ctx context.Context, pciList *compute.ListPCIDevices) []uint64 {
tflog.Info(ctx, "Start flattenPCI")
res := make([]uint64, 0, len(pciList.Data))
for _, v := range pciList.Data {
res = append(res, v.ID)
}
tflog.Info(ctx, "End flattenPCI")
return res
}
func flattenResourceComputeVGPU(ctx context.Context, vgpuList []compute.VGPUItem) types.List {
tflog.Info(ctx, "Start flattenVGPU")
tempSlice := make([]types.Object, 0, len(vgpuList))
for _, item := range vgpuList {
temp := models.ComputeVGPUModel{
ID: types.Int64Value(int64(item.ID)),
GID: types.Int64Value(int64(item.GID)),
Type: types.StringValue(item.Type),
Mode: types.StringValue(item.Mode),
Status: types.StringValue(item.Status),
ProfileID: types.Int64Value(int64(item.ProfileID)),
RAM: types.Int64Value(int64(item.RAM)),
LastUpdateTime: types.Int64Value(int64(item.LastUpdateTime)),
CreatedTime: types.Int64Value(int64(item.CreatedTime)),
DeletedTime: types.Int64Value(int64(item.DeletedTime)),
VMID: types.Int64Value(int64(item.VMID)),
PGPUID: types.Int64Value(int64(item.PGPuid)),
ReferenceID: types.StringValue(item.ReferenceID),
AccountID: types.Int64Value(int64(item.AccountID)),
RGID: types.Int64Value(int64(item.RgID)),
LastClaimedBy: types.Int64Value(int64(item.LastClaimedBy)),
PCISlot: types.Int64Value(int64(item.PCISlot)),
BusNumber: types.Int64Value(int64(item.BusNumber)),
GUID: types.Int64Value(int64(item.GUID)),
}
obj, err := types.ObjectValueFrom(ctx, models.ComputeItemVGPU, temp)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error converting VGPU model to object", err))
}
tempSlice = append(tempSlice, obj)
}
res, err := types.ListValueFrom(ctx, types.ObjectType{AttrTypes: models.ComputeItemVGPU}, tempSlice)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error creating VGPU list value", err))
}
tflog.Info(ctx, "End flattenVGPU")
return res
}