Skip to content

Commit

Permalink
Add fix for storage capacity & system pool output
Browse files Browse the repository at this point in the history
Add fix for storage capacity & system pool output
  • Loading branch information
rmoralesjr committed Oct 5, 2022
1 parent de6b694 commit 4be5d83
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 33 deletions.
1 change: 1 addition & 0 deletions ibm/flex/flatten.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func flatten(result map[string]string, prefix string, v reflect.Value) {
result[prefix] = "false"
}
case reflect.Int:
case reflect.Int64:
result[prefix] = fmt.Sprintf("%d", v.Int())
case reflect.Map:
flattenMap(result, prefix, v)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func dataSourceIBMPIStoragePoolCapacityRead(ctx context.Context, d *schema.Resou

d.SetId(fmt.Sprintf("%s/%s", cloudInstanceID, storagePool))

d.Set(MaxAllocationSize, sp.MaxAllocationSize)
d.Set(MaxAllocationSize, *sp.MaxAllocationSize)
d.Set(StorageType, sp.StorageType)
d.Set(TotalCapacity, sp.TotalCapacity)

Expand Down
12 changes: 6 additions & 6 deletions ibm/service/power/data_source_ibm_pi_storage_pools_capacity.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,22 @@ func dataSourceIBMPIStoragePoolsCapacityRead(ctx context.Context, d *schema.Reso
if spc.MaximumStorageAllocation != nil {
msa := spc.MaximumStorageAllocation
data := map[string]interface{}{
MaxAllocationSize: msa.MaxAllocationSize,
StoragePool: msa.StoragePool,
StorageType: msa.StorageType,
MaxAllocationSize: *msa.MaxAllocationSize,
StoragePool: *msa.StoragePool,
StorageType: *msa.StorageType,
}
d.Set(MaximumStorageAllocation, flex.Flatten(data))
}

result := make([]map[string]string, 0, len(spc.StoragePoolsCapacity))
result := make([]map[string]interface{}, 0, len(spc.StoragePoolsCapacity))
for _, sp := range spc.StoragePoolsCapacity {
data := map[string]interface{}{
MaxAllocationSize: sp.MaxAllocationSize,
MaxAllocationSize: *sp.MaxAllocationSize,
PoolName: sp.PoolName,
StorageType: sp.StorageType,
TotalCapacity: sp.TotalCapacity,
}
result = append(result, flex.Flatten(data))
result = append(result, data)
}
d.Set(StoragePoolsCapacity, result)

Expand Down
12 changes: 6 additions & 6 deletions ibm/service/power/data_source_ibm_pi_storage_type_capacity.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,22 @@ func dataSourceIBMPIStorageTypeCapacityRead(ctx context.Context, d *schema.Resou
if stc.MaximumStorageAllocation != nil {
msa := stc.MaximumStorageAllocation
data := map[string]interface{}{
MaxAllocationSize: msa.MaxAllocationSize,
StoragePool: msa.StoragePool,
StorageType: msa.StorageType,
MaxAllocationSize: *msa.MaxAllocationSize,
StoragePool: *msa.StoragePool,
StorageType: *msa.StorageType,
}
d.Set(MaximumStorageAllocation, flex.Flatten(data))
}

result := make([]map[string]string, 0, len(stc.StoragePoolsCapacity))
result := make([]map[string]interface{}, 0, len(stc.StoragePoolsCapacity))
for _, sp := range stc.StoragePoolsCapacity {
data := map[string]interface{}{
MaxAllocationSize: sp.MaxAllocationSize,
MaxAllocationSize: *sp.MaxAllocationSize,
PoolName: sp.PoolName,
StorageType: sp.StorageType,
TotalCapacity: sp.TotalCapacity,
}
result = append(result, flex.Flatten(data))
result = append(result, data)
}
d.Set(StoragePoolsCapacity, result)

Expand Down
18 changes: 9 additions & 9 deletions ibm/service/power/data_source_ibm_pi_storage_types_capacity.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ func dataSourceIBMPIStorageTypesCapacityRead(ctx context.Context, d *schema.Reso
if stc.MaximumStorageAllocation != nil {
msa := stc.MaximumStorageAllocation
data := map[string]interface{}{
MaxAllocationSize: msa.MaxAllocationSize,
StoragePool: msa.StoragePool,
StorageType: msa.StorageType,
MaxAllocationSize: *msa.MaxAllocationSize,
StoragePool: *msa.StoragePool,
StorageType: *msa.StorageType,
}
d.Set(MaximumStorageAllocation, flex.Flatten(data))
}
Expand All @@ -124,21 +124,21 @@ func dataSourceIBMPIStorageTypesCapacityRead(ctx context.Context, d *schema.Reso
if st.MaximumStorageAllocation != nil {
msa := st.MaximumStorageAllocation
data := map[string]interface{}{
MaxAllocationSize: msa.MaxAllocationSize,
StoragePool: msa.StoragePool,
StorageType: msa.StorageType,
MaxAllocationSize: *msa.MaxAllocationSize,
StoragePool: *msa.StoragePool,
StorageType: *msa.StorageType,
}
stResult[MaximumStorageAllocation] = flex.Flatten(data)
}
spc := make([]map[string]string, 0, len(st.StoragePoolsCapacity))
spc := make([]map[string]interface{}, 0, len(st.StoragePoolsCapacity))
for _, sp := range st.StoragePoolsCapacity {
data := map[string]interface{}{
MaxAllocationSize: sp.MaxAllocationSize,
MaxAllocationSize: *sp.MaxAllocationSize,
PoolName: sp.PoolName,
StorageType: sp.StorageType,
TotalCapacity: sp.TotalCapacity,
}
spc = append(spc, flex.Flatten(data))
spc = append(spc, data)
}
stResult[StoragePoolsCapacity] = spc
stResult[StorageType] = st.StorageType
Expand Down
22 changes: 15 additions & 7 deletions ibm/service/power/data_source_ibm_pi_system_pools.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ func dataSourceIBMPISystemPoolsRead(ctx context.Context, d *schema.ResourceData,
for s, sp := range sps {
data := map[string]interface{}{
SystemPoolName: s,
Capacity: flattenSystem(sp.Capacity),
Capacity: flattenMax(sp.Capacity),
CoreMemoryRatio: sp.CoreMemoryRatio,
MaxAvailable: flattenSystem(sp.MaxAvailable),
MaxCoresAvailable: flattenSystem(sp.MaxCoresAvailable),
MaxMemoryAvailable: flattenSystem(sp.MaxMemoryAvailable),
MaxAvailable: flattenMax(sp.MaxAvailable),
MaxCoresAvailable: flattenMax(sp.MaxCoresAvailable),
MaxMemoryAvailable: flattenMax(sp.MaxMemoryAvailable),
SharedCoreRatio: flattenSharedCoreRatio(sp.SharedCoreRatio),
Type: sp.Type,
Systems: flattenSystems(sp.Systems),
Expand All @@ -167,18 +167,26 @@ func dataSourceIBMPISystemPoolsRead(ctx context.Context, d *schema.ResourceData,
return nil
}

func flattenMax(s *models.System) map[string]string {
ret := map[string]interface{}{
Cores: *s.Cores,
Memory: *s.Memory,
}
return flex.Flatten(ret)
}

func flattenSystem(s *models.System) map[string]string {
ret := map[string]interface{}{
Cores: s.Cores,
Cores: *s.Cores,
ID: s.ID,
Memory: s.Memory,
Memory: *s.Memory,
}
return flex.Flatten(ret)
}

func flattenSystems(sl []*models.System) (systems []map[string]string) {
if sl != nil {
systems = make([]map[string]string, len(sl))
systems = make([]map[string]string, 0, len(sl))
for _, s := range sl {
systems = append(systems, flattenSystem(s))
}
Expand Down
4 changes: 0 additions & 4 deletions website/docs/d/pi_system_pools.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,25 @@ In addition to all argument reference list, you can access the following attribu

Nested scheme for `capacity`:
- `cores` - (String) The host available Processor units.
- `id` - (String) The host identifier.
- `memory`- (String) The host available RAM memory in GiB.

- `core_memory_ratio` - (Float) Processor to Memory (GB) Ratio.
- `max_available` - (Map) Maximum configurable cores and memory (GB) (aggregated from all hosts).

Nested scheme for `max_available`:
- `cores` - (String) The host available Processor units.
- `id` - (String) The host identifier.
- `memory`- (String) The host available RAM memory in GiB.

- `max_cores_available` - (Map) Maximum configurable cores available combined with available memory of that host.

Nested scheme for `max_cores_available`:
- `cores` - (String) The host available Processor units.
- `id` - (String) The host identifier.
- `memory`- (String) The host available RAM memory in GiB.

- `max_memory_available` - (Map) Maximum configurable memory available combined with available cores of that host.

Nested scheme for `max_memory_available`:
- `cores` - (String) The host available Processor units.
- `id` - (String) The host identifier.
- `memory`- (String) The host available RAM memory in GiB.

- `shared_core_ratio` - (Map) The min-max-default allocation percentage of shared core per vCPU.
Expand Down

0 comments on commit 4be5d83

Please sign in to comment.