This commit is contained in:
2026-02-11 13:02:14 +03:00
parent 069d63a65c
commit b8283ebfaf
277 changed files with 2184 additions and 4192 deletions

View File

@@ -1,69 +0,0 @@
/*
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@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 image
import (
"context"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func dataSourceImageListStacksRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
imageListStacks, err := utilityImageListStacksCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenImageListStacks(imageListStacks))
d.Set("entry_count", imageListStacks.EntryCount)
return nil
}
func DataSourceImageListStacks() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceImageListStacksRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceImageListStacksSchemaMake(),
}
}

View File

@@ -161,40 +161,6 @@ func flattenEco(m interface{}) string {
return output
}
func flattenImageListStacks(stack *image.ListStacks) []map[string]interface{} {
log.Debug("flattenImageListStacks")
temp := make([]map[string]interface{}, 0, len(stack.Data))
for _, item := range stack.Data {
t := map[string]interface{}{
"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,
"desc": item.Description,
"descr": item.Descr,
"drivers": item.Drivers,
"eco": flattenEco(item.Eco),
"error": item.Error,
"gid": item.GID,
"guid": item.GUID,
"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,
}
temp = append(temp, t)
}
return temp
}
func flattenPackages(pg image.Packages) []map[string]interface{} {
log.Debug("flattenPackages")
res := make([]map[string]interface{}, 0)

View File

@@ -36,291 +36,6 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
func dataSourceImageListStacksSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"image_id": {
Type: schema.TypeInt,
Required: true,
Description: "image id",
},
"sort_by": {
Type: schema.TypeString,
Optional: true,
Description: "sort by one of supported fields, format +|-(field)",
},
"page": {
Type: schema.TypeInt,
Optional: true,
Description: "page number",
},
"size": {
Type: schema.TypeInt,
Optional: true,
Description: "page size",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "find by name",
},
"status": {
Type: schema.TypeString,
Optional: true,
Description: "find by status",
},
"type_image": {
Type: schema.TypeString,
Optional: true,
Description: "find by type",
},
"items": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ckey": {
Type: schema.TypeString,
Computed: true,
},
"api_url": {
Type: schema.TypeString,
Computed: true,
},
"api_key": {
Type: schema.TypeString,
Computed: true,
},
"app_id": {
Type: schema.TypeString,
Computed: true,
},
"cpu_allocation_ratio": {
Type: schema.TypeFloat,
Computed: true,
},
"desc": {
Type: schema.TypeString,
Computed: true,
},
"descr": {
Type: schema.TypeString,
Computed: true,
},
"drivers": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"eco": {
Type: schema.TypeString,
Computed: true,
},
"error": {
Type: schema.TypeInt,
Computed: true,
},
"gid": {
Type: schema.TypeInt,
Computed: true,
},
"guid": {
Type: schema.TypeInt,
Computed: true,
},
"id": {
Type: schema.TypeInt,
Computed: true,
},
"images": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"login": {
Type: schema.TypeString,
Computed: true,
},
"mem_allocation_ratio": {
Type: schema.TypeFloat,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"packages": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: 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",
},
},
},
},
"libvirt_daemon": {
Type: schema.TypeList,
Computed: true,
Description: "libvirt_daemon",
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",
},
},
},
},
},
},
},
"passwd": {
Type: schema.TypeString,
Computed: true,
},
"reference_id": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
},
},
Description: "items of stacks list",
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
Description: "entry count",
},
}
}
func dataSourceImageListSchemaMake() map[string]*schema.Schema {
rets := map[string]*schema.Schema{
"sep_id": {
@@ -1017,10 +732,6 @@ func resourceCDROMImageSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "unc path",
},
"ckey": {
Type: schema.TypeString,
Computed: true,
},
"acl": {
Type: schema.TypeList,
Computed: true,
@@ -1531,10 +1242,6 @@ func resourceVirtualImageSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "unc path",
},
"ckey": {
Type: schema.TypeString,
Computed: true,
},
"acl": {
Type: schema.TypeList,
Computed: true,

View File

@@ -1,76 +0,0 @@
/*
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@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 image
import (
"context"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/image"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityImageListStacksCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*image.ListStacks, error) {
c := m.(*controller.ControllerCfg)
req := image.ListStacksRequest{
ImageID: uint64(d.Get("image_id").(int)),
}
if sortBy, ok := d.GetOk("sort_by"); ok {
req.SortBy = sortBy.(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))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
if typeImage, ok := d.GetOk("type_image"); ok {
req.Type = typeImage.(string)
}
log.Debugf("utilityImageListStacksCheckPresence: load image list")
imageListStacks, err := c.CloudBroker().Image().ListStacks(ctx, req)
if err != nil {
return nil, err
}
return imageListStacks, nil
}