Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for Large integer in Snapshot Ds Target ID #254

Merged
merged 12 commits into from
Nov 21, 2024
Merged
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,7 @@ generate:
cover:
rm -f coverage.*
go test -coverprofile=coverage.out ./...
go tool cover -html coverage.out -o coverage.html
go tool cover -html coverage.out -o coverage.html

sweep :
go test -v ./powerscale/provider -timeout 20m -sweep=all
2 changes: 1 addition & 1 deletion docs/data-sources/snapshot.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,5 @@ Read-Only:
- `shadow_bytes` (Number) The amount of shadow bytes referred to by this snapshot.
- `size` (Number) The amount of storage in bytes used to store this snapshot.
- `state` (String) Snapshot state.
- `target_id` (Number) The ID of the snapshot pointed to if this is an alias. 18446744073709551615 (max uint64) is returned for an alias to the live filesystem.
- `target_id` (Number) The ID of the snapshot pointed to if this is an alias. An alias to the live filesystem is represented by the value -1.
- `target_name` (String) The name of the snapshot pointed to if this is an alias.
3 changes: 2 additions & 1 deletion goClientZip/PowerScale_API_9.5.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -58825,7 +58825,8 @@
"description": "The ID of the snapshot pointed to if this is an alias. 18446744073709551615 (max uint64) is returned for an alias to the live filesystem.",
"maximum": 2147483646,
"minimum": 0,
"type": "integer"
"type": "integer",
"format": "unsigned64"
},
"target_name": {
"description": "The name of the snapshot pointed to if this is an alias.",
Expand Down
Binary file modified goClientZip/powerscale-go-client.zip
Binary file not shown.
6 changes: 4 additions & 2 deletions powerscale/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,20 @@ import (
powerscale "dell/powerscale-go-client"
"encoding/json"
"fmt"
"golang.org/x/net/html"
"math/big"
"net/http"
"reflect"
"strings"

"golang.org/x/net/html"

"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
)

// CopyFields copy the source of a struct to destination of struct with terraform types.
// Unsigned integers are not properly handled.
func CopyFields(ctx context.Context, source, destination interface{}) error {
tflog.Debug(ctx, "Copy fields", map[string]interface{}{
"source": source,
Expand Down Expand Up @@ -94,7 +96,7 @@ func CopyFields(ctx context.Context, source, destination interface{}) error {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
destinationFieldValue = types.Int64Value(sourceField.Int())
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
destinationFieldValue = types.Int64Value(sourceField.Int())
destinationFieldValue = types.Int64Value(int64(sourceField.Uint()))
case reflect.Float32, reflect.Float64:
// destinationFieldValue = types.Float64Value(sourceField.Float())
destinationFieldValue = types.NumberValue(big.NewFloat(sourceField.Float()))
Expand Down
8 changes: 8 additions & 0 deletions powerscale/helper/snapshot_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ func SnapshotDetailMapper(ctx context.Context, snap powerscale.V1SnapshotSnapsho
return model, err
}
model.ID = types.StringValue(fmt.Sprint(snap.Id))
// Max uint64 is returned when aliasing to live filesystem
// Other than that, valid targetIDs have a max value of max int64
// In Terraform, we shall represent by -1 live system alias by -1
if snap.TargetId == 18446744073709551615 {
model.TargetID = types.Int64Value(-1)
} else {
model.TargetID = types.Int64Value(int64(snap.TargetId))
}
model.TargetID = types.Int64Value(int64(snap.TargetId))
model.SetExpires = types.StringNull()
return model, nil
Expand Down
4 changes: 2 additions & 2 deletions powerscale/provider/snapshot_datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ func (d *SnapshotDataSource) Schema(ctx context.Context, req datasource.SchemaRe
Computed: true,
},
"target_id": schema.Int64Attribute{
Description: "The ID of the snapshot pointed to if this is an alias. 18446744073709551615 (max uint64) is returned for an alias to the live filesystem.",
MarkdownDescription: "The ID of the snapshot pointed to if this is an alias. 18446744073709551615 (max uint64) is returned for an alias to the live filesystem.",
Description: "The ID of the snapshot pointed to if this is an alias. An alias to the live filesystem is represented by the value -1.",
MarkdownDescription: "The ID of the snapshot pointed to if this is an alias. An alias to the live filesystem is represented by the value -1.",
Computed: true,
},
"target_name": schema.StringAttribute{
Expand Down
Loading