4.5.0-alpha
This commit is contained in:
126
internal/service/cloudbroker/sep/flattens.go
Normal file
126
internal/service/cloudbroker/sep/flattens.go
Normal file
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Sergey Kisil, <svkisil@digitalenergy.online>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||
Orchestration Technology) with Terraform by Hashicorp.
|
||||
|
||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||
|
||||
Please see README.md to learn where to place source code so that it
|
||||
builds seamlessly.
|
||||
|
||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||
*/
|
||||
|
||||
package sep
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/sep"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens"
|
||||
)
|
||||
|
||||
func flattenSepList(sl *sep.ListSEP) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, item := range sl.Data {
|
||||
data, _ := json.Marshal(item.Config)
|
||||
temp := map[string]interface{}{
|
||||
"ckey": item.CKey,
|
||||
"meta": flattens.FlattenMeta(item.Meta),
|
||||
"consumed_by": item.ConsumedBy,
|
||||
"desc": item.Description,
|
||||
"gid": item.GID,
|
||||
"guid": item.GUID,
|
||||
"sep_id": item.ID,
|
||||
"milestones": item.Milestones,
|
||||
"name": item.Name,
|
||||
"obj_status": item.ObjStatus,
|
||||
"provided_by": item.ProvidedBy,
|
||||
"shared_with": item.SharedWith,
|
||||
"tech_status": item.TechStatus,
|
||||
"type": item.Type,
|
||||
"config": string(data),
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenSepPool(rp *sep.RecordPool) []map[string]interface{} {
|
||||
sh := make([]map[string]interface{}, 0)
|
||||
res := map[string]interface{}{
|
||||
"access_account_ids": rp.AccessAccountIDs,
|
||||
"access_res_group_ids": rp.AccessResGroupIDs,
|
||||
"name": rp.Name,
|
||||
"pagecache_ratio": rp.PageCacheRatio,
|
||||
"reference_id": rp.ReferenceID,
|
||||
"types": rp.Types,
|
||||
"uris": flattenSepPoolUris(rp),
|
||||
"usage_limit": rp.UsageLimit,
|
||||
}
|
||||
sh = append(sh, res)
|
||||
return sh
|
||||
}
|
||||
|
||||
func flattenSepPoolUris(rp *sep.RecordPool) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, ur := range rp.URIs {
|
||||
temp := map[string]interface{}{
|
||||
"ip": ur.IP,
|
||||
"port": ur.Port,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenSepConsumption(sc sep.Total) []map[string]interface{} {
|
||||
sh := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"capacity_limit": sc.CapacityLimit,
|
||||
"disk_count": sc.DiskCount,
|
||||
"disk_usage": sc.DiskUsage,
|
||||
"snapshot_count": sc.SnapshotCount,
|
||||
"snapshot_usage": sc.SnapshotUsage,
|
||||
"usage": sc.Usage,
|
||||
"usage_limit": sc.UsageLimit,
|
||||
}
|
||||
sh = append(sh, temp)
|
||||
return sh
|
||||
}
|
||||
|
||||
func flattenSepConsumptionPools(bp *sep.RecordConsumption) []map[string]interface{} {
|
||||
sh := make([]map[string]interface{}, 0)
|
||||
for key, value := range bp.ByPool {
|
||||
temp := map[string]interface{}{
|
||||
"name": key,
|
||||
"disk_count": value.DiskCount,
|
||||
"disk_usage": value.DiskUsage,
|
||||
"snapshot_count": value.SnapshotCount,
|
||||
"snapshot_usage": value.SnapshotUsage,
|
||||
"usage": value.Usage,
|
||||
"usage_limit": value.UsageLimit,
|
||||
}
|
||||
sh = append(sh, temp)
|
||||
}
|
||||
return sh
|
||||
}
|
||||
Reference in New Issue
Block a user