This commit is contained in:
2026-09-21 11:51:12 +03:00
parent 9cd93e4277
commit 2b229a84fb
240 changed files with 7735 additions and 3166 deletions

View File

@@ -80,8 +80,8 @@ func dataSourceDiskSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"blk_discard": {
Type: schema.TypeBool,
"discard": {
Type: schema.TypeString,
Computed: true,
},
"block_size": {
@@ -109,6 +109,22 @@ func dataSourceDiskSchemaMake() map[string]*schema.Schema {
},
},
},
"computes_read_only": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"compute_id": {
Type: schema.TypeString,
Computed: true,
},
"read_only": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},
"created_by": {
Type: schema.TypeString,
Computed: true,
@@ -431,6 +447,10 @@ func dataSourceDiskSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "Name of the snapshot",
},
"pool_name": {
Type: schema.TypeString,
Computed: true,
},
"res_id": {
Type: schema.TypeString,
Computed: true,

View File

@@ -152,8 +152,8 @@ func dataSourceDiskListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"blk_discard": {
Type: schema.TypeBool,
"discard": {
Type: schema.TypeString,
Computed: true,
},
"block_size": {
@@ -181,6 +181,22 @@ func dataSourceDiskListSchemaMake() map[string]*schema.Schema {
},
},
},
"computes_read_only": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"compute_id": {
Type: schema.TypeString,
Computed: true,
},
"read_only": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},
"created_by": {
Type: schema.TypeString,
Computed: true,
@@ -510,6 +526,10 @@ func dataSourceDiskListSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "Name of the snapshot",
},
"pool_name": {
Type: schema.TypeString,
Computed: true,
},
"res_id": {
Type: schema.TypeString,
Computed: true,

View File

@@ -155,8 +155,8 @@ func dataSourceDiskListUnattachedSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"blk_discard": {
Type: schema.TypeBool,
"discard": {
Type: schema.TypeString,
Computed: true,
},
"block_size": {
@@ -430,6 +430,10 @@ func dataSourceDiskListUnattachedSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "Name of the snapshot",
},
"pool_name": {
Type: schema.TypeString,
Computed: true,
},
"res_id": {
Type: schema.TypeString,
Computed: true,

View File

@@ -416,6 +416,10 @@ func dataSourceDiskReplicationSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "Name of the snapshot",
},
"pool_name": {
Type: schema.TypeString,
Computed: true,
},
"res_id": {
Type: schema.TypeString,
Computed: true,

View File

@@ -123,8 +123,8 @@ func dataSourceDiskDeletedListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"blk_discard": {
Type: schema.TypeBool,
"discard": {
Type: schema.TypeString,
Computed: true,
},
"block_size": {
@@ -152,6 +152,22 @@ func dataSourceDiskDeletedListSchemaMake() map[string]*schema.Schema {
},
},
},
"computes_read_only": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"compute_id": {
Type: schema.TypeString,
Computed: true,
},
"read_only": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},
"created_by": {
Type: schema.TypeString,
Computed: true,
@@ -481,6 +497,10 @@ func dataSourceDiskDeletedListSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "Name of the snapshot",
},
"pool_name": {
Type: schema.TypeString,
Computed: true,
},
"res_id": {
Type: schema.TypeString,
Computed: true,

View File

@@ -25,7 +25,7 @@ func flattenDiskListUnattached(ul *disks.ListDisksUnattached) []map[string]inter
"account_id": unattachedDisk.AccountID,
"account_name": unattachedDisk.AccountName,
"acl": string(unattachedDiskAcl),
"blk_discard": unattachedDisk.BLKDiscard,
"discard": unattachedDisk.Discard,
"block_size": unattachedDisk.BlockSize,
"boot_partition": unattachedDisk.BootPartition,
"created_time": unattachedDisk.CreatedTime,
@@ -79,10 +79,11 @@ func flattenDisk(d *schema.ResourceData, disk *disks.RecordDisk) {
d.Set("account_id", disk.AccountID)
d.Set("account_name", disk.AccountName)
d.Set("acl", string(diskAcl))
d.Set("blk_discard", disk.BLKDiscard)
d.Set("discard", disk.Discard)
d.Set("block_size", disk.BlockSize)
// d.Set("boot_partition", disk.BootPartition)
d.Set("computes", flattenDiskComputes(disk.Computes))
d.Set("computes_read_only", flattenDiskComputesReadOnly(disk.ComputesReadOnly))
d.Set("created_by", disk.CreatedBy)
d.Set("created_time", disk.CreatedTime)
d.Set("deleted_by", disk.DeletedBy)
@@ -206,6 +207,7 @@ func flattenDiskSnapshotList(sl disks.ListSnapshots) []interface{} {
temp := map[string]interface{}{
"guid": snapshot.GUID,
"label": snapshot.Label,
"pool_name": snapshot.PoolName,
"res_id": snapshot.ResID,
"snap_set_guid": snapshot.SnapSetGUID,
"snap_set_time": snapshot.SnapSetTime,
@@ -222,56 +224,57 @@ func flattenDiskList(dl *disks.ListDisks) []map[string]interface{} {
for _, disk := range dl.Data {
diskAcl, _ := json.Marshal(disk.ACL)
temp := map[string]interface{}{
"account_id": disk.AccountID,
"account_name": disk.AccountName,
"acl": string(diskAcl),
"blk_discard": disk.BLKDiscard,
"block_size": disk.BlockSize,
"computes": flattenDiskComputes(disk.Computes),
"created_by": disk.CreatedBy,
"created_time": disk.CreatedTime,
"deleted_by": disk.DeletedBy,
"deleted_time": disk.DeletedTime,
"desc": disk.Description,
"destruction_time": disk.DestructionTime,
"devicename": disk.DeviceName,
"gid": disk.GID,
"disk_id": disk.ID,
"image_id": disk.ImageID,
"images": disk.Images,
"independent": disk.Independent,
"iotune": flattenIOTune(disk.IOTune),
"machine_id": disk.MachineID,
"machine_name": disk.MachineName,
"milestones": disk.Milestones,
"disk_name": disk.Name,
"order": disk.Order,
"params": disk.Params,
"parent_id": disk.ParentID,
"pci_slot": disk.PCISlot,
"pool": disk.Pool,
"present_to": disk.PresentTo,
"provision": disk.Provision,
"purge_time": disk.PurgeTime,
"replication": flattenDiskReplication(disk.Replication),
"res_id": disk.ResID,
"res_name": disk.ResName,
"role": disk.Role,
"sep_id": disk.SepID,
"sep_type": disk.SepType,
"shareable": disk.Shareable,
"cache": disk.Cache,
"size_available": disk.SizeAvailable,
"size_max": disk.SizeMax,
"size_used": disk.SizeUsed,
"snapshots": flattenDiskSnapshotList(disk.Snapshots),
"status": disk.Status,
"storage_policy_id": disk.StoragePolicyID,
"tech_status": disk.TechStatus,
"vmid": disk.VMID,
"updated_by": disk.UpdatedBy,
"updated_time": disk.UpdatedTime,
"to_clean": disk.ToClean,
"account_id": disk.AccountID,
"account_name": disk.AccountName,
"acl": string(diskAcl),
"discard": disk.Discard,
"block_size": disk.BlockSize,
"computes": flattenDiskComputes(disk.Computes),
"computes_read_only": flattenDiskComputesReadOnly(disk.ComputesReadOnly),
"created_by": disk.CreatedBy,
"created_time": disk.CreatedTime,
"deleted_by": disk.DeletedBy,
"deleted_time": disk.DeletedTime,
"desc": disk.Description,
"destruction_time": disk.DestructionTime,
"devicename": disk.DeviceName,
"gid": disk.GID,
"disk_id": disk.ID,
"image_id": disk.ImageID,
"images": disk.Images,
"independent": disk.Independent,
"iotune": flattenIOTune(disk.IOTune),
"machine_id": disk.MachineID,
"machine_name": disk.MachineName,
"milestones": disk.Milestones,
"disk_name": disk.Name,
"order": disk.Order,
"params": disk.Params,
"parent_id": disk.ParentID,
"pci_slot": disk.PCISlot,
"pool": disk.Pool,
"present_to": disk.PresentTo,
"provision": disk.Provision,
"purge_time": disk.PurgeTime,
"replication": flattenDiskReplication(disk.Replication),
"res_id": disk.ResID,
"res_name": disk.ResName,
"role": disk.Role,
"sep_id": disk.SepID,
"sep_type": disk.SepType,
"shareable": disk.Shareable,
"cache": disk.Cache,
"size_available": disk.SizeAvailable,
"size_max": disk.SizeMax,
"size_used": disk.SizeUsed,
"snapshots": flattenDiskSnapshotList(disk.Snapshots),
"status": disk.Status,
"storage_policy_id": disk.StoragePolicyID,
"tech_status": disk.TechStatus,
"vmid": disk.VMID,
"updated_by": disk.UpdatedBy,
"updated_time": disk.UpdatedTime,
"to_clean": disk.ToClean,
}
res = append(res, temp)
}
@@ -311,3 +314,15 @@ func flattenDiskComputes(computes map[string]string) []map[string]interface{} {
}
return res
}
func flattenDiskComputesReadOnly(computesReadOnly map[string]bool) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for computeID, readOnly := range computesReadOnly {
temp := map[string]interface{}{
"compute_id": computeID,
"read_only": readOnly,
}
res = append(res, temp)
}
return res
}

View File

@@ -419,3 +419,12 @@ func resourceDiskV1() *schema.Resource {
},
}
}
func resourceDiskV2() *schema.Resource {
s := resourceDiskSchemaMake()
s["blk_discard"] = &schema.Schema{
Type: schema.TypeBool,
Computed: true,
}
return &schema.Resource{Schema: s}
}

View File

@@ -558,6 +558,22 @@ func resourceDiskSchemaMake() map[string]*schema.Schema {
},
},
},
"computes_read_only": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"compute_id": {
Type: schema.TypeString,
Computed: true,
},
"read_only": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
@@ -755,6 +771,10 @@ func resourceDiskSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "Name of the snapshot",
},
"pool_name": {
Type: schema.TypeString,
Computed: true,
},
"res_id": {
Type: schema.TypeString,
Computed: true,
@@ -805,10 +825,10 @@ func resourceDiskSchemaMake() map[string]*schema.Schema {
Type: schema.TypeBool,
Computed: true,
},
"blk_discard": {
Type: schema.TypeBool,
"discard": {
Type: schema.TypeString,
Computed: true,
Description: "Flag indicating whether blk-discard is enabled for the disk",
Description: "Discard mode of the disk",
},
"block_size": {
Type: schema.TypeString,
@@ -821,7 +841,7 @@ func resourceDiskSchemaMake() map[string]*schema.Schema {
func ResourceDisk() *schema.Resource {
return &schema.Resource{
SchemaVersion: 2,
SchemaVersion: 3,
CreateContext: resourceDiskCreate,
ReadContext: resourceDiskRead,
@@ -847,6 +867,11 @@ func ResourceDisk() *schema.Resource {
Upgrade: resourceDiskUpgradeV1,
Version: 1,
},
{
Type: resourceDiskV2().CoreConfigSchema().ImpliedType(),
Upgrade: resourceDiskUpgradeV2,
Version: 2,
},
},
}
}

View File

@@ -12,3 +12,17 @@ func resourceDiskUpgradeV1(ctx context.Context, rawState map[string]interface{},
return rawState, nil
}
func resourceDiskUpgradeV2(ctx context.Context, rawState map[string]interface{}, meta any) (map[string]interface{}, error) {
log.Debug("resourceDiskUpgradeV2: upgrading state")
if v, ok := rawState["blk_discard"].(bool); ok {
if v {
rawState["discard"] = "unmap"
} else {
rawState["discard"] = "ignore"
}
}
delete(rawState, "blk_discard")
return rawState, nil
}