Skip to content

Commit d00a7cd

Browse files
Adding Storagepool tier datasource (#259)
* Adding storagepool datasource
1 parent 9153356 commit d00a7cd

File tree

9 files changed

+601
-5
lines changed

9 files changed

+601
-5
lines changed

docs/data-sources/storagepool_tier.md

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
---
2+
# Copyright (c) 2024 Dell Inc., or its subsidiaries. All Rights Reserved.
3+
#
4+
# Licensed under the Mozilla Public License Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://mozilla.org/MPL/2.0/
9+
#
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
title: "powerscale_storagepool_tier data source"
18+
linkTitle: "powerscale_storagepool_tier"
19+
page_title: "powerscale_storagepool_tier Data Source - terraform-provider-powerscale"
20+
subcategory: ""
21+
description: |-
22+
This datasource is used to query the Storagepool tiers from PowerScale array. The information fetched from this datasource can be used for getting the details or for further processing in resource block. PowerScale Storagepool tiers provide the ability to configure Storagepool tiers on the cluster.
23+
---
24+
25+
# powerscale_storagepool_tier (Data Source)
26+
27+
This datasource is used to query the Storagepool tiers from PowerScale array. The information fetched from this datasource can be used for getting the details or for further processing in resource block. PowerScale Storagepool tiers provide the ability to configure Storagepool tiers on the cluster.
28+
29+
## Example Usage
30+
31+
```terraform
32+
/*
33+
Copyright (c) 2024 Dell Inc., or its subsidiaries. All Rights Reserved.
34+
35+
Licensed under the Mozilla Public License Version 2.0 (the "License");
36+
you may not use this file except in compliance with the License.
37+
You may obtain a copy of the License at
38+
39+
http://mozilla.org/MPL/2.0/
40+
41+
42+
Unless required by applicable law or agreed to in writing, software
43+
distributed under the License is distributed on an "AS IS" BASIS,
44+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
45+
See the License for the specific language governing permissions and
46+
limitations under the License.
47+
*/
48+
49+
# Returns a list of PowerScale Storage pool tier
50+
data "powerscale_storagepool_tier" "example_storagepool_tier" {
51+
52+
}
53+
54+
output "powerscale_storagepool_tier" {
55+
value = data.powerscale_storagepool_tier.example_storagepool_tier
56+
}
57+
```
58+
59+
<!-- schema generated by tfplugindocs -->
60+
## Schema
61+
62+
### Read-Only
63+
64+
- `id` (String) Id of Storagepool tiers. Readonly. Fixed value of "storagepool_tiers"
65+
- `storagepool_tiers` (Attributes List) List of Storagepool tiers (see [below for nested schema](#nestedatt--storagepool_tiers))
66+
67+
<a id="nestedatt--storagepool_tiers"></a>
68+
### Nested Schema for `storagepool_tiers`
69+
70+
Read-Only:
71+
72+
- `children` (List of String) The names or IDs of the tier's children.
73+
- `id` (String) Id of storagepool tier.
74+
- `lnns` (List of Number) The nodes that are part of this tier.
75+
- `name` (String) Name of storagepool tier.
76+
- `transfer_limit_pct` (Number) Stop moving files to this tier when this limit is met.
77+
- `transfer_limit_state` (String) How the transfer limit value is being applied.
78+
- `usage` (Attributes) Usage. (see [below for nested schema](#nestedatt--storagepool_tiers--usage))
79+
80+
<a id="nestedatt--storagepool_tiers--usage"></a>
81+
### Nested Schema for `storagepool_tiers.usage`
82+
83+
Read-Only:
84+
85+
- `avail_bytes` (String) Available free bytes remaining in the pool when virtual hot spare is taken into account.
86+
- `avail_hdd_bytes` (String) Available free bytes remaining in the pool on HDD drives when virtual hot spare is taken into account.
87+
- `avail_ssd_bytes` (String) Available free bytes remaining in the pool on SSD drives when virtual hot spare is taken into account.
88+
- `balanced` (Boolean) Whether or not the pool usage is currently balanced.
89+
- `free_bytes` (String) Free bytes remaining in the pool.
90+
- `free_hdd_bytes` (String) Free bytes remaining in the pool on HDD drives.
91+
- `free_ssd_bytes` (String) Free bytes remaining in the pool on SSD drives.
92+
- `pct_used` (String) Percentage of usable space in the pool which is used.
93+
- `pct_used_hdd` (String) Percentage of usable space on HDD drives in the pool which is used.
94+
- `pct_used_ssd` (String) Percentage of usable space on SSD drives in the pool which is used.
95+
- `total_bytes` (String) Total bytes in the pool.
96+
- `total_hdd_bytes` (String) Total bytes in the pool on HDD drives.
97+
- `total_ssd_bytes` (String) Total bytes in the pool on SSD drives.
98+
- `usable_bytes` (String) Total bytes in the pool drives when virtual hot spare is taken into account.
99+
- `usable_hdd_bytes` (String) Total bytes in the pool on HDD drives when virtual hot spare is taken into account.
100+
- `usable_ssd_bytes` (String) Total bytes in the pool on SSD drives when virtual hot spare is taken into account.
101+
- `used_bytes` (String) Used bytes in the pool.
102+
- `used_hdd_bytes` (String) Used bytes in the pool on HDD drives.
103+
- `used_ssd_bytes` (String) Used bytes in the pool on SSD drives.
104+
- `virtual_hot_spare_bytes` (String) Bytes reserved for virtual hot spare in the pool.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
Copyright (c) 2024 Dell Inc., or its subsidiaries. All Rights Reserved.
3+
4+
Licensed under the Mozilla Public License Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://mozilla.org/MPL/2.0/
9+
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
# Returns a list of PowerScale Storage pool tier
19+
data "powerscale_storagepool_tier" "example_storagepool_tier" {
20+
21+
}
22+
23+
output "powerscale_storagepool_tier" {
24+
value = data.powerscale_storagepool_tier.example_storagepool_tier
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
Copyright (c) 2024 Dell Inc., or its subsidiaries. All Rights Reserved.
3+
4+
Licensed under the Mozilla Public License Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://mozilla.org/MPL/2.0/
9+
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
terraform {
18+
required_providers {
19+
powerscale = {
20+
source = "registry.terraform.io/dell/powerscale"
21+
}
22+
}
23+
}
24+
25+
provider "powerscale" {
26+
username = var.username
27+
password = var.password
28+
endpoint = var.endpoint
29+
insecure = var.insecure
30+
}

powerscale/constants/constants.go

+3
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,9 @@ const (
497497
// ReadSyncIQReplicationJobErrorMessage specifies error details occurred while reading SyncIQ jobs.
498498
ReadSyncIQReplicationJobErrorMessage = "Could not read SyncIQ jobs "
499499

500+
// ReadStoragepoolTiersErrorMsg specifies error details occurred while reading storagepool tiers.
501+
ReadStoragepoolTiersErrorMsg = "Could not read storagepool tiers "
502+
500503
// ReadStoragepoolTierErrorMsg specifies error details occurred while reading Storage pool tiers.
501504
ReadStoragepoolTierErrorMsg = "Could not read storagepool tier "
502505

powerscale/helper/storagepool_tier_helper.go

+22-5
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,35 @@ package helper
2020
import (
2121
"context"
2222
powerscale "dell/powerscale-go-client"
23-
"strconv"
24-
2523
"fmt"
24+
"github.com/hashicorp/terraform-plugin-framework/diag"
25+
"github.com/hashicorp/terraform-plugin-framework/types"
2626
"math"
27+
"strconv"
2728
"terraform-provider-powerscale/client"
2829
"terraform-provider-powerscale/powerscale/constants"
2930
"terraform-provider-powerscale/powerscale/models"
30-
31-
"github.com/hashicorp/terraform-plugin-framework/diag"
32-
"github.com/hashicorp/terraform-plugin-framework/types"
3331
)
3432

33+
// GetStoragepoolTier gets storage pool tier.
34+
func GetStoragepoolTier(ctx context.Context, client *client.Client, path string) (*powerscale.V16StoragepoolTiersExtended, error) {
35+
StoragepoolTier, _, err := client.PscaleOpenAPIClient.StoragepoolApi.GetStoragepoolv16StoragepoolTier(ctx, path).Execute()
36+
return StoragepoolTier, err
37+
}
38+
39+
// GetAllStoragepoolTiers returns the full list of storage pool tiers.
40+
func GetAllStoragepoolTiers(ctx context.Context, client *client.Client) ([]powerscale.V16StoragepoolTierExtended, error) {
41+
StoragepoolTierParams := client.PscaleOpenAPIClient.StoragepoolApi.ListStoragepoolv16StoragepoolTiers(ctx)
42+
43+
StoragepoolTiers, _, err := StoragepoolTierParams.Execute()
44+
if err != nil {
45+
errStr := constants.ReadStoragepoolTiersErrorMsg + "with error: "
46+
message := GetErrorString(err, errStr)
47+
return nil, fmt.Errorf("error getting storagepool tiers: %s", message)
48+
}
49+
return StoragepoolTiers.Tiers, nil
50+
}
51+
3552
// CreateStoragepoolTier created the storagepool tier on the array.
3653
func CreateStoragepoolTier(ctx context.Context, client *client.Client, plan models.StoragepoolTierResourceModel, state *models.StoragepoolTierResourceModel) diag.Diagnostics {
3754
var diags diag.Diagnostics

powerscale/models/storagepool_tier.go

+40
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,46 @@ package models
1919

2020
import "github.com/hashicorp/terraform-plugin-framework/types"
2121

22+
// StoragepoolTierDataSourceModel describes the data source data model.
23+
type StoragepoolTierDataSourceModel struct {
24+
ID types.String `tfsdk:"id"`
25+
StoragepoolTier []StoragepoolTierModel `tfsdk:"storagepool_tiers"`
26+
}
27+
28+
// StoragepoolTierDetailModel details of the individual storage pool tier.
29+
type StoragepoolTierModel struct {
30+
Children types.List `tfsdk:"children"`
31+
Id types.String `tfsdk:"id"`
32+
Lnns types.List `tfsdk:"lnns"`
33+
Name types.String `tfsdk:"name"`
34+
TransferLimitPct types.Int64 `tfsdk:"transfer_limit_pct"`
35+
TransferLimitState types.String `tfsdk:"transfer_limit_state"`
36+
Usage *StoragepoolTierUsageModel `tfsdk:"usage"`
37+
}
38+
39+
type StoragepoolTierUsageModel struct {
40+
AvailBytes types.String `tfsdk:"avail_bytes"`
41+
AvailHddBytes types.String `tfsdk:"avail_hdd_bytes"`
42+
AvailSsdBytes types.String `tfsdk:"avail_ssd_bytes"`
43+
Balanced types.Bool `tfsdk:"balanced"`
44+
FreeBytes types.String `tfsdk:"free_bytes"`
45+
FreeHddBytes types.String `tfsdk:"free_hdd_bytes"`
46+
FreeSsdBytes types.String `tfsdk:"free_ssd_bytes"`
47+
PctUsed types.String `tfsdk:"pct_used"`
48+
PctUsedHdd types.String `tfsdk:"pct_used_hdd"`
49+
PctUsedSsd types.String `tfsdk:"pct_used_ssd"`
50+
TotalBytes types.String `tfsdk:"total_bytes"`
51+
TotalHddBytes types.String `tfsdk:"total_hdd_bytes"`
52+
TotalSsdBytes types.String `tfsdk:"total_ssd_bytes"`
53+
UsableBytes types.String `tfsdk:"usable_bytes"`
54+
UsableHddBytes types.String `tfsdk:"usable_hdd_bytes"`
55+
UsableSsdBytes types.String `tfsdk:"usable_ssd_bytes"`
56+
UsedBytes types.String `tfsdk:"used_bytes"`
57+
UsedHddBytes types.String `tfsdk:"used_hdd_bytes"`
58+
UsedSsdBytes types.String `tfsdk:"used_ssd_bytes"`
59+
VirtualHotSpareBytes types.String `tfsdk:"virtual_hot_spare_bytes"`
60+
}
61+
2262
type StoragepoolTierResourceModel struct {
2363
Children types.List `tfsdk:"children"`
2464
// Nodepools. The names or IDs of the tier's children.

powerscale/provider/provider.go

+1
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ func (p *PscaleProvider) DataSources(ctx context.Context) []func() datasource.Da
237237
NewSubnetDataSource,
238238
NewGroupnetDataSource,
239239
NewSmartPoolSettingDataSource,
240+
NewStoragepoolTierDataSource,
240241
NewNetworkSettingDataSource,
241242
NewNetworkRuleDataSource,
242243
NewLdapProviderDataSource,

0 commit comments

Comments
 (0)