This commit is contained in:
2025-05-21 16:38:25 +03:00
parent 2c70109d2d
commit 9e68edb2b9
1034 changed files with 73925 additions and 3187 deletions

View File

@@ -51,12 +51,12 @@ func dataSourceComputeListDeletedRead(ctx context.Context, d *schema.ResourceDat
result := computeList
if d.Get("ignore_k8s").(bool) {
// matches automatically generated names like "s234-g2134-c1" etc
result = matchComputes(computeList)
result = matchDeletedComputes(computeList)
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenComputeList(result))
d.Set("items", flattenDeletedComputeList(result))
d.Set("entry_count", computeList.EntryCount)
return nil

View File

@@ -75,7 +75,7 @@ func flattenCompute(d *schema.ResourceData, computeRec *compute.RecordCompute, p
d.Set("need_reboot", computeRec.NeedReboot)
d.Set("numa_node_id", computeRec.NumaNodeId)
d.Set("os_users", flattenOSUsers(computeRec.OSUsers))
d.Set("pinned", computeRec.Pinned)
d.Set("pinned", computeRec.PinnedToStack)
d.Set("preferred_cpu", computeRec.PreferredCPU)
d.Set("reference_id", computeRec.ReferenceID)
d.Set("registered", computeRec.Registered)
@@ -95,10 +95,14 @@ func flattenCompute(d *schema.ResourceData, computeRec *compute.RecordCompute, p
d.Set("user_data", string(userData))
d.Set("user_managed", computeRec.UserManaged)
d.Set("vnc_password", computeRec.VNCPassword)
d.Set("vgpus", computeRec.VGPUs)
d.Set("vgpus", flattenVGPUs(computeRec.VGPUs))
d.Set("virtual_image_id", computeRec.VirtualImageID)
d.Set("virtual_image_name", computeRec.VirtualImageName)
d.Set("pci_devices", flattenPCI(*pciList))
d.Set("loader_type", computeRec.LoaderType)
d.Set("boot_type", computeRec.BootType)
d.Set("hot_resize", computeRec.HotResize)
d.Set("network_interface_naming", computeRec.NetworkInterfaceNaming)
return nil
}
@@ -249,6 +253,7 @@ func flattenComputeDisks(disksList compute.ListDisks, disksBlocks, extraDisks []
"size_used": disk.SizeUsed,
"size_max": disk.SizeMax,
"permanently": pernamentlyValue,
"present_to": disk.PresentTo,
}
res = append(res, temp)
indexDataDisks++
@@ -289,73 +294,164 @@ func flattenComputeList(computes *compute.ListComputes) []map[string]interface{}
devices, _ := json.Marshal(computeItem.Devices)
userData, _ := json.Marshal(computeItem.Userdata)
temp := map[string]interface{}{
"acl": flattenListACLInterface(computeItem.ACL),
"account_id": computeItem.AccountID,
"account_name": computeItem.AccountName,
"affinity_label": computeItem.AffinityLabel,
"affinity_rules": flattenListRules(computeItem.AffinityRules),
"affinity_weight": computeItem.AffinityWeight,
"anti_affinity_rules": flattenListRules(computeItem.AntiAffinityRules),
"arch": computeItem.Arch,
"auto_start_w_node": computeItem.AutoStart,
"chipset": computeItem.Chipset,
"cd_image_id": computeItem.CdImageId,
"boot_order": computeItem.BootOrder,
"bootdisk_size": computeItem.BootDiskSize,
"clone_reference": computeItem.CloneReference,
"clones": computeItem.Clones,
"computeci_id": computeItem.ComputeCIID,
"cpus": computeItem.CPUs,
"created_by": computeItem.CreatedBy,
"created_time": computeItem.CreatedTime,
"custom_fields": string(customFields),
"deleted_by": computeItem.DeletedBy,
"deleted_time": computeItem.DeletedTime,
"desc": computeItem.Description,
"devices": string(devices),
"disks": flattenDisks(computeItem.Disks),
"driver": computeItem.Driver,
"gid": computeItem.GID,
"guid": computeItem.GUID,
"hp_backed": computeItem.HPBacked,
"compute_id": computeItem.ID,
"cpu_pin": computeItem.CPUPin,
"image_id": computeItem.ImageID,
"interfaces": flattenInterfaces(computeItem.Interfaces),
"lock_status": computeItem.LockStatus,
"manager_id": computeItem.ManagerID,
"manager_type": computeItem.ManagerType,
"migrationjob": computeItem.MigrationJob,
"milestones": computeItem.Milestones,
"name": computeItem.Name,
"need_reboot": computeItem.NeedReboot,
"numa_affinity": computeItem.NumaAffinity,
"numa_node_id": computeItem.NumaNodeId,
"os_users": flattenOSUsers(computeItem.OSUsers),
"pinned": computeItem.Pinned,
"preferred_cpu": computeItem.PreferredCPU,
"ram": computeItem.RAM,
"reference_id": computeItem.ReferenceID,
"registered": computeItem.Registered,
"res_name": computeItem.ResName,
"reserved_node_cpus": computeItem.ReservedNodeCpus,
"rg_id": computeItem.RGID,
"rg_name": computeItem.RGName,
"snap_sets": flattenSnapSets(computeItem.SnapSets),
"stack_id": computeItem.StackID,
"stateless_sep_id": computeItem.StatelessSEPID,
"stateless_sep_type": computeItem.StatelessSEPType,
"status": computeItem.Status,
"tags": flattenTags(computeItem.Tags),
"tech_status": computeItem.TechStatus,
"total_disk_size": computeItem.TotalDiskSize,
"updated_by": computeItem.UpdatedBy,
"updated_time": computeItem.UpdatedTime,
"user_data": string(userData),
"user_managed": computeItem.UserManaged,
"vgpus": computeItem.VGPUs,
"vins_connected": computeItem.VINSConnected,
"virtual_image_id": computeItem.VirtualImageID,
"acl": flattenListACLInterface(computeItem.ACL),
"account_id": computeItem.AccountID,
"account_name": computeItem.AccountName,
"affinity_label": computeItem.AffinityLabel,
"affinity_rules": flattenListRules(computeItem.AffinityRules),
"affinity_weight": computeItem.AffinityWeight,
"anti_affinity_rules": flattenListRules(computeItem.AntiAffinityRules),
"arch": computeItem.Arch,
"auto_start_w_node": computeItem.AutoStart,
"chipset": computeItem.Chipset,
"cd_image_id": computeItem.CdImageId,
"boot_order": computeItem.BootOrder,
"bootdisk_size": computeItem.BootDiskSize,
"clone_reference": computeItem.CloneReference,
"clones": computeItem.Clones,
"computeci_id": computeItem.ComputeCIID,
"cpus": computeItem.CPUs,
"created_by": computeItem.CreatedBy,
"created_time": computeItem.CreatedTime,
"custom_fields": string(customFields),
"deleted_by": computeItem.DeletedBy,
"deleted_time": computeItem.DeletedTime,
"desc": computeItem.Description,
"devices": string(devices),
"disks": flattenDisks(computeItem.Disks),
"driver": computeItem.Driver,
"gid": computeItem.GID,
"guid": computeItem.GUID,
"hp_backed": computeItem.HPBacked,
"compute_id": computeItem.ID,
"cpu_pin": computeItem.CPUPin,
"image_id": computeItem.ImageID,
"interfaces": flattenInterfaces(computeItem.Interfaces),
"lock_status": computeItem.LockStatus,
"manager_id": computeItem.ManagerID,
"manager_type": computeItem.ManagerType,
"migrationjob": computeItem.MigrationJob,
"milestones": computeItem.Milestones,
"nid": computeItem.NID,
"name": computeItem.Name,
"need_reboot": computeItem.NeedReboot,
"numa_affinity": computeItem.NumaAffinity,
"numa_node_id": computeItem.NumaNodeId,
"os_users": flattenOSUsers(computeItem.OSUsers),
"pinned": computeItem.PinnedToStack,
"preferred_cpu": computeItem.PreferredCPU,
"ram": computeItem.RAM,
"reference_id": computeItem.ReferenceID,
"registered": computeItem.Registered,
"res_name": computeItem.ResName,
"reserved_node_cpus": computeItem.ReservedNodeCpus,
"rg_id": computeItem.RGID,
"rg_name": computeItem.RGName,
"snap_sets": flattenSnapSets(computeItem.SnapSets),
"stack_id": computeItem.StackID,
"stack_name": computeItem.StackName,
"stateless_sep_id": computeItem.StatelessSEPID,
"stateless_sep_type": computeItem.StatelessSEPType,
"status": computeItem.Status,
"tags": flattenTags(computeItem.Tags),
"tech_status": computeItem.TechStatus,
"total_disk_size": computeItem.TotalDiskSize,
"updated_by": computeItem.UpdatedBy,
"updated_time": computeItem.UpdatedTime,
"user_data": string(userData),
"user_managed": computeItem.UserManaged,
"vgpus": computeItem.VGPUs,
"vins_connected": computeItem.VINSConnected,
"virtual_image_id": computeItem.VirtualImageID,
"loader_type": computeItem.LoaderType,
"boot_type": computeItem.BootType,
"hot_resize": computeItem.HotResize,
"network_interface_naming": computeItem.NetworkInterfaceNaming,
}
res = append(res, temp)
}
return res
}
func flattenDeletedComputeList(computes *compute.ListDeletedComputes) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(computes.Data))
for _, computeItem := range computes.Data {
customFields, _ := json.Marshal(computeItem.CustomFields)
devices, _ := json.Marshal(computeItem.Devices)
userData, _ := json.Marshal(computeItem.Userdata)
temp := map[string]interface{}{
"acl": flattenListACLInterface(computeItem.ACL),
"account_id": computeItem.AccountID,
"account_name": computeItem.AccountName,
"affinity_label": computeItem.AffinityLabel,
"affinity_rules": flattenListRules(computeItem.AffinityRules),
"affinity_weight": computeItem.AffinityWeight,
"anti_affinity_rules": flattenListRules(computeItem.AntiAffinityRules),
"arch": computeItem.Arch,
"auto_start_w_node": computeItem.AutoStart,
"chipset": computeItem.Chipset,
"cd_image_id": computeItem.CdImageId,
"boot_order": computeItem.BootOrder,
"bootdisk_size": computeItem.BootDiskSize,
"clone_reference": computeItem.CloneReference,
"clones": computeItem.Clones,
"computeci_id": computeItem.ComputeCIID,
"cpus": computeItem.CPUs,
"created_by": computeItem.CreatedBy,
"created_time": computeItem.CreatedTime,
"custom_fields": string(customFields),
"deleted_by": computeItem.DeletedBy,
"deleted_time": computeItem.DeletedTime,
"desc": computeItem.Description,
"devices": string(devices),
"disks": flattenDisks(computeItem.Disks),
"driver": computeItem.Driver,
"gid": computeItem.GID,
"guid": computeItem.GUID,
"hp_backed": computeItem.HPBacked,
"compute_id": computeItem.ID,
"cpu_pin": computeItem.CPUPin,
"image_id": computeItem.ImageID,
"interfaces": flattenInterfaces(computeItem.Interfaces),
"lock_status": computeItem.LockStatus,
"manager_id": computeItem.ManagerID,
"manager_type": computeItem.ManagerType,
"migrationjob": computeItem.MigrationJob,
"milestones": computeItem.Milestones,
"name": computeItem.Name,
"need_reboot": computeItem.NeedReboot,
"numa_affinity": computeItem.NumaAffinity,
"numa_node_id": computeItem.NumaNodeId,
"os_users": flattenOSUsers(computeItem.OSUsers),
"pinned": computeItem.PinnedToStack,
"preferred_cpu": computeItem.PreferredCPU,
"ram": computeItem.RAM,
"reference_id": computeItem.ReferenceID,
"registered": computeItem.Registered,
"res_name": computeItem.ResName,
"reserved_node_cpus": computeItem.ReservedNodeCpus,
"rg_id": computeItem.RGID,
"rg_name": computeItem.RGName,
"snap_sets": flattenSnapSets(computeItem.SnapSets),
"stack_id": computeItem.StackID,
"stack_name": computeItem.StackName,
"stateless_sep_id": computeItem.StatelessSEPID,
"stateless_sep_type": computeItem.StatelessSEPType,
"status": computeItem.Status,
"tags": flattenTags(computeItem.Tags),
"tech_status": computeItem.TechStatus,
"total_disk_size": computeItem.TotalDiskSize,
"updated_by": computeItem.UpdatedBy,
"updated_time": computeItem.UpdatedTime,
"user_data": string(userData),
"user_managed": computeItem.UserManaged,
"vgpus": computeItem.VGPUs,
"vins_connected": computeItem.VINSConnected,
"virtual_image_id": computeItem.VirtualImageID,
"loader_type": computeItem.LoaderType,
"boot_type": computeItem.BootType,
"hot_resize": computeItem.HotResize,
"network_interface_naming": computeItem.NetworkInterfaceNaming,
}
res = append(res, temp)
}
@@ -431,9 +527,9 @@ func flattenDisks(disks []compute.InfoDisk) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, disk := range disks {
temp := map[string]interface{}{
"bus_number": disk.BusNumber,
"disk_id": disk.ID,
"pci_slot": disk.PCISlot,
// "bus_number": disk.BusNumber,
"disk_id": disk.ID,
// "pci_slot": disk.PCISlot,
}
res = append(res, temp)
}
@@ -657,7 +753,7 @@ func flattenDataCompute(d *schema.ResourceData, compFacts *compute.RecordCompute
d.Set("numa_affinity", compFacts.NumaAffinity)
d.Set("numa_node_id", compFacts.NumaNodeId)
d.Set("os_users", flattenOSUsers(compFacts.OSUsers))
d.Set("pinned", compFacts.Pinned)
d.Set("pinned", compFacts.PinnedToStack)
d.Set("preferred_cpu", compFacts.PreferredCPU)
d.Set("ram", compFacts.RAM)
d.Set("reference_id", compFacts.ReferenceID)
@@ -679,10 +775,14 @@ func flattenDataCompute(d *schema.ResourceData, compFacts *compute.RecordCompute
d.Set("user_data", string(userData))
d.Set("user_managed", compFacts.UserManaged)
d.Set("vnc_password", compFacts.VNCPassword)
d.Set("vgpus", compFacts.VGPUs)
d.Set("vgpus", flattenVGPUs(compFacts.VGPUs))
d.Set("virtual_image_id", compFacts.VirtualImageID)
d.Set("virtual_image_name", compFacts.VirtualImageName)
d.Set("pci_devices", flattenPCI(*pciList))
d.Set("loader_type", compFacts.LoaderType)
d.Set("boot_type", compFacts.BootType)
d.Set("hot_resize", compFacts.HotResize)
d.Set("network_interface_naming", compFacts.NetworkInterfaceNaming)
//extra fields setting
bootDisk := findBootDisk(compFacts.Disks)
if bootDisk != nil {
@@ -771,6 +871,7 @@ func flattenDisk(diskList compute.ListDisks) []map[string]interface{} {
"role": disk.Role,
"sep_id": disk.SEPID,
"shareable": disk.Shareable,
"size_available": disk.SizeAvailable,
"size_max": disk.SizeMax,
"size_used": disk.SizeUsed,
"snapshots": flattendDiskSnapshotList(disk.Snapshots),
@@ -837,3 +938,34 @@ func flattendDiskSnapshotList(sl compute.ListDetailedSnapshots) []interface{} {
return res
}
func flattenVGPUs(vgpus []compute.VGPUItem) []map[string]interface{} {
res := make([]map[string]interface{}, len(vgpus))
for i, vgpu := range vgpus {
res[i] = map[string]interface{}{
"id": int(vgpu.ID),
"gid": int(vgpu.GID),
"type": vgpu.Type,
"mode": vgpu.Mode,
"status": vgpu.Status,
"profile_id": vgpu.ProfileID,
"ram": int(vgpu.RAM),
"last_update_time": int(vgpu.LastUpdateTime),
"created_time": int(vgpu.CreatedTime),
"deleted_time": int(vgpu.DeletedTime),
"vmid": int(vgpu.VMID),
"pgpuid": int(vgpu.PGPuid),
"reference_id": vgpu.ReferenceID,
"account_id": int(vgpu.AccountID),
"rg_id": int(vgpu.RgID),
"last_claimed_by": int(vgpu.LastClaimedBy),
"pci_slot": int(vgpu.PCISlot),
"bus_number": int(vgpu.BusNumber),
"guid": int(vgpu.GUID),
}
}
return res
}

File diff suppressed because it is too large Load Diff

View File

@@ -121,6 +121,11 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
reqInterface.IPAddr = ipaddr.(string)
}
macaddr, macSet := netInterfaceVal["mac"]
if macSet {
reqInterface.MAC = macaddr.(string)
}
interfacesX86 = append(interfacesX86, reqInterface)
}
createReqX86.Interfaces = interfacesX86
@@ -242,6 +247,38 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
log.Debugf("resourceComputeCreate: new simple Compute ID %d, name %s created", computeId, d.Get("name").(string))
updateReq := compute.UpdateRequest{}
loaderType, loaderTypeOk := d.GetOk("loader_type")
bootType, bootTypeOk := d.GetOk("boot_type")
hotResize, hotResizeOk := d.GetOk("hot_resize")
networkInterfaceNaming, networkInterfaceNamingOk := d.GetOk("network_interface_naming")
if loaderTypeOk {
updateReq.LoaderType = loaderType.(string)
}
if bootTypeOk {
updateReq.BootType = bootType.(string)
}
if hotResizeOk {
updateReq.HotResize = hotResize.(bool)
}
if networkInterfaceNamingOk {
updateReq.NetworkInterfaceNaming = networkInterfaceNaming.(string)
}
if loaderTypeOk || bootTypeOk || hotResizeOk || networkInterfaceNamingOk {
log.Debugf("resourceComputeCreate: change loaderType or bootType or hotResize or networkInterfaceNaming on ComputeID: %d", computeId)
updateReq.ComputeID = computeId
_, err := c.CloudBroker().Compute().Update(ctx, updateReq)
if err != nil {
warnings.Add(err)
}
}
if ars, ok := d.GetOk("pci_devices"); ok {
log.Debugf("resourceComputeCreate: add pci devices on ComputeID: %d", computeId)
addedPciDevices := ars.(*schema.Set).List()
@@ -352,9 +389,6 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
}
} else if ok && !start.(bool) {
req := compute.StopRequest{ComputeID: computeId}
if depresent, ok := d.Get("depresent").(bool); ok {
req.Depresent = depresent
}
log.Debugf("resourceComputeCreate: stoping Compute ID %d after completing its resource configuration", computeId)
if _, err := c.CloudBroker().Compute().Stop(ctx, req); err != nil {
warnings.Add(err)
@@ -713,7 +747,18 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
}
}
if d.HasChanges("description", "name", "numa_affinity", "cpu_pin", "hp_backed", "chipset", "auto_start_w_node", "preferred_cpu") {
if d.HasChanges("description",
"name",
"numa_affinity",
"cpu_pin",
"hp_backed",
"chipset",
"auto_start_w_node",
"preferred_cpu",
"loader_type",
"boot_type",
"hot_resize",
"network_interface_naming") {
if err := utilityComputeUpdate(ctx, d, m); err != nil {
return diag.FromErr(err)
}
@@ -874,7 +919,7 @@ func resourceComputeDelete(ctx context.Context, d *schema.ResourceData, m interf
func ResourceCompute() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
SchemaVersion: 2,
CustomizeDiff: func(ctx context.Context, diff *schema.ResourceDiff, i interface{}) error {
if diff.HasChanges() || diff.HasChanges("chipset", "pin_to_stack", "auto_start_w_node", "libvirt_settings", "network", "affinity_rules", "anti_affinity_rules",
@@ -911,5 +956,12 @@ func ResourceCompute() *schema.Resource {
},
Schema: resourceComputeSchemaMake(),
StateUpgraders: []schema.StateUpgrader{
{
Type: resourceComputeResourceV1().CoreConfigSchema().ImpliedType(),
Upgrade: resourceCompueteStateUpgradeV1,
Version: 1,
},
},
}
}

View File

@@ -391,7 +391,7 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
Computed: true,
},
"present_to": {
Type: schema.TypeList,
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
@@ -466,6 +466,10 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeBool,
Computed: true,
},
"size_available": {
Type: schema.TypeFloat,
Computed: true,
},
"size_max": {
Type: schema.TypeInt,
Computed: true,
@@ -789,7 +793,7 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
},
},
"pinned": {
Type: schema.TypeBool,
Type: schema.TypeInt,
Computed: true,
},
"preferred_cpu": {
@@ -918,10 +922,88 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
Computed: true,
},
"vgpus": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
Type: schema.TypeList,
Computed: true,
Description: "List of virtual GPUs",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
},
"gid": {
Type: schema.TypeInt,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
"mode": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"profile_id": {
Type: schema.TypeInt,
Computed: true,
},
"ram": {
Type: schema.TypeInt,
Computed: true,
},
"last_update_time": {
Type: schema.TypeInt,
Computed: true,
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"vmid": {
Type: schema.TypeInt,
Computed: true,
},
"pgpuid": {
Type: schema.TypeInt,
Computed: true,
},
"reference_id": {
Type: schema.TypeString,
Computed: true,
},
"account_id": {
Type: schema.TypeInt,
Computed: true,
},
"rg_id": {
Type: schema.TypeInt,
Computed: true,
},
"last_claimed_by": {
Type: schema.TypeInt,
Computed: true,
},
"pci_slot": {
Type: schema.TypeInt,
Computed: true,
},
"bus_number": {
Type: schema.TypeInt,
Computed: true,
},
"guid": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"virtual_image_id": {
@@ -949,6 +1031,22 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"loader_type": {
Type: schema.TypeString,
Computed: true,
},
"boot_type": {
Type: schema.TypeString,
Computed: true,
},
"hot_resize": {
Type: schema.TypeBool,
Computed: true,
},
"network_interface_naming": {
Type: schema.TypeString,
Computed: true,
},
}
return res
}
@@ -985,6 +1083,11 @@ func dataSourceComputeListSchemaMake() map[string]*schema.Schema {
Optional: true,
Description: "Find by tech status",
},
"stack_name": {
Type: schema.TypeString,
Optional: true,
Description: "Find by node name.",
},
"status": {
Type: schema.TypeString,
Optional: true,
@@ -1462,6 +1565,10 @@ func dataSourceComputeListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeBool,
Computed: true,
},
"nid": {
Type: schema.TypeInt,
Computed: true,
},
"numa_affinity": {
Type: schema.TypeString,
Computed: true,
@@ -1495,7 +1602,7 @@ func dataSourceComputeListSchemaMake() map[string]*schema.Schema {
},
},
"pinned": {
Type: schema.TypeBool,
Type: schema.TypeInt,
Computed: true,
},
"preferred_cpu": {
@@ -1567,6 +1674,11 @@ func dataSourceComputeListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"stack_name": {
Type: schema.TypeString,
Computed: true,
Description: "Find by node name.",
},
"stateless_sep_id": {
Type: schema.TypeInt,
Computed: true,
@@ -1634,6 +1746,22 @@ func dataSourceComputeListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"loader_type": {
Type: schema.TypeString,
Computed: true,
},
"boot_type": {
Type: schema.TypeString,
Computed: true,
},
"hot_resize": {
Type: schema.TypeBool,
Computed: true,
},
"network_interface_naming": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
@@ -1848,6 +1976,10 @@ func dataSourceComputeListDeletedSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"chipset": {
Type: schema.TypeString,
Computed: true,
},
"cd_image_id": {
Type: schema.TypeInt,
Computed: true,
@@ -1948,6 +2080,10 @@ func dataSourceComputeListDeletedSchemaMake() map[string]*schema.Schema {
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"bus_number": {
Type: schema.TypeInt,
Computed: true,
},
"conn_id": {
Type: schema.TypeInt,
Computed: true,
@@ -1984,6 +2120,10 @@ func dataSourceComputeListDeletedSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"mtu": {
Type: schema.TypeInt,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
@@ -2032,6 +2172,42 @@ func dataSourceComputeListDeletedSchemaMake() map[string]*schema.Schema {
},
},
},
"libvirt_settings": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"guid": {
Type: schema.TypeString,
Computed: true,
},
"txmode": {
Type: schema.TypeString,
Computed: true,
},
"ioeventfd": {
Type: schema.TypeString,
Computed: true,
},
"event_idx": {
Type: schema.TypeString,
Computed: true,
},
"queues": {
Type: schema.TypeInt,
Computed: true,
},
"rx_queue_size": {
Type: schema.TypeInt,
Computed: true,
},
"tx_queue_size": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"target": {
Type: schema.TypeString,
Computed: true,
@@ -2111,10 +2287,6 @@ func dataSourceComputeListDeletedSchemaMake() map[string]*schema.Schema {
},
},
"pinned": {
Type: schema.TypeBool,
Computed: true,
},
"ram": {
Type: schema.TypeInt,
Computed: true,
},
@@ -2125,6 +2297,10 @@ func dataSourceComputeListDeletedSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
},
},
"ram": {
Type: schema.TypeInt,
Computed: true,
},
"reference_id": {
Type: schema.TypeString,
Computed: true,
@@ -2183,6 +2359,11 @@ func dataSourceComputeListDeletedSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"stack_name": {
Type: schema.TypeString,
Computed: true,
Description: "Find by node name.",
},
"stateless_sep_id": {
Type: schema.TypeInt,
Computed: true,
@@ -2250,6 +2431,22 @@ func dataSourceComputeListDeletedSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"loader_type": {
Type: schema.TypeString,
Computed: true,
},
"boot_type": {
Type: schema.TypeString,
Computed: true,
},
"hot_resize": {
Type: schema.TypeBool,
Computed: true,
},
"network_interface_naming": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
@@ -3001,12 +3198,6 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "Optional text description of this compute instance.",
},
"depresent": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: "whether to depresent compute disks from node or not",
},
"started": {
Type: schema.TypeBool,
Optional: true,
@@ -3044,7 +3235,6 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeSet,
Optional: true,
MinItems: 1,
MaxItems: constants.MAX_NETWORKS_PER_COMPUTE,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"net_type": {
@@ -3067,9 +3257,11 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
Description: "Optional IP address to assign to this connection. This IP should belong to the selected network and free for use.",
},
"mac": {
Type: schema.TypeString,
Computed: true,
Description: "MAC address associated with this connection. MAC address is assigned automatically.",
Type: schema.TypeString,
Optional: true,
Computed: true,
DiffSuppressFunc: networkSubresIPAddreDiffSupperss,
Description: "MAC address associated with this connection. MAC address is assigned automatically.",
},
"weight": {
Type: schema.TypeInt,
@@ -3288,6 +3480,13 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "Disk ID",
},
"present_to": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"shareable": {
Type: schema.TypeBool,
Computed: true,
@@ -3306,7 +3505,6 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
"extra_disks": {
Type: schema.TypeSet,
Optional: true,
MaxItems: constants.MAX_EXTRA_DISKS_PER_COMPUTE,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
@@ -3507,6 +3705,33 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
},
Description: "ID of the connected pci devices",
},
"loader_type": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{"linux", "windows", "unknown"}, false),
Description: "Type of image vm.",
},
"boot_type": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{"bios", "uefi"}, false),
Description: "Type of image upload.",
},
"hot_resize": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "Type of image vm.",
},
"network_interface_naming": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{"eth", "ens"}, false),
Description: "Name of netfowrk interface.",
},
// Computed properties
"account_id": {
Type: schema.TypeInt,
@@ -3858,7 +4083,7 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
Description: "Guest OS users provisioned on this compute instance.",
},
"pinned": {
Type: schema.TypeBool,
Type: schema.TypeInt,
Computed: true,
},
"reference_id": {
@@ -3950,10 +4175,88 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
Computed: true,
},
"vgpus": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
Type: schema.TypeList,
Computed: true,
Description: "List of virtual GPUs",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
},
"gid": {
Type: schema.TypeInt,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
"mode": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"profile_id": {
Type: schema.TypeInt,
Computed: true,
},
"ram": {
Type: schema.TypeInt,
Computed: true,
},
"last_update_time": {
Type: schema.TypeInt,
Computed: true,
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"vmid": {
Type: schema.TypeInt,
Computed: true,
},
"pgpuid": {
Type: schema.TypeInt,
Computed: true,
},
"reference_id": {
Type: schema.TypeString,
Computed: true,
},
"account_id": {
Type: schema.TypeInt,
Computed: true,
},
"rg_id": {
Type: schema.TypeInt,
Computed: true,
},
"last_claimed_by": {
Type: schema.TypeInt,
Computed: true,
},
"pci_slot": {
Type: schema.TypeInt,
Computed: true,
},
"bus_number": {
Type: schema.TypeInt,
Computed: true,
},
"guid": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"virtual_image_id": {

View File

@@ -0,0 +1,20 @@
package kvmvm
import (
"context"
log "github.com/sirupsen/logrus"
)
func resourceCompueteStateUpgradeV1(ctx context.Context, rawState map[string]interface{}, meta any) (map[string]interface{}, error) {
log.Debug("resourceCompueteStateUpgradeV1: upgrading state")
if oldVal, ok := rawState["pinned"].(bool); ok {
if !oldVal {
rawState["pinned"] = -1
} else {
rawState["pinned"] = 0
}
}
return rawState, nil
}

View File

@@ -100,9 +100,6 @@ func utilityComputeStarted(ctx context.Context, d *schema.ResourceData, m interf
if force, ok := d.Get("force_stop").(bool); ok {
req.Force = force
}
if depresent, ok := d.Get("depresent").(bool); ok {
req.Depresent = depresent
}
if _, err := c.CloudBroker().Compute().Stop(ctx, req); err != nil {
return err
}
@@ -267,10 +264,6 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
Force: false,
}
if depresent, ok := d.Get("depresent").(bool); ok {
stopReq.Depresent = depresent
}
_, err := c.CloudBroker().Compute().Stop(ctx, stopReq)
if err != nil {
return err
@@ -474,19 +467,6 @@ func utilityComputeExtraDisksConfigure(ctx context.Context, d *schema.ResourceDa
if detach_set.Len() > 0 {
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
stopReq := compute.StopRequest{
ComputeID: computeId,
Force: false,
}
if depresent, ok := d.Get("depresent").(bool); ok {
stopReq.Depresent = depresent
}
_, err := c.CloudBroker().Compute().Stop(ctx, stopReq)
if err != nil {
return err
}
for _, diskId := range detach_set.List() {
req := compute.DiskDetachRequest{
@@ -501,14 +481,6 @@ func utilityComputeExtraDisksConfigure(ctx context.Context, d *schema.ResourceDa
}
}
req := compute.StartRequest{
ComputeID: computeId,
AltBootID: 0,
}
_, err = c.CloudBroker().Compute().Start(ctx, req)
if err != nil {
return err
}
}
attach_set := new_set.(*schema.Set).Difference(old_set.(*schema.Set))
@@ -601,7 +573,7 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
oldList := oldSet.(*schema.Set).List()
newList := newSet.(*schema.Set).List()
detachMap, changeIpMap, attachMap := differenceNetwork(oldList, newList)
detachMap, changeIpMap, changeMacMap, attachMap := differenceNetwork(oldList, newList)
apiErrCount := 0
var lastSavedError error
@@ -649,7 +621,7 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
addedLibvirtSettings := (newLibvirtSet.(*schema.Set).Difference(oldLibvirtSet.(*schema.Set))).List()
libvirtSettingsMap := addAttachedNetwork(addedLibvirtSettings, newLibvirtSet.(*schema.Set).List(), attachMap)
if oldSet.(*schema.Set).Len() == len(detachMap) || oldSet.(*schema.Set).Len() == 0 || len(libvirtSettingsMap) > 0 || hasDPDKnetwork(attachMap) {
if oldSet.(*schema.Set).Len() == len(detachMap) || oldSet.(*schema.Set).Len() == 0 || len(libvirtSettingsMap) > 0 || hasDPDKnetwork(attachMap) || len(changeMacMap) > 0 {
if err := utilityComputeStop(ctx, d, m); err != nil {
apiErrCount++
lastSavedError = err
@@ -659,6 +631,24 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
}
}
log.Debugf("utilityComputeNetworksConfigure: changeMac set has %d items for Compute ID %s", len(changeMacMap), d.Id())
for _, netData := range changeMacMap {
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
req := compute.ChangeMACRequest{
ComputeID: computeId,
NewMAC: netData["mac"].(string),
СurrentMAC: netData["old_mac"].(string),
}
_, err := c.CloudBroker().Compute().ChangeMAC(ctx, req)
if err != nil {
log.Errorf("utilityComputeNetworksConfigure: failed to change mac %s to %s from Compute ID %s: %s",
req.СurrentMAC, req.NewMAC, d.Id(), err)
apiErrCount++
lastSavedError = err
}
}
sort.Slice(attachMap, func(i, j int) bool {
weightI := attachMap[i]["weight"].(int)
weightJ := attachMap[j]["weight"].(int)
@@ -687,6 +677,10 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
req.IPAddr = netData["ip_address"].(string)
}
if netData["mac"].(string) != "" {
req.MACAddr = netData["mac"].(string)
}
_, err := c.CloudBroker().Compute().NetAttach(ctx, req)
if err != nil {
log.Errorf("utilityComputeNetworksConfigure: failed to attach net ID %d of type %s to Compute ID %s: %s",
@@ -758,9 +752,10 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
return nil
}
func differenceNetwork(oldList, newList []interface{}) (detachMap, changeIpMap, attachMap []map[string]interface{}) {
func differenceNetwork(oldList, newList []interface{}) (detachMap, changeIpMap, changeMacMap, attachMap []map[string]interface{}) {
attachMap = make([]map[string]interface{}, 0)
changeIpMap = make([]map[string]interface{}, 0)
changeMacMap = make([]map[string]interface{}, 0)
detachMap = make([]map[string]interface{}, 0)
for _, oldNetwork := range oldList {
oldMap := oldNetwork.(map[string]interface{})
@@ -768,15 +763,21 @@ func differenceNetwork(oldList, newList []interface{}) (detachMap, changeIpMap,
for _, newNetwork := range newList {
newMap := newNetwork.(map[string]interface{})
if newMap["net_type"] == oldMap["net_type"] && newMap["net_id"] == oldMap["net_id"] && newMap["weight"] == oldMap["weight"] && (newMap["mtu"] == oldMap["mtu"] || newMap["mtu"].(int) == 0) {
if (newMap["net_type"].(string) == "EXTNET" || newMap["net_type"].(string) == "VINS") && (newMap["ip_address"] != oldMap["ip_address"] && newMap["ip_address"].(string) != "") {
found = true
switch {
case (newMap["net_type"].(string) == "EXTNET" || newMap["net_type"].(string) == "VINS") && (newMap["ip_address"] != oldMap["ip_address"] && newMap["ip_address"].(string) != ""):
changeIpMap = append(changeIpMap, newMap)
found = true
break
} else if newMap["ip_address"] == oldMap["ip_address"] || newMap["ip_address"].(string) == "" {
fallthrough
case newMap["mac"] != oldMap["mac"] && newMap["mac"].(string) != "":
newMap["old_mac"] = oldMap["mac"]
changeMacMap = append(changeMacMap, newMap)
found = true
break
}
}
if found {
break
}
}
if found {
continue
@@ -790,12 +791,8 @@ func differenceNetwork(oldList, newList []interface{}) (detachMap, changeIpMap,
for _, oldNetwork := range oldList {
oldMap := oldNetwork.(map[string]interface{})
if newMap["net_type"] == oldMap["net_type"] && newMap["net_id"] == oldMap["net_id"] && newMap["weight"] == oldMap["weight"] && (newMap["mtu"] == oldMap["mtu"] || newMap["mtu"].(int) == 0) {
if newMap["ip_address"] == oldMap["ip_address"] || newMap["ip_address"].(string) == "" ||
((newMap["net_type"].(string) == "EXTNET" || newMap["net_type"].(string) == "VINS") &&
newMap["ip_address"] != oldMap["ip_address"] && newMap["ip_address"].(string) != "") {
found = true
break
}
found = true
break
}
}
if found {
@@ -871,6 +868,23 @@ func utilityComputeUpdate(ctx context.Context, d *schema.ResourceData, m interfa
if d.HasChange("chipset") {
req.Chipset = d.Get("chipset").(string)
}
if d.HasChange("loader_type") {
req.LoaderType = d.Get("loader_type").(string)
}
if d.HasChange("boot_type") {
req.BootType = d.Get("boot_type").(string)
}
if d.HasChange("hot_resize") {
req.HotResize = d.Get("hot_resize").(bool)
}
if d.HasChange("network_interface_naming") {
req.NetworkInterfaceNaming = d.Get("network_interface_naming").(string)
}
req.CPUPin = d.Get("cpu_pin").(bool)
req.HPBacked = d.Get("hp_backed").(bool)
req.AutoStart = d.Get("auto_start_w_node").(bool)
@@ -902,9 +916,7 @@ func utilityComputeUpdate(ctx context.Context, d *schema.ResourceData, m interfa
ComputeID: computeId,
Force: false,
}
if depresent, ok := d.Get("depresent").(bool); ok {
stopReq.Depresent = depresent
}
if _, err := c.CloudBroker().Compute().Stop(ctx, stopReq); err != nil {
return err
}
@@ -1368,9 +1380,6 @@ func utilityComputeRollback(ctx context.Context, d *schema.ResourceData, m inter
ComputeID: computeId,
Force: false,
}
if depresent, ok := d.Get("depresent").(bool); ok {
req.Depresent = depresent
}
_, err := c.CloudBroker().Compute().Stop(ctx, req)
if err != nil {
@@ -1531,9 +1540,6 @@ func utilityComputeUpdateImage(ctx context.Context, d *schema.ResourceData, m in
ComputeID: computeId,
Force: false,
}
if depresent, ok := d.Get("depresent").(bool); ok {
stopReq.Depresent = depresent
}
if forceStop, ok := d.GetOk("force_stop"); ok {
stopReq.Force = forceStop.(bool)
}
@@ -1608,9 +1614,6 @@ func utilityComputeStop(ctx context.Context, d *schema.ResourceData, m interface
Force: true,
}
req.ComputeID = uint64(d.Get("compute_id").(int))
if depresent, ok := d.Get("depresent").(bool); ok {
req.Depresent = depresent
}
log.Debugf("utilityComputeStop: stopping compute %d", req.ComputeID)
_, err := c.CloudBroker().Compute().Stop(ctx, req)

View File

@@ -72,6 +72,9 @@ func utilityDataComputeListCheckPresence(ctx context.Context, d *schema.Resource
if stackID, ok := d.GetOk("stack_id"); ok {
req.StackID = stackID.(uint64)
}
if stackName, ok := d.GetOk("stack_name"); ok {
req.StackName = stackName.(string)
}
if imageID, ok := d.GetOk("image_id"); ok {
req.ImageID = imageID.(uint64)
}

View File

@@ -34,13 +34,14 @@ package kvmvm
import (
"context"
"regexp"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityDataComputeListDeletedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*compute.ListComputes, error) {
func utilityDataComputeListDeletedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*compute.ListDeletedComputes, error) {
c := m.(*controller.ControllerCfg)
req := compute.ListDeletedRequest{}
@@ -88,3 +89,12 @@ func utilityDataComputeListDeletedCheckPresence(ctx context.Context, d *schema.R
return listComputes, nil
}
func matchDeletedComputes(computeList *compute.ListDeletedComputes) *compute.ListDeletedComputes {
matched, _ := regexp.Compile(`[a-zA-Z]+\\d+-[a-zA-Z]+\\d+-[a-zA-Z]+\\d+`)
result := computeList.FilterFunc(func(ic compute.ItemDeletedCompute) bool {
res := matched.Match([]byte(ic.Name))
return !res
})
return &result
}