This commit is contained in:
2023-07-26 13:32:39 +03:00
parent f731cf246f
commit 272e385318
167 changed files with 5194 additions and 890 deletions

View File

@@ -49,16 +49,72 @@ func dataSourceImageListRead(ctx context.Context, d *schema.ResourceData, m inte
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenImageList(imageList))
d.Set("entry_count", imageList.EntryCount)
return nil
}
func dataSourceImageListSchemaMake() map[string]*schema.Schema {
rets := map[string]*schema.Schema{
"account_id": {
"sep_id": {
Type: schema.TypeInt,
Optional: true,
Description: "optional account ID to include account images",
Description: "Filter by Storage Endpoint ID",
},
"by_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by ID",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by name",
},
"status": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by status",
},
"architecture": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by architecture",
},
"type_image": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by image type",
},
"image_size": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by image size",
},
"sep_name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by SEP name",
},
"pool": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by pool",
},
"public": {
Type: schema.TypeBool,
Optional: true,
Description: "Find public/private images",
},
"hot_resize": {
Type: schema.TypeBool,
Optional: true,
Description: "Find hot resizable images",
},
"bootable": {
Type: schema.TypeBool,
Optional: true,
Description: "Find bootable images",
},
"page": {
Type: schema.TypeInt,
@@ -78,6 +134,10 @@ func dataSourceImageListSchemaMake() map[string]*schema.Schema {
Schema: dataSourceImageSchemaMake(),
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
return rets

View File

@@ -58,9 +58,9 @@ func flattenImage(d *schema.ResourceData, img *image.RecordImage) {
d.Set("version", img.Version)
}
func flattenImageList(il image.ListImages) []map[string]interface{} {
func flattenImageList(il *image.ListImages) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, img := range il {
for _, img := range il.Data {
temp := map[string]interface{}{
"account_id": img.AccountID,
"architecture": img.Architecture,

View File

@@ -19,7 +19,7 @@ func existAccountID(ctx context.Context, d *schema.ResourceData, m interface{})
return false, err
}
return len(accounts.FilterByID(accountId)) != 0, nil
return len(accounts.FilterByID(accountId).Data) != 0, nil
}
func existGID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
@@ -32,5 +32,5 @@ func existGID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool,
return false, err
}
return len(locationList.FilterByGID(gid)) != 0, nil
return len(locationList.FilterByGID(gid).Data) != 0, nil
}

View File

@@ -42,12 +42,56 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityImageListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (image.ListImages, error) {
func utilityImageListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*image.ListImages, error) {
c := m.(*controller.ControllerCfg)
req := image.ListRequest{}
if accountId, ok := d.GetOk("account_id"); ok {
req.AccountID = uint64(accountId.(int))
if sep_id, ok := d.GetOk("sep_id"); ok {
req.SEPID = uint64(sep_id.(int))
}
if by_id, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(by_id.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
if architecture, ok := d.GetOk("architecture"); ok {
req.Architecture = architecture.(string)
}
if type_image, ok := d.GetOk("type_image"); ok {
req.TypeImage = type_image.(string)
}
if image_size, ok := d.GetOk("image_size"); ok {
req.ImageSize = uint64(image_size.(int))
}
if sep_name, ok := d.GetOk("sep_name"); ok {
req.SEPName = sep_name.(string)
}
if pool, ok := d.GetOk("pool"); ok {
req.Pool = pool.(string)
}
if public, ok := d.GetOk("public"); ok {
req.Public = public.(bool)
}
if hot_resize, ok := d.GetOk("hot_resize"); ok {
req.HotResize = hot_resize.(bool)
}
if bootable, ok := d.GetOk("bootable"); ok {
req.Bootable = bootable.(bool)
}
if page, ok := d.GetOk("page"); ok {