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.
160 lines
4.6 KiB
160 lines
4.6 KiB
package account
|
|
|
|
import (
|
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
|
)
|
|
|
|
func flattenAccount(d *schema.ResourceData, acc account.RecordAccount) error {
|
|
d.Set("dc_location", acc.DCLocation)
|
|
// d.Set("resources", flattenAccResources(acc.Resources))
|
|
d.Set("ckey", acc.CKey)
|
|
d.Set("acl", flattenAccAcl(acc.ACL))
|
|
d.Set("company", acc.Company)
|
|
d.Set("companyurl", acc.CompanyURL)
|
|
d.Set("created_by", acc.CreatedBy)
|
|
d.Set("created_time", acc.CreatedTime)
|
|
d.Set("deactivation_time", acc.DeactivationTime)
|
|
d.Set("deleted_by", acc.DeletedBy)
|
|
d.Set("deleted_time", acc.DeletedTime)
|
|
d.Set("displayname", acc.DisplayName)
|
|
d.Set("guid", acc.GUID)
|
|
d.Set("account_id", acc.ID)
|
|
d.Set("account_name", acc.Name)
|
|
d.Set("resource_limits", flattenAccResourceLimits(acc.ResourceLimits))
|
|
d.Set("send_access_emails", acc.SendAccessEmails)
|
|
d.Set("status", acc.Status)
|
|
d.Set("updated_time", acc.UpdatedTime)
|
|
d.Set("version", acc.Version)
|
|
d.Set("vins", acc.VINS)
|
|
d.Set("vinses", acc.VINSes)
|
|
d.Set("computes", flattenAccComputes(acc.Computes))
|
|
d.Set("machines", flattenAccMachines(acc.Machines))
|
|
d.Set("cpu_allocation_parameter", acc.CPUAllocationParameter)
|
|
d.Set("cpu_allocation_ratio", acc.CPUAllocationRatio)
|
|
|
|
if username, ok := d.GetOk("username"); ok {
|
|
d.Set("username", username)
|
|
} else {
|
|
d.Set("username", acc.ACL[0].UgroupID)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func flattenAccComputes(acs account.Computes) []map[string]interface{} {
|
|
res := make([]map[string]interface{}, 0)
|
|
temp := map[string]interface{}{
|
|
"started": acs.Started,
|
|
"stopped": acs.Stopped,
|
|
}
|
|
res = append(res, temp)
|
|
return res
|
|
}
|
|
|
|
func flattenAccMachines(ams account.Machines) []map[string]interface{} {
|
|
res := make([]map[string]interface{}, 0)
|
|
temp := map[string]interface{}{
|
|
"running": ams.Running,
|
|
"halted": ams.Halted,
|
|
}
|
|
res = append(res, temp)
|
|
return res
|
|
}
|
|
|
|
func flattenAccAcl(acls []account.RecordACL) []map[string]interface{} {
|
|
res := make([]map[string]interface{}, 0)
|
|
for _, acls := range acls {
|
|
temp := map[string]interface{}{
|
|
"can_be_deleted": acls.CanBeDeleted,
|
|
"explicit": acls.IsExplicit,
|
|
"guid": acls.GUID,
|
|
"right": acls.Rights,
|
|
"status": acls.Status,
|
|
"type": acls.Type,
|
|
"user_group_id": acls.UgroupID,
|
|
}
|
|
res = append(res, temp)
|
|
}
|
|
return res
|
|
}
|
|
|
|
func flattenResourceConsumption(d *schema.ResourceData, acc *account.RecordResourceConsumption) {
|
|
d.Set("account_id", acc.AccountID)
|
|
d.Set("consumed", flattenAccResource(acc.Consumed))
|
|
d.Set("reserved", flattenAccResource(acc.Reserved))
|
|
d.Set("resource_limits", flattenAccResourceLimits(acc.ResourceLimits))
|
|
}
|
|
|
|
func flattenAccResourceLimits(rl account.ResourceLimits) []map[string]interface{} {
|
|
res := make([]map[string]interface{}, 0)
|
|
temp := map[string]interface{}{
|
|
"cu_c": rl.CUC,
|
|
"cu_d": rl.CUD,
|
|
"cu_dm": rl.CUDM,
|
|
"cu_i": rl.CUI,
|
|
"cu_m": rl.CUM,
|
|
"cu_np": rl.CUNP,
|
|
"gpu_units": rl.GPUUnits,
|
|
}
|
|
res = append(res, temp)
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
// func flattenAccResources(r account.Resources) []map[string]interface{} {
|
|
// res := make([]map[string]interface{}, 0)
|
|
// temp := map[string]interface{}{
|
|
// "current": flattenAccResource(r.Current),
|
|
// "reserved": flattenAccResource(r.Reserved),
|
|
// }
|
|
// res = append(res, temp)
|
|
// return res
|
|
// }
|
|
|
|
func flattenAccountSeps(seps map[string]map[string]account.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
|
|
}
|
|
|
|
func flattenAccResource(r account.Resource) []map[string]interface{} {
|
|
res := make([]map[string]interface{}, 0)
|
|
temp := map[string]interface{}{
|
|
"cpu": r.CPU,
|
|
"disk_size": r.DiskSize,
|
|
"disk_size_max": r.DiskSizeMax,
|
|
"ext_ips": r.ExtIPs,
|
|
"ext_traffic": r.ExtTraffic,
|
|
"gpu": r.GPU,
|
|
"ram": r.RAM,
|
|
"seps": flattenAccountSeps(r.SEPs),
|
|
}
|
|
res = append(res, temp)
|
|
return res
|
|
}
|
|
|
|
func flattenAccResourceConsumption(lrc *account.ListResourceConsumption) []map[string]interface{} {
|
|
res := make([]map[string]interface{}, 0, len(lrc.Data))
|
|
for _, rc := range lrc.Data {
|
|
temp := map[string]interface{}{
|
|
"consumed": flattenAccResource(rc.Consumed),
|
|
"reserved": flattenAccResource(rc.Reserved),
|
|
"account_id": rc.AccountID,
|
|
}
|
|
res = append(res, temp)
|
|
}
|
|
return res
|
|
}
|