This commit is contained in:
2023-12-18 18:36:55 +03:00
parent 294680282e
commit e2ee45ee14
155 changed files with 10125 additions and 17209 deletions

View File

@@ -33,6 +33,7 @@ Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/w
package stack
import (
log "github.com/sirupsen/logrus"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -41,6 +42,9 @@ import (
)
func flattenStack(d *schema.ResourceData, st *stack.InfoStack) {
log.Debugf("flattenStack: decoded Stack name %q / ID %d",
st.Name, st.ID)
d.Set("ckey", st.Ckey)
d.Set("meta", flattens.FlattenMeta(st.Meta))
d.Set("api_url", st.APIURL)
@@ -69,12 +73,13 @@ func flattenStack(d *schema.ResourceData, st *stack.InfoStack) {
func flattenPackages(pg stack.Packages) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"libvirt_bin": flattenLibvirtBin (pg),
"lvm2_lockd": flattenLvm2Lockd (pg),
"openvswitch_common": flattenOpenvswitchCommon (pg),
"openvswitch_switch": flattenOpenvswitchSwitch (pg),
"qemu_system_x86": flattenQemuSystemX86 (pg),
"sanlock": flattenSanlock (pg),
"libvirt_bin": flattenLibvirtBin(pg),
"libvirt_daemon": flattenLibvirtDaemon(pg),
"lvm2_lockd": flattenLvm2Lockd(pg),
"openvswitch_common": flattenOpenvswitchCommon(pg),
"openvswitch_switch": flattenOpenvswitchSwitch(pg),
"qemu_system_x86": flattenQemuSystemX86(pg),
"sanlock": flattenSanlock(pg),
}
res = append(res, temp)
return res
@@ -83,8 +88,18 @@ func flattenPackages(pg stack.Packages) []map[string]interface{} {
func flattenLibvirtBin(lb stack.Packages) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"installed_size": lb.LibvirtBin.InstalledSize,
"ver": lb.LibvirtBin.Ver,
"installed_size": lb.LibvirtBin.InstalledSize,
"ver": lb.LibvirtBin.Ver,
}
res = append(res, temp)
return res
}
func flattenLibvirtDaemon(ld stack.Packages) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"installed_size": ld.LibvirtDaemon.InstalledSize,
"ver": ld.LibvirtDaemon.Ver,
}
res = append(res, temp)
return res
@@ -93,8 +108,8 @@ func flattenLibvirtBin(lb stack.Packages) []map[string]interface{} {
func flattenLvm2Lockd(ll stack.Packages) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"installed_size": ll.Lvm2Lockd.InstalledSize,
"ver": ll.Lvm2Lockd.Ver,
"installed_size": ll.Lvm2Lockd.InstalledSize,
"ver": ll.Lvm2Lockd.Ver,
}
res = append(res, temp)
return res
@@ -103,8 +118,8 @@ func flattenLvm2Lockd(ll stack.Packages) []map[string]interface{} {
func flattenOpenvswitchCommon(oc stack.Packages) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"installed_size": oc.OpenvswitchCommon.InstalledSize,
"ver": oc.OpenvswitchCommon.Ver,
"installed_size": oc.OpenvswitchCommon.InstalledSize,
"ver": oc.OpenvswitchCommon.Ver,
}
res = append(res, temp)
return res
@@ -113,8 +128,8 @@ func flattenOpenvswitchCommon(oc stack.Packages) []map[string]interface{} {
func flattenOpenvswitchSwitch(os stack.Packages) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"installed_size": os.OpenvswitchSwitch.InstalledSize,
"ver": os.OpenvswitchSwitch.Ver,
"installed_size": os.OpenvswitchSwitch.InstalledSize,
"ver": os.OpenvswitchSwitch.Ver,
}
res = append(res, temp)
return res
@@ -123,8 +138,8 @@ func flattenOpenvswitchSwitch(os stack.Packages) []map[string]interface{} {
func flattenQemuSystemX86(qs stack.Packages) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"installed_size": qs.QemuSystemX86.InstalledSize,
"ver": qs.QemuSystemX86.Ver,
"installed_size": qs.QemuSystemX86.InstalledSize,
"ver": qs.QemuSystemX86.Ver,
}
res = append(res, temp)
return res
@@ -133,56 +148,55 @@ func flattenQemuSystemX86(qs stack.Packages) []map[string]interface{} {
func flattenSanlock(sl stack.Packages) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"installed_size": sl.Sanlock.InstalledSize,
"ver": sl.Sanlock.Ver,
"installed_size": sl.Sanlock.InstalledSize,
"ver": sl.Sanlock.Ver,
}
res = append(res, temp)
return res
}
func flattenEco(m interface{}) string {
switch d := m.(type) {
case string:
return d
case int:
return strconv.Itoa(d)
case int64:
return strconv.FormatInt(d, 10)
case float64:
return strconv.FormatInt(int64(d), 10)
default:
return ""
}
switch d := m.(type) {
case string:
return d
case int:
return strconv.Itoa(d)
case int64:
return strconv.FormatInt(d, 10)
case float64:
return strconv.FormatInt(int64(d), 10)
default:
return ""
}
}
func flattenStacksList(sl *stack.ListStacks) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(sl.Data))
for _, item := range sl.Data {
temp := map[string]interface{}{
"ckey": item.Ckey,
"meta": flattens.FlattenMeta(item.Meta),
"api_url": item.APIURL,
"api_key": item.Apikey,
"app_id": item.AppID,
"ckey": item.Ckey,
"meta": flattens.FlattenMeta(item.Meta),
"api_url": item.APIURL,
"api_key": item.Apikey,
"app_id": item.AppID,
"cpu_allocation_ratio": item.CPUAllocationRatio,
"description": item.Description,
"descr": item.Descr,
"drivers": item.Drivers,
"eco": flattenEco(item.Eco),
"error": item.Error,
"gid": item.GID,
"guid": item.GUID,
"stack_id": item.ID,
"images": item.Images,
"login": item.Login,
"description": item.Description,
"descr": item.Descr,
"drivers": item.Drivers,
"eco": flattenEco(item.Eco),
"error": item.Error,
"gid": item.GID,
"guid": item.GUID,
"stack_id": item.ID,
"images": item.Images,
"login": item.Login,
"mem_allocation_ratio": item.MemAllocationRatio,
"name": item.Name,
"packages": flattenPackages(item.Packages),
"passwd": item.Password,
"reference_id": item.ReferenceID,
"status": item.Status,
"type": item.Type,
"name": item.Name,
"packages": flattenPackages(item.Packages),
"passwd": item.Password,
"reference_id": item.ReferenceID,
"status": item.Status,
"type": item.Type,
}
res = append(res, temp)
}