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.
406 lines
11 KiB
406 lines
11 KiB
package account
|
|
|
|
import (
|
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/account"
|
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens"
|
|
)
|
|
|
|
func flattenResourceAccount(d *schema.ResourceData, acc *account.RecordAccount) {
|
|
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", flattenRgResourceLimits(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)
|
|
}
|
|
|
|
func flattenDataAccount(d *schema.ResourceData, acc *account.RecordAccount) {
|
|
d.Set("dc_location", acc.DCLocation)
|
|
// d.Set("resources", flattenAccResources(acc.Resources))
|
|
d.Set("ckey", acc.CKey)
|
|
// d.Set("meta", flattens.FlattenMeta(acc.))
|
|
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", flattenRgResourceLimits(acc.ResourceLimits))
|
|
d.Set("send_access_emails", acc.SendAccessEmails)
|
|
// d.Set("service_account", acc.ServiceAccount)
|
|
d.Set("status", acc.Status)
|
|
d.Set("updated_time", acc.UpdatedTime)
|
|
d.Set("version", acc.Version)
|
|
d.Set("vins", acc.VINS)
|
|
|
|
}
|
|
|
|
func flattenAccountRGList(argl *account.ListRG) []map[string]interface{} {
|
|
res := make([]map[string]interface{}, 0)
|
|
for _, arg := range argl.Data {
|
|
temp := map[string]interface{}{
|
|
"computes": flattenAccRGComputes(arg.Computes),
|
|
"resources": flattenAccRGResources(arg.Resources),
|
|
"created_by": arg.CreatedBy,
|
|
"created_time": arg.CreatedTime,
|
|
"deleted_by": arg.DeletedBy,
|
|
"deleted_time": arg.DeletedTime,
|
|
"rg_id": arg.ID,
|
|
"milestones": arg.Milestones,
|
|
"rg_name": arg.Name,
|
|
"status": arg.Status,
|
|
"updated_by": arg.UpdatedBy,
|
|
"updated_time": arg.UpdatedTime,
|
|
"vinses": arg.VINSes,
|
|
}
|
|
res = append(res, temp)
|
|
}
|
|
return res
|
|
|
|
}
|
|
|
|
func flattenAccRGComputes(argc account.Computes) []map[string]interface{} {
|
|
res := make([]map[string]interface{}, 0)
|
|
temp := map[string]interface{}{
|
|
"started": argc.Started,
|
|
"stopped": argc.Stopped,
|
|
}
|
|
res = append(res, temp)
|
|
return res
|
|
}
|
|
|
|
func flattenAccRGResources(argr account.RGResuorces) []map[string]interface{} {
|
|
res := make([]map[string]interface{}, 0)
|
|
temp := map[string]interface{}{
|
|
"consumed": flattenAccConsumed(argr.Consumed),
|
|
"limits": flattenAccLimits(argr.Limits),
|
|
"reserved": flattenAccResource(argr.Reserved),
|
|
}
|
|
res = append(res, temp)
|
|
return res
|
|
}
|
|
|
|
func flattenAccResources(r account.RecordResourceConsumption) []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 flattenAccConsumed(c account.Consumed) []map[string]interface{} {
|
|
res := make([]map[string]interface{}, 0)
|
|
temp := map[string]interface{}{
|
|
"cpu": c.CPU,
|
|
"disksize": c.DiskSize,
|
|
"extips": c.ExtIPs,
|
|
"exttraffic": c.ExtTraffic,
|
|
"gpu": c.GPU,
|
|
"ram": c.RAM,
|
|
}
|
|
res = append(res, temp)
|
|
return res
|
|
}
|
|
|
|
func flattenAccLimits(l account.Limits) []map[string]interface{} {
|
|
res := make([]map[string]interface{}, 0)
|
|
temp := map[string]interface{}{
|
|
"cpu": l.CPU,
|
|
"disksize": l.DiskSize,
|
|
"extips": l.ExtIPs,
|
|
"exttraffic": l.ExtTraffic,
|
|
"gpu": l.GPU,
|
|
"ram": l.RAM,
|
|
}
|
|
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,
|
|
"disksize": r.DiskSize,
|
|
"extips": r.ExtIPs,
|
|
"exttraffic": r.ExtTraffic,
|
|
"gpu": r.GPU,
|
|
"ram": r.RAM,
|
|
}
|
|
res = append(res, temp)
|
|
return res
|
|
}
|
|
|
|
func flattenAccAcl(acls []account.ACL) []map[string]interface{} {
|
|
res := make([]map[string]interface{}, 0)
|
|
for _, acls := range acls {
|
|
temp := map[string]interface{}{
|
|
"explicit": acls.Explicit,
|
|
"guid": acls.GUID,
|
|
"right": acls.Right,
|
|
"status": acls.Status,
|
|
"type": acls.Type,
|
|
"user_group_id": acls.UserGroupID,
|
|
}
|
|
res = append(res, temp)
|
|
}
|
|
return res
|
|
}
|
|
|
|
func flattenRgResourceLimits(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_i": rl.CuI,
|
|
"cu_m": rl.CuM,
|
|
"cu_np": rl.CuNP,
|
|
"gpu_units": rl.GPUUnits,
|
|
}
|
|
res = append(res, temp)
|
|
|
|
return res
|
|
}
|
|
|
|
func flattenRgAcl(rgAcls []account.ACL) []map[string]interface{} {
|
|
res := make([]map[string]interface{}, 0)
|
|
for _, rgAcl := range rgAcls {
|
|
temp := map[string]interface{}{
|
|
"explicit": rgAcl.Explicit,
|
|
"guid": rgAcl.GUID,
|
|
"right": rgAcl.Right,
|
|
"status": rgAcl.Status,
|
|
"type": rgAcl.Type,
|
|
"user_group_id": rgAcl.UserGroupID,
|
|
}
|
|
res = append(res, temp)
|
|
}
|
|
return res
|
|
}
|
|
|
|
func flattenListDeleted(al *account.ListAccounts) []map[string]interface{} {
|
|
res := make([]map[string]interface{}, 0)
|
|
for _, acc := range al.Data {
|
|
temp := map[string]interface{}{
|
|
"dc_location": acc.DCLocation,
|
|
"ckey": acc.CKey,
|
|
"meta": flattens.FlattenMeta(acc.Meta),
|
|
|
|
"acl": flattenRgAcl(acc.ACL),
|
|
|
|
"company": acc.Company,
|
|
"companyurl": acc.CompanyURL,
|
|
"created_by": acc.CreatedBy,
|
|
|
|
"created_time": acc.CreatedTime,
|
|
|
|
"deactivation_time": acc.DeactivationTime,
|
|
"deleted_by": acc.DeletedBy,
|
|
|
|
"deleted_time": acc.DeletedTime,
|
|
|
|
"displayname": acc.DisplayName,
|
|
"guid": acc.GUID,
|
|
|
|
"account_id": acc.ID,
|
|
"account_name": acc.Name,
|
|
|
|
"resource_limits": flattenRgResourceLimits(acc.ResourceLimits),
|
|
"send_access_emails": acc.SendAccessEmails,
|
|
// "service_account": acc.ServiceAccount,
|
|
|
|
"status": acc.Status,
|
|
"updated_time": acc.UpdatedTime,
|
|
|
|
"version": acc.Version,
|
|
"vins": acc.VINS,
|
|
}
|
|
res = append(res, temp)
|
|
}
|
|
return res
|
|
}
|
|
|
|
func flattenAccountList(al *account.ListAccounts) []map[string]interface{} {
|
|
res := make([]map[string]interface{}, 0)
|
|
for _, acc := range al.Data {
|
|
temp := map[string]interface{}{
|
|
"dc_location": acc.DCLocation,
|
|
"ckey": acc.CKey,
|
|
"meta": flattens.FlattenMeta(acc.Meta),
|
|
|
|
"acl": flattenRgAcl(acc.ACL),
|
|
|
|
"company": acc.Company,
|
|
"companyurl": acc.CompanyURL,
|
|
"created_by": acc.CreatedBy,
|
|
|
|
"created_time": acc.CreatedTime,
|
|
|
|
"deactivation_time": acc.DeactivationTime,
|
|
"deleted_by": acc.DeletedBy,
|
|
|
|
"deleted_time": acc.DeletedTime,
|
|
|
|
"displayname": acc.DisplayName,
|
|
"guid": acc.GUID,
|
|
|
|
"account_id": acc.ID,
|
|
"account_name": acc.Name,
|
|
|
|
"resource_limits": flattenRgResourceLimits(acc.ResourceLimits),
|
|
"send_access_emails": acc.SendAccessEmails,
|
|
// "service_account": acc.ServiceAccount,
|
|
|
|
"status": acc.Status,
|
|
"updated_time": acc.UpdatedTime,
|
|
|
|
"version": acc.Version,
|
|
"vins": acc.VINS,
|
|
}
|
|
res = append(res, temp)
|
|
}
|
|
return res
|
|
}
|
|
|
|
func flattenAccountAuditsList(aal account.ListAudits) []map[string]interface{} {
|
|
res := make([]map[string]interface{}, 0)
|
|
for _, aa := range aal {
|
|
temp := map[string]interface{}{
|
|
"call": aa.Call,
|
|
"responsetime": aa.ResponseTime,
|
|
"statuscode": aa.StatusCode,
|
|
"timestamp": aa.Timestamp,
|
|
"user": aa.User,
|
|
}
|
|
res = append(res, temp)
|
|
}
|
|
return res
|
|
}
|
|
|
|
func flattenAccountComputesList(acl *account.ListComputes) []map[string]interface{} {
|
|
res := make([]map[string]interface{}, 0)
|
|
for _, acc := range acl.Data {
|
|
temp := map[string]interface{}{
|
|
"account_id": acc.AccountID,
|
|
"account_name": acc.AccountName,
|
|
"cpus": acc.CPUs,
|
|
"created_by": acc.CreatedBy,
|
|
"created_time": acc.CreatedTime,
|
|
"deleted_by": acc.DeletedBy,
|
|
"deleted_time": acc.DeletedTime,
|
|
"compute_id": acc.ID,
|
|
"compute_name": acc.Name,
|
|
"ram": acc.RAM,
|
|
"registered": acc.Registered,
|
|
"rg_id": acc.RGID,
|
|
"rg_name": acc.RgName,
|
|
"status": acc.Status,
|
|
"tech_status": acc.TechStatus,
|
|
"total_disks_size": acc.TotalDisksSize,
|
|
"updated_by": acc.UpdatedBy,
|
|
"updated_time": acc.UpdatedTime,
|
|
"user_managed": acc.UserManaged,
|
|
"vins_connected": acc.VINSConnected,
|
|
}
|
|
res = append(res, temp)
|
|
}
|
|
return res
|
|
}
|
|
|
|
func flattenAccountDisksList(adl *account.ListDisks) []map[string]interface{} {
|
|
res := make([]map[string]interface{}, 0)
|
|
for _, ad := range adl.Data {
|
|
temp := map[string]interface{}{
|
|
"disk_id": ad.ID,
|
|
"disk_name": ad.Name,
|
|
"pool_name": ad.Pool,
|
|
"sep_id": ad.SepID,
|
|
"size_max": ad.SizeMax,
|
|
"type": ad.Type,
|
|
}
|
|
res = append(res, temp)
|
|
}
|
|
return res
|
|
}
|
|
|
|
func flattenAccountFlipGroupsList(afgl *account.ListFLIPGroups) []map[string]interface{} {
|
|
res := make([]map[string]interface{}, 0)
|
|
for _, afg := range afgl.Data {
|
|
temp := map[string]interface{}{
|
|
"account_id": afg.AccountID,
|
|
"client_type": afg.ClientType,
|
|
"conn_type": afg.ConnType,
|
|
"created_by": afg.CreatedBy,
|
|
"created_time": afg.CreatedTime,
|
|
"default_gw": afg.DefaultGW,
|
|
"deleted_by": afg.DeletedBy,
|
|
"deleted_time": afg.DeletedTime,
|
|
"desc": afg.Description,
|
|
"gid": afg.GID,
|
|
"guid": afg.GUID,
|
|
"fg_id": afg.ID,
|
|
"ip": afg.IP,
|
|
"milestones": afg.Milestones,
|
|
"fg_name": afg.Name,
|
|
"net_id": afg.NetID,
|
|
"net_type": afg.NetType,
|
|
"netmask": afg.Netmask,
|
|
"status": afg.Status,
|
|
"updated_by": afg.UpdatedBy,
|
|
"updated_time": afg.UpdatedTime,
|
|
}
|
|
res = append(res, temp)
|
|
}
|
|
return res
|
|
}
|
|
|
|
func flattenAccountVinsList(avl *account.ListVINS) []map[string]interface{} {
|
|
res := make([]map[string]interface{}, 0)
|
|
for _, av := range avl.Data {
|
|
temp := map[string]interface{}{
|
|
"account_id": av.AccountID,
|
|
"account_name": av.AccountName,
|
|
"computes": av.Computes,
|
|
"created_by": av.CreatedBy,
|
|
"created_time": av.CreatedTime,
|
|
"deleted_by": av.DeletedBy,
|
|
"deleted_time": av.DeletedTime,
|
|
"external_ip": av.ExternalIP,
|
|
"vin_id": av.ID,
|
|
"vin_name": av.Name,
|
|
"network": av.Network,
|
|
"pri_vnf_dev_id": av.PriVNFDevID,
|
|
"rg_id": av.RGID,
|
|
"rg_name": av.RGName,
|
|
"status": av.Status,
|
|
"updated_by": av.UpdatedBy,
|
|
"updated_time": av.UpdatedTime,
|
|
}
|
|
res = append(res, temp)
|
|
}
|
|
return res
|
|
}
|