This commit is contained in:
2026-09-21 11:51:12 +03:00
parent 9cd93e4277
commit 2b229a84fb
240 changed files with 7735 additions and 3166 deletions

View File

@@ -50,7 +50,7 @@ func dataSourceSepConsumptionRead(ctx context.Context, d *schema.ResourceData, m
id := uuid.New()
d.SetId(id.String())
flattenSepConsumption(d, sepCons)
flattenSepConsumptionList(d, sepCons)
return nil
}

View File

@@ -110,15 +110,28 @@ func flattenSepPoolUris(rp *sep.RecordPool) []map[string]interface{} {
return res
}
func flattenSepConsumption(d *schema.ResourceData, sepCons *sep.RecordConsumption) {
d.Set("type", sepCons.Type)
d.Set("total", flattenSepConsumptionTotal(sepCons.Total))
d.Set("by_pool", flattenSepConsumptionPools(sepCons))
func flattenSepConsumptionList(d *schema.ResourceData, list *sep.ListConsumption) {
d.Set("entry_count", list.EntryCount)
d.Set("items", flattenSepConsumptionItems(list.Data))
}
func flattenSepConsumptionItems(records []sep.RecordConsumption) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(records))
for _, r := range records {
res = append(res, map[string]interface{}{
"sep_id": r.ID,
"name": r.Name,
"type": r.Type,
"consumed_by": r.ConsumedBy,
"total": flattenSepConsumptionTotal(r.Total),
"by_pool": flattenSepConsumptionPools(r.ByPool),
})
}
return res
}
func flattenSepConsumptionTotal(sc sep.Total) []map[string]interface{} {
sh := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
return []map[string]interface{}{{
"capacity_limit": sc.CapacityLimit,
"disk_count": sc.DiskCount,
"disk_usage": sc.DiskUsage,
@@ -126,15 +139,13 @@ func flattenSepConsumptionTotal(sc sep.Total) []map[string]interface{} {
"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{}{
func flattenSepConsumptionPools(byPool map[string]sep.ByPool) []map[string]interface{} {
sh := make([]map[string]interface{}, 0, len(byPool))
for key, value := range byPool {
sh = append(sh, map[string]interface{}{
"name": key,
"disk_count": value.DiskCount,
"disk_usage": value.DiskUsage,
@@ -142,8 +153,7 @@ func flattenSepConsumptionPools(bp *sep.RecordConsumption) []map[string]interfac
"snapshot_usage": value.SnapshotUsage,
"usage": value.Usage,
"usage_limit": value.UsageLimit,
}
sh = append(sh, temp)
})
}
return sh
}

View File

@@ -129,102 +129,134 @@ func dataSourceSepConsumptionSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"sep_id": {
Type: schema.TypeInt,
Required: true,
Optional: true,
Description: "sep id",
},
"by_pool": {
"entry_count": {
Type: schema.TypeInt,
Computed: true,
Description: "number of entries",
},
"items": {
Type: schema.TypeList,
Computed: true,
Description: "consumption divided by pool",
Description: "list of sep consumption records",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"sep_id": {
Type: schema.TypeInt,
Computed: true,
Description: "sep id",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "pool name",
Description: "sep name",
},
"disk_count": {
Type: schema.TypeInt,
"type": {
Type: schema.TypeString,
Computed: true,
Description: "number of disks",
Description: "sep type",
},
"disk_usage": {
Type: schema.TypeInt,
"consumed_by": {
Type: schema.TypeList,
Computed: true,
Description: "disk usage",
Description: "list of consumer node IDs",
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"snapshot_count": {
Type: schema.TypeInt,
"by_pool": {
Type: schema.TypeList,
Computed: true,
Description: "number of snapshots",
Description: "consumption divided by pool",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
Description: "pool name",
},
"disk_count": {
Type: schema.TypeInt,
Computed: true,
Description: "number of disks",
},
"disk_usage": {
Type: schema.TypeInt,
Computed: true,
Description: "disk usage",
},
"snapshot_count": {
Type: schema.TypeInt,
Computed: true,
Description: "number of snapshots",
},
"snapshot_usage": {
Type: schema.TypeInt,
Computed: true,
Description: "snapshot usage",
},
"usage": {
Type: schema.TypeInt,
Computed: true,
Description: "usage",
},
"usage_limit": {
Type: schema.TypeInt,
Computed: true,
Description: "usage limit",
},
},
},
},
"snapshot_usage": {
Type: schema.TypeInt,
"total": {
Type: schema.TypeList,
Computed: true,
Description: "snapshot usage",
},
"usage": {
Type: schema.TypeInt,
Computed: true,
Description: "usage",
},
"usage_limit": {
Type: schema.TypeInt,
Computed: true,
Description: "usage limit",
Description: "total consumption",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"capacity_limit": {
Type: schema.TypeInt,
Computed: true,
Description: "capacity limit",
},
"disk_count": {
Type: schema.TypeInt,
Computed: true,
Description: "number of disks",
},
"disk_usage": {
Type: schema.TypeInt,
Computed: true,
Description: "disk usage",
},
"snapshot_count": {
Type: schema.TypeInt,
Computed: true,
Description: "number of snapshots",
},
"snapshot_usage": {
Type: schema.TypeInt,
Computed: true,
Description: "snapshot usage",
},
"usage": {
Type: schema.TypeInt,
Computed: true,
Description: "usage",
},
"usage_limit": {
Type: schema.TypeInt,
Computed: true,
Description: "usage limit",
},
},
},
},
},
},
},
"total": {
Type: schema.TypeList,
Computed: true,
Description: "total consumption",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"capacity_limit": {
Type: schema.TypeInt,
Computed: true,
Description: "capacity limit",
},
"disk_count": {
Type: schema.TypeInt,
Computed: true,
Description: "number of disks",
},
"disk_usage": {
Type: schema.TypeInt,
Computed: true,
Description: "disk usage",
},
"snapshot_count": {
Type: schema.TypeInt,
Computed: true,
Description: "number of snapshots",
},
"snapshot_usage": {
Type: schema.TypeInt,
Computed: true,
Description: "snapshot usage",
},
"usage": {
Type: schema.TypeInt,
Computed: true,
Description: "usage",
},
"usage_limit": {
Type: schema.TypeInt,
Computed: true,
Description: "usage limit",
},
},
},
},
"type": {
Type: schema.TypeString,
Computed: true,
Description: "sep type",
},
}
}
@@ -522,6 +554,7 @@ func resourceSepSchemaMake() map[string]*schema.Schema {
Optional: true,
Computed: true,
Description: "grant or revoke access to pool",
Deprecated: "\"access_to_pool\" is deprecated and will be removed in version 4.14.0",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"pool_name": {
@@ -546,6 +579,7 @@ func resourceSepSchemaMake() map[string]*schema.Schema {
Type: schema.TypeSet,
Optional: true,
Description: "lift of account ids to have access to sep",
Deprecated: "\"account_ids\" is deprecated and will be removed in version 4.14.0",
Elem: &schema.Schema{
Type: schema.TypeInt,
},

View File

@@ -39,16 +39,16 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilitySepConsumptionCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*sep.RecordConsumption, error) {
func utilitySepConsumptionCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*sep.ListConsumption, error) {
c := m.(*controller.ControllerCfg)
req := sep.ConsumptionRequest{
SEPID: uint64(d.Get("sep_id").(int)),
}
sepCons, err := c.CloudBroker().SEP().Consumption(ctx, req)
result, err := c.CloudBroker().SEP().Consumption(ctx, req)
if err != nil {
return nil, err
}
return sepCons, nil
return result, nil
}