4.5.1
This commit is contained in:
@@ -44,6 +44,7 @@ import (
|
||||
func dataSourceStackListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
stackList, err := utilityStackListCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
@@ -55,54 +56,6 @@ func dataSourceStackListRead(ctx context.Context, d *schema.ResourceData, m inte
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceStaksListSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"by_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "by_id",
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "name",
|
||||
},
|
||||
"type": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "type",
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "type",
|
||||
},
|
||||
"page": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "page number",
|
||||
},
|
||||
"size": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "page size",
|
||||
},
|
||||
"items": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: dataSourceStackSchemaMake(),
|
||||
},
|
||||
Description: "items of stacks list",
|
||||
},
|
||||
"entry_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "entry_count",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func DataSourceStacksList() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
@@ -114,6 +67,6 @@ func DataSourceStacksList() *schema.Resource {
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceStaksListSchemaMake(),
|
||||
Schema: dataSourceStacksListSchemaMake(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ import (
|
||||
func dataSourceStackRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
stack, err := utilityStackCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("") // ensure ID is empty in this case
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
@@ -52,257 +53,6 @@ func dataSourceStackRead(ctx context.Context, d *schema.ResourceData, m interfac
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceStackSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"stack_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "stack_id",
|
||||
},
|
||||
"ckey": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "ckey",
|
||||
},
|
||||
"meta": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
Description: "meta",
|
||||
},
|
||||
"api_url": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "api_url",
|
||||
},
|
||||
"api_key": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "api_key",
|
||||
},
|
||||
"app_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "api_id",
|
||||
},
|
||||
"cpu_allocation_ratio": {
|
||||
Type: schema.TypeFloat,
|
||||
Computed: true,
|
||||
Description: "cpu_allocation_ratio",
|
||||
},
|
||||
"description": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "description",
|
||||
},
|
||||
"descr": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "descr",
|
||||
},
|
||||
"drivers": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
Description: "drivers",
|
||||
},
|
||||
"eco": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "eco",
|
||||
},
|
||||
"error": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "error",
|
||||
},
|
||||
"gid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "gid",
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "guid",
|
||||
},
|
||||
"images": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
Description: "images",
|
||||
},
|
||||
"login": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "login",
|
||||
},
|
||||
"mem_allocation_ratio": {
|
||||
Type: schema.TypeFloat,
|
||||
Computed: true,
|
||||
Description: "mem_allocation_ratio",
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "name",
|
||||
},
|
||||
"packages": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: packagesSchemaMake(),
|
||||
},
|
||||
},
|
||||
"passwd": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "password",
|
||||
},
|
||||
"reference_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "reference_id",
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "status",
|
||||
},
|
||||
"type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "type",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func packagesSchemaMake() map[string]*schema.Schema {
|
||||
res := map[string]*schema.Schema{
|
||||
"libvirt_bin": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Description: "libvirt_bin",
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"installed_size": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "installed_size",
|
||||
},
|
||||
"ver": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "ver",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"lvm2_lockd": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Description: "lvm2_lockd",
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"installed_size": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "installed_size",
|
||||
},
|
||||
"ver": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "ver",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"openvswitch_common": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Description: "openvswitch_common",
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"installed_size": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "installed_size",
|
||||
},
|
||||
"ver": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "ver",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"openvswitch_switch": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Description: "openvswitch_switch",
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"installed_size": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "installed_size",
|
||||
},
|
||||
"ver": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "ver",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"qemu_system_x86": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Description: "qemu_system_x86",
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"installed_size": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "installed_size",
|
||||
},
|
||||
"ver": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "ver",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"sanlock": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Description: "sanlock",
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"installed_size": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "installed_size",
|
||||
},
|
||||
"ver": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "ver",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func DataSourceStack() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ func utilityStackCheckPresence(ctx context.Context, d *schema.ResourceData, m in
|
||||
req.StackId = uint64(d.Get("stack_id").(int))
|
||||
}
|
||||
|
||||
log.Debugf("utilityStackListCheckPresence: load stack list")
|
||||
log.Debugf("utilityStackCheckPresence: load stack")
|
||||
stackInfo, err := c.CloudBroker().Stack().Get(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -50,20 +50,20 @@ func utilityStackListCheckPresence(ctx context.Context, d *schema.ResourceData,
|
||||
req.ByID = uint64(ByID.(int))
|
||||
}
|
||||
if Name, ok := d.GetOk("name"); ok {
|
||||
req.Name = string(Name.(string))
|
||||
req.Name = Name.(string)
|
||||
}
|
||||
if Type, ok := d.GetOk("type"); ok {
|
||||
req.Type = string(Type.(string))
|
||||
req.Type = Type.(string)
|
||||
}
|
||||
if Status, ok := d.GetOk("status"); ok {
|
||||
req.Status = string(Status.(string))
|
||||
req.Status = Status.(string)
|
||||
}
|
||||
if Page, ok := d.GetOk("page"); ok {
|
||||
req.Page = uint64(Page.(int))
|
||||
}
|
||||
if Size, ok := d.GetOk("size"); ok {
|
||||
req.Size = uint64(Size.(int))
|
||||
}
|
||||
}
|
||||
|
||||
log.Debugf("utilityStackListCheckPresence: load stack list")
|
||||
stackList, err := c.CloudBroker().Stack().List(ctx, req)
|
||||
|
||||
Reference in New Issue
Block a user