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.
91 lines
2.6 KiB
91 lines
2.6 KiB
package grid
|
|
|
|
import (
|
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/grid"
|
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens"
|
|
)
|
|
|
|
func flattenGrid(d *schema.ResourceData, grid *grid.RecordGrid) {
|
|
d.Set("auth_broker", flattens.FlattenMeta(grid.AuthBroker))
|
|
d.Set("name", grid.Name)
|
|
d.Set("flag", grid.Flag)
|
|
d.Set("gid", grid.GID)
|
|
d.Set("guid", grid.GUID)
|
|
d.Set("location_code", grid.LocationCode)
|
|
d.Set("id", grid.ID)
|
|
}
|
|
|
|
func flattenGridList(gl *grid.ListGrids) []map[string]interface{} {
|
|
res := make([]map[string]interface{}, 0, len(gl.Data))
|
|
for _, item := range gl.Data {
|
|
temp := map[string]interface{}{
|
|
"resources": flattenGridResources(item.Resources),
|
|
"name": item.Name,
|
|
"auth_broker": flattens.FlattenMeta(item.AuthBroker),
|
|
"flag": item.Flag,
|
|
"gid": item.GID,
|
|
"guid": item.GUID,
|
|
"location_code": item.LocationCode,
|
|
"id": item.ID,
|
|
}
|
|
res = append(res, temp)
|
|
}
|
|
return res
|
|
}
|
|
|
|
func flattenGridListConsumption(gl *grid.ListResourceConsumption) []map[string]interface{} {
|
|
res := make([]map[string]interface{}, 0, len(gl.Data))
|
|
for _, item := range gl.Data {
|
|
temp := map[string]interface{}{
|
|
"consumed": flattenGridRecordResource(item.Consumed),
|
|
"reserved": flattenGridRecordResource(item.Reserved),
|
|
"id": item.GID,
|
|
}
|
|
res = append(res, temp)
|
|
}
|
|
return res
|
|
}
|
|
|
|
func flattenGridResources(r grid.Resources) []map[string]interface{} {
|
|
res := make([]map[string]interface{}, 0)
|
|
temp := map[string]interface{}{
|
|
"current": flattenGridRecordResource(r.Current),
|
|
"reserved": flattenGridRecordResource(r.Reserved),
|
|
}
|
|
res = append(res, temp)
|
|
return res
|
|
}
|
|
|
|
func flattenGridRecordResource(rr grid.RecordResource) []map[string]interface{} {
|
|
res := make([]map[string]interface{}, 0)
|
|
temp := map[string]interface{}{
|
|
"cpu": rr.CPU,
|
|
"disk_size": rr.DiskSize,
|
|
"disk_size_max": rr.DiskSizeMax,
|
|
"ext_ips": rr.ExtIPs,
|
|
"ext_traffic": rr.ExtTraffic,
|
|
"gpu": rr.GPU,
|
|
"ram": rr.RAM,
|
|
"seps": flattenGridSeps(rr.SEPs),
|
|
}
|
|
res = append(res, temp)
|
|
return res
|
|
}
|
|
|
|
func flattenGridSeps(seps map[string]map[string]grid.DiskUsage) []map[string]interface{} {
|
|
res := make([]map[string]interface{}, 0)
|
|
for sepKey, sepVal := range seps {
|
|
for dataKey, dataVal := range sepVal {
|
|
temp := map[string]interface{}{
|
|
"sep_id": sepKey,
|
|
"data_name": dataKey,
|
|
"disk_size": dataVal.DiskSize,
|
|
"disk_size_max": dataVal.DiskSizeMax,
|
|
}
|
|
res = append(res, temp)
|
|
}
|
|
}
|
|
return res
|
|
}
|