Skip to content

Commit

Permalink
Adding Storagepool tier datasource (#259)
Browse files Browse the repository at this point in the history
* Adding storagepool datasource
  • Loading branch information
ABHISHEK-SINHA10 authored Dec 11, 2024
1 parent 9153356 commit d00a7cd
Show file tree
Hide file tree
Showing 9 changed files with 601 additions and 5 deletions.
104 changes: 104 additions & 0 deletions docs/data-sources/storagepool_tier.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
---
# Copyright (c) 2024 Dell Inc., or its subsidiaries. All Rights Reserved.
#
# Licensed under the Mozilla Public 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://mozilla.org/MPL/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.

title: "powerscale_storagepool_tier data source"
linkTitle: "powerscale_storagepool_tier"
page_title: "powerscale_storagepool_tier Data Source - terraform-provider-powerscale"
subcategory: ""
description: |-
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.
---

# powerscale_storagepool_tier (Data Source)

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.

## Example Usage

```terraform
/*
Copyright (c) 2024 Dell Inc., or its subsidiaries. All Rights Reserved.
Licensed under the Mozilla Public 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://mozilla.org/MPL/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.
*/
# Returns a list of PowerScale Storage pool tier
data "powerscale_storagepool_tier" "example_storagepool_tier" {
}
output "powerscale_storagepool_tier" {
value = data.powerscale_storagepool_tier.example_storagepool_tier
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Read-Only

- `id` (String) Id of Storagepool tiers. Readonly. Fixed value of "storagepool_tiers"
- `storagepool_tiers` (Attributes List) List of Storagepool tiers (see [below for nested schema](#nestedatt--storagepool_tiers))

<a id="nestedatt--storagepool_tiers"></a>
### Nested Schema for `storagepool_tiers`

Read-Only:

- `children` (List of String) The names or IDs of the tier's children.
- `id` (String) Id of storagepool tier.
- `lnns` (List of Number) The nodes that are part of this tier.
- `name` (String) Name of storagepool tier.
- `transfer_limit_pct` (Number) Stop moving files to this tier when this limit is met.
- `transfer_limit_state` (String) How the transfer limit value is being applied.
- `usage` (Attributes) Usage. (see [below for nested schema](#nestedatt--storagepool_tiers--usage))

<a id="nestedatt--storagepool_tiers--usage"></a>
### Nested Schema for `storagepool_tiers.usage`

Read-Only:

- `avail_bytes` (String) Available free bytes remaining in the pool when virtual hot spare is taken into account.
- `avail_hdd_bytes` (String) Available free bytes remaining in the pool on HDD drives when virtual hot spare is taken into account.
- `avail_ssd_bytes` (String) Available free bytes remaining in the pool on SSD drives when virtual hot spare is taken into account.
- `balanced` (Boolean) Whether or not the pool usage is currently balanced.
- `free_bytes` (String) Free bytes remaining in the pool.
- `free_hdd_bytes` (String) Free bytes remaining in the pool on HDD drives.
- `free_ssd_bytes` (String) Free bytes remaining in the pool on SSD drives.
- `pct_used` (String) Percentage of usable space in the pool which is used.
- `pct_used_hdd` (String) Percentage of usable space on HDD drives in the pool which is used.
- `pct_used_ssd` (String) Percentage of usable space on SSD drives in the pool which is used.
- `total_bytes` (String) Total bytes in the pool.
- `total_hdd_bytes` (String) Total bytes in the pool on HDD drives.
- `total_ssd_bytes` (String) Total bytes in the pool on SSD drives.
- `usable_bytes` (String) Total bytes in the pool drives when virtual hot spare is taken into account.
- `usable_hdd_bytes` (String) Total bytes in the pool on HDD drives when virtual hot spare is taken into account.
- `usable_ssd_bytes` (String) Total bytes in the pool on SSD drives when virtual hot spare is taken into account.
- `used_bytes` (String) Used bytes in the pool.
- `used_hdd_bytes` (String) Used bytes in the pool on HDD drives.
- `used_ssd_bytes` (String) Used bytes in the pool on SSD drives.
- `virtual_hot_spare_bytes` (String) Bytes reserved for virtual hot spare in the pool.
25 changes: 25 additions & 0 deletions examples/data-sources/powerscale_storagepool_tier/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
Copyright (c) 2024 Dell Inc., or its subsidiaries. All Rights Reserved.
Licensed under the Mozilla Public 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://mozilla.org/MPL/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.
*/

# Returns a list of PowerScale Storage pool tier
data "powerscale_storagepool_tier" "example_storagepool_tier" {

}

output "powerscale_storagepool_tier" {
value = data.powerscale_storagepool_tier.example_storagepool_tier
}
30 changes: 30 additions & 0 deletions examples/data-sources/powerscale_storagepool_tier/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
Copyright (c) 2024 Dell Inc., or its subsidiaries. All Rights Reserved.
Licensed under the Mozilla Public 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://mozilla.org/MPL/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 {
required_providers {
powerscale = {
source = "registry.terraform.io/dell/powerscale"
}
}
}

provider "powerscale" {
username = var.username
password = var.password
endpoint = var.endpoint
insecure = var.insecure
}
3 changes: 3 additions & 0 deletions powerscale/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,9 @@ const (
// ReadSyncIQReplicationJobErrorMessage specifies error details occurred while reading SyncIQ jobs.
ReadSyncIQReplicationJobErrorMessage = "Could not read SyncIQ jobs "

// ReadStoragepoolTiersErrorMsg specifies error details occurred while reading storagepool tiers.
ReadStoragepoolTiersErrorMsg = "Could not read storagepool tiers "

// ReadStoragepoolTierErrorMsg specifies error details occurred while reading Storage pool tiers.
ReadStoragepoolTierErrorMsg = "Could not read storagepool tier "

Expand Down
27 changes: 22 additions & 5 deletions powerscale/helper/storagepool_tier_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,35 @@ package helper
import (
"context"
powerscale "dell/powerscale-go-client"
"strconv"

"fmt"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
"math"
"strconv"
"terraform-provider-powerscale/client"
"terraform-provider-powerscale/powerscale/constants"
"terraform-provider-powerscale/powerscale/models"

"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
)

// GetStoragepoolTier gets storage pool tier.
func GetStoragepoolTier(ctx context.Context, client *client.Client, path string) (*powerscale.V16StoragepoolTiersExtended, error) {
StoragepoolTier, _, err := client.PscaleOpenAPIClient.StoragepoolApi.GetStoragepoolv16StoragepoolTier(ctx, path).Execute()
return StoragepoolTier, err
}

// GetAllStoragepoolTiers returns the full list of storage pool tiers.
func GetAllStoragepoolTiers(ctx context.Context, client *client.Client) ([]powerscale.V16StoragepoolTierExtended, error) {
StoragepoolTierParams := client.PscaleOpenAPIClient.StoragepoolApi.ListStoragepoolv16StoragepoolTiers(ctx)

StoragepoolTiers, _, err := StoragepoolTierParams.Execute()
if err != nil {
errStr := constants.ReadStoragepoolTiersErrorMsg + "with error: "
message := GetErrorString(err, errStr)
return nil, fmt.Errorf("error getting storagepool tiers: %s", message)
}
return StoragepoolTiers.Tiers, nil
}

// CreateStoragepoolTier created the storagepool tier on the array.
func CreateStoragepoolTier(ctx context.Context, client *client.Client, plan models.StoragepoolTierResourceModel, state *models.StoragepoolTierResourceModel) diag.Diagnostics {
var diags diag.Diagnostics
Expand Down
40 changes: 40 additions & 0 deletions powerscale/models/storagepool_tier.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,46 @@ package models

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

// StoragepoolTierDataSourceModel describes the data source data model.
type StoragepoolTierDataSourceModel struct {
ID types.String `tfsdk:"id"`
StoragepoolTier []StoragepoolTierModel `tfsdk:"storagepool_tiers"`
}

// StoragepoolTierDetailModel details of the individual storage pool tier.
type StoragepoolTierModel struct {
Children types.List `tfsdk:"children"`
Id types.String `tfsdk:"id"`
Lnns types.List `tfsdk:"lnns"`
Name types.String `tfsdk:"name"`
TransferLimitPct types.Int64 `tfsdk:"transfer_limit_pct"`
TransferLimitState types.String `tfsdk:"transfer_limit_state"`
Usage *StoragepoolTierUsageModel `tfsdk:"usage"`
}

type StoragepoolTierUsageModel struct {
AvailBytes types.String `tfsdk:"avail_bytes"`
AvailHddBytes types.String `tfsdk:"avail_hdd_bytes"`
AvailSsdBytes types.String `tfsdk:"avail_ssd_bytes"`
Balanced types.Bool `tfsdk:"balanced"`
FreeBytes types.String `tfsdk:"free_bytes"`
FreeHddBytes types.String `tfsdk:"free_hdd_bytes"`
FreeSsdBytes types.String `tfsdk:"free_ssd_bytes"`
PctUsed types.String `tfsdk:"pct_used"`
PctUsedHdd types.String `tfsdk:"pct_used_hdd"`
PctUsedSsd types.String `tfsdk:"pct_used_ssd"`
TotalBytes types.String `tfsdk:"total_bytes"`
TotalHddBytes types.String `tfsdk:"total_hdd_bytes"`
TotalSsdBytes types.String `tfsdk:"total_ssd_bytes"`
UsableBytes types.String `tfsdk:"usable_bytes"`
UsableHddBytes types.String `tfsdk:"usable_hdd_bytes"`
UsableSsdBytes types.String `tfsdk:"usable_ssd_bytes"`
UsedBytes types.String `tfsdk:"used_bytes"`
UsedHddBytes types.String `tfsdk:"used_hdd_bytes"`
UsedSsdBytes types.String `tfsdk:"used_ssd_bytes"`
VirtualHotSpareBytes types.String `tfsdk:"virtual_hot_spare_bytes"`
}

type StoragepoolTierResourceModel struct {
Children types.List `tfsdk:"children"`
// Nodepools. The names or IDs of the tier's children.
Expand Down
1 change: 1 addition & 0 deletions powerscale/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ func (p *PscaleProvider) DataSources(ctx context.Context) []func() datasource.Da
NewSubnetDataSource,
NewGroupnetDataSource,
NewSmartPoolSettingDataSource,
NewStoragepoolTierDataSource,
NewNetworkSettingDataSource,
NewNetworkRuleDataSource,
NewLdapProviderDataSource,
Expand Down
Loading

0 comments on commit d00a7cd

Please sign in to comment.