You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
282 lines
9.9 KiB
282 lines
9.9 KiB
package disks
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/disks"
|
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens"
|
|
)
|
|
|
|
func flattenDisk(d *schema.ResourceData, disk *disks.RecordDisk) {
|
|
diskAcl, _ := json.Marshal(disk.ACL)
|
|
|
|
d.Set("account_id", disk.AccountID)
|
|
d.Set("account_name", disk.AccountName)
|
|
d.Set("acl", string(diskAcl))
|
|
d.Set("boot_partition", disk.BootPartition)
|
|
d.Set("computes", flattenDiskComputes(disk.Computes))
|
|
d.Set("created_time", disk.CreatedTime)
|
|
d.Set("deleted_time", disk.DeletedTime)
|
|
d.Set("desc", disk.Description)
|
|
d.Set("destruction_time", disk.DestructionTime)
|
|
d.Set("devicename", disk.DeviceName)
|
|
d.Set("disk_path", disk.DiskPath)
|
|
d.Set("gid", disk.GID)
|
|
d.Set("guid", disk.GUID)
|
|
d.Set("disk_id", disk.ID)
|
|
d.Set("image_id", disk.ImageID)
|
|
d.Set("images", disk.Images)
|
|
d.Set("iotune", flattenIOTune(disk.IOTune))
|
|
d.Set("iqn", disk.IQN)
|
|
d.Set("login", disk.Login)
|
|
d.Set("milestones", disk.Milestones)
|
|
d.Set("disk_name", disk.Name)
|
|
d.Set("order", disk.Order)
|
|
d.Set("params", disk.Params)
|
|
d.Set("parent_id", disk.ParentID)
|
|
d.Set("passwd", disk.Password)
|
|
d.Set("pci_slot", disk.PCISlot)
|
|
d.Set("pool", disk.Pool)
|
|
d.Set("purge_attempts", disk.PurgeAttempts)
|
|
d.Set("present_to", disk.PresentTo)
|
|
d.Set("purge_time", disk.PurgeTime)
|
|
d.Set("reality_device_number", disk.RealityDeviceNumber)
|
|
d.Set("reference_id", disk.ReferenceID)
|
|
d.Set("res_id", disk.ResID)
|
|
d.Set("res_name", disk.ResName)
|
|
d.Set("role", disk.Role)
|
|
d.Set("sep_id", disk.SEPID)
|
|
d.Set("sep_type", disk.SEPType)
|
|
d.Set("shareable", disk.Shareable)
|
|
d.Set("size_max", disk.SizeMax)
|
|
d.Set("size_used", disk.SizeUsed)
|
|
d.Set("snapshots", flattendDiskSnapshotList(disk.Snapshots))
|
|
d.Set("status", disk.Status)
|
|
d.Set("tech_status", disk.TechStatus)
|
|
d.Set("type", disk.Type)
|
|
d.Set("vmid", disk.VMID)
|
|
}
|
|
|
|
func flattenDiskSnapshot(d *schema.ResourceData, snapshot disks.ItemSnapshot) {
|
|
d.Set("timestamp", snapshot.Timestamp)
|
|
d.Set("guid", snapshot.GUID)
|
|
d.Set("reference_id", snapshot.ReferenceID)
|
|
d.Set("res_id", snapshot.ResID)
|
|
d.Set("snap_set_guid", snapshot.SnapSetGUID)
|
|
d.Set("snap_set_time", snapshot.SnapSetTime)
|
|
}
|
|
|
|
func flattenDiskComputes(computes map[string]string) []map[string]interface{} {
|
|
res := make([]map[string]interface{}, 0, len(computes))
|
|
for key, val := range computes {
|
|
tmp := map[string]interface{}{
|
|
"compute_id": key,
|
|
"compute_name": val,
|
|
}
|
|
res = append(res, tmp)
|
|
}
|
|
return res
|
|
}
|
|
|
|
func flattenIOTune(iot disks.IOTune) []map[string]interface{} {
|
|
res := make([]map[string]interface{}, 0)
|
|
temp := map[string]interface{}{
|
|
"read_bytes_sec": iot.ReadBytesSec,
|
|
"read_bytes_sec_max": iot.ReadBytesSecMax,
|
|
"read_iops_sec": iot.ReadIOPSSec,
|
|
"read_iops_sec_max": iot.ReadIOPSSecMax,
|
|
"size_iops_sec": iot.SizeIOPSSec,
|
|
"total_bytes_sec": iot.TotalBytesSec,
|
|
"total_bytes_sec_max": iot.TotalBytesSecMax,
|
|
"total_iops_sec": iot.TotalIOPSSec,
|
|
"total_iops_sec_max": iot.TotalIOPSSecMax,
|
|
"write_bytes_sec": iot.WriteBytesSec,
|
|
"write_bytes_sec_max": iot.WriteBytesSecMax,
|
|
"write_iops_sec": iot.WriteIOPSSec,
|
|
"write_iops_sec_max": iot.WriteIOPSSecMax,
|
|
}
|
|
|
|
res = append(res, temp)
|
|
return res
|
|
}
|
|
|
|
func flattenDiskList(dl *disks.ListDisks) []map[string]interface{} {
|
|
res := make([]map[string]interface{}, 0)
|
|
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),
|
|
"boot_partition": disk.BootPartition,
|
|
// "compute_id": disk.MachineID,
|
|
// "compute_name": disk.MachineName,
|
|
"created_time": disk.CreatedTime,
|
|
"deleted_time": disk.DeletedTime,
|
|
"desc": disk.Description,
|
|
"destruction_time": disk.DestructionTime,
|
|
"devicename": disk.DeviceName,
|
|
"disk_path": disk.DiskPath,
|
|
"gid": disk.GID,
|
|
"guid": disk.GUID,
|
|
"disk_id": disk.ID,
|
|
"image_id": disk.ImageID,
|
|
"images": disk.Images,
|
|
"iotune": flattenIOTune(disk.IOTune),
|
|
"iqn": disk.IQN,
|
|
"login": disk.Login,
|
|
"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,
|
|
"passwd": disk.Password,
|
|
"pci_slot": disk.PCISlot,
|
|
"pool": disk.Pool,
|
|
"purge_attempts": disk.PurgeAttempts,
|
|
"purge_time": disk.PurgeTime,
|
|
"reality_device_number": disk.RealityDeviceNumber,
|
|
"reference_id": disk.ReferenceID,
|
|
"res_id": disk.ResID,
|
|
"res_name": disk.ResName,
|
|
"role": disk.Role,
|
|
"sep_id": disk.SEPID,
|
|
"sep_type": disk.SEPType,
|
|
"size_max": disk.SizeMax,
|
|
"size_used": disk.SizeUsed,
|
|
"snapshots": flattendDiskSnapshotList(disk.Snapshots),
|
|
"status": disk.Status,
|
|
"tech_status": disk.TechStatus,
|
|
"type": disk.Type,
|
|
"vmid": disk.VMID,
|
|
}
|
|
res = append(res, temp)
|
|
}
|
|
return res
|
|
|
|
}
|
|
|
|
func flattendDiskSnapshotList(sl disks.ListSnapshots) []interface{} {
|
|
res := make([]interface{}, 0)
|
|
for _, snapshot := range sl {
|
|
temp := map[string]interface{}{
|
|
"guid": snapshot.GUID,
|
|
"label": snapshot.Label,
|
|
"reference_id": snapshot.ReferenceID,
|
|
"res_id": snapshot.ResID,
|
|
"snap_set_guid": snapshot.SnapSetGUID,
|
|
"snap_set_time": snapshot.SnapSetTime,
|
|
"timestamp": snapshot.Timestamp,
|
|
}
|
|
res = append(res, temp)
|
|
}
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
func flattenDiskListTypesDetailed(tld *disks.ListTypes) []map[string]interface{} {
|
|
res := make([]map[string]interface{}, 0)
|
|
for _, typeListDetailed := range tld.Data {
|
|
toMap := typeListDetailed.(map[string]interface{})
|
|
temp := map[string]interface{}{
|
|
"pools": flattenListTypesDetailedPools(toMap["pools"].([]interface{})),
|
|
"sep_id": toMap["sepId"].(float64),
|
|
"sep_name": toMap["sepName"].(string),
|
|
}
|
|
res = append(res, temp)
|
|
}
|
|
return res
|
|
}
|
|
|
|
func flattenListTypesDetailedPools(pools []interface{}) []interface{} {
|
|
res := make([]interface{}, 0)
|
|
for _, pool := range pools {
|
|
toMap := pool.(map[string]interface{})
|
|
temp := map[string]interface{}{
|
|
"name": toMap["name"].(string),
|
|
"system": toMap["system"].(string),
|
|
"types": toMap["types"].([]interface{}),
|
|
}
|
|
res = append(res, temp)
|
|
}
|
|
|
|
return res
|
|
}
|
|
|
|
func flattenDiskListUnattached(ul *disks.ListUnattachedDisks) []map[string]interface{} {
|
|
res := make([]map[string]interface{}, 0)
|
|
for _, unattachedDisk := range ul.Data {
|
|
unattachedDiskAcl, _ := json.Marshal(unattachedDisk.ACL)
|
|
tmp := map[string]interface{}{
|
|
"_ckey": unattachedDisk.CKey,
|
|
"_meta": flattens.FlattenMeta(unattachedDisk.Meta),
|
|
"account_id": unattachedDisk.AccountID,
|
|
"account_name": unattachedDisk.AccountName,
|
|
"acl": string(unattachedDiskAcl),
|
|
"boot_partition": unattachedDisk.BootPartition,
|
|
"created_time": unattachedDisk.CreatedTime,
|
|
"deleted_time": unattachedDisk.DeletedTime,
|
|
"desc": unattachedDisk.Description,
|
|
"destruction_time": unattachedDisk.DestructionTime,
|
|
"disk_path": unattachedDisk.DiskPath,
|
|
"gid": unattachedDisk.GID,
|
|
"guid": unattachedDisk.GUID,
|
|
"disk_id": unattachedDisk.ID,
|
|
"image_id": unattachedDisk.ImageID,
|
|
"images": unattachedDisk.Images,
|
|
"iotune": flattenIOTune(unattachedDisk.IOTune),
|
|
"iqn": unattachedDisk.IQN,
|
|
"login": unattachedDisk.Login,
|
|
"milestones": unattachedDisk.Milestones,
|
|
"disk_name": unattachedDisk.Name,
|
|
"order": unattachedDisk.Order,
|
|
"params": unattachedDisk.Params,
|
|
"parent_id": unattachedDisk.ParentID,
|
|
"passwd": unattachedDisk.Password,
|
|
"pci_slot": unattachedDisk.PCISlot,
|
|
"pool": unattachedDisk.Pool,
|
|
"present_to": unattachedDisk.PresentTo,
|
|
"purge_attempts": unattachedDisk.PurgeAttempts,
|
|
"purge_time": unattachedDisk.PurgeTime,
|
|
"reality_device_number": unattachedDisk.RealityDeviceNumber,
|
|
"reference_id": unattachedDisk.ReferenceID,
|
|
"res_id": unattachedDisk.ResID,
|
|
"res_name": unattachedDisk.ResName,
|
|
"role": unattachedDisk.Role,
|
|
"sep_id": unattachedDisk.SEPID,
|
|
"shareable": unattachedDisk.Shareable,
|
|
"size_max": unattachedDisk.SizeMax,
|
|
"size_used": unattachedDisk.SizeUsed,
|
|
"snapshots": flattenDiskSnapshotList(unattachedDisk.Snapshots),
|
|
"status": unattachedDisk.Status,
|
|
"tech_status": unattachedDisk.TechStatus,
|
|
"type": unattachedDisk.Type,
|
|
"vmid": unattachedDisk.VMID,
|
|
}
|
|
res = append(res, tmp)
|
|
}
|
|
return res
|
|
}
|
|
|
|
func flattenDiskSnapshotList(sl disks.ListSnapshots) []interface{} {
|
|
res := make([]interface{}, 0)
|
|
for _, snapshot := range sl {
|
|
temp := map[string]interface{}{
|
|
"guid": snapshot.GUID,
|
|
"label": snapshot.Label,
|
|
"reference_id": snapshot.ReferenceID,
|
|
"res_id": snapshot.ResID,
|
|
"snap_set_guid": snapshot.SnapSetGUID,
|
|
"snap_set_time": snapshot.SnapSetTime,
|
|
"timestamp": snapshot.Timestamp,
|
|
}
|
|
res = append(res, temp)
|
|
}
|
|
|
|
return res
|
|
}
|