Skip to content

Commit

Permalink
US69000: Adding support for new volume attributes in schema (#217)
Browse files Browse the repository at this point in the history
* volume: support for new attributes in schema

* volume: lint-fix for error check

* pkg: update hpegl-metal-client to v1.5.21

* pkg: go mod tidy

* version: bumping the version to the next release version

* volume: remove method name from error context
  • Loading branch information
achu-1612 authored Sep 2, 2024
1 parent 8ae9240 commit 850d1d0
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 20 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/golangci/golangci-lint v1.58.2
github.com/hashicorp/terraform-plugin-docs v0.19.4
github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0
github.com/hewlettpackard/hpegl-metal-client v1.5.19
github.com/hewlettpackard/hpegl-metal-client v1.5.21
github.com/hewlettpackard/hpegl-provider-lib v0.0.18
github.com/stretchr/testify v1.9.0
gopkg.in/yaml.v2 v2.4.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,8 @@ github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S
github.com/hashicorp/terraform-svchost v0.1.1/go.mod h1:mNsjQfZyf/Jhz35v6/0LWcv26+X7JPS+buii2c9/ctc=
github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE=
github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
github.com/hewlettpackard/hpegl-metal-client v1.5.19 h1:Y3RizmAi5H+RtzdozDywUg/0/aupDltW5b+HrzgIQeQ=
github.com/hewlettpackard/hpegl-metal-client v1.5.19/go.mod h1:+BO4BfQXf3IWnsxvk2IdE27Ijrm1jDVYIgpebYh1L9M=
github.com/hewlettpackard/hpegl-metal-client v1.5.21 h1:3/9hC2eByX9NpPUd9+0IM7axw4nlG9izyBqWaVc3RTA=
github.com/hewlettpackard/hpegl-metal-client v1.5.21/go.mod h1:+BO4BfQXf3IWnsxvk2IdE27Ijrm1jDVYIgpebYh1L9M=
github.com/hewlettpackard/hpegl-provider-lib v0.0.18 h1:87iXgq8Oe2ebBRicL5K+HknQF9e1ce6MHfIHeTVVqlI=
github.com/hewlettpackard/hpegl-provider-lib v0.0.18/go.mod h1:Bw2DhefBjqXQI6s5vBBGiWUkFz7fx4KkbGfwmo9wv3U=
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
Expand Down
97 changes: 81 additions & 16 deletions internal/resources/resource_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,27 @@ import (
)

const (
vName = "name"
vDescription = "description"
vLocation = "location"
vLocationID = "location_id"
vFlavorID = "flavor_id"
vFlavor = "flavor"
vSize = "size"
vShareable = "shareable"
vState = "state"
vStatus = "status"
vLabels = "labels"
vWWN = "wwn"
vStoragePool = "storage_pool"
vStoragePoolID = "storage_pool_id"
vCollection = "volume_collection"
vCollectionID = "volume_collection_id"
vName = "name"
vDescription = "description"
vLocation = "location"
vLocationID = "location_id"
vFlavorID = "flavor_id"
vFlavor = "flavor"
vSize = "size"
vSizeInUse = "size_in_use"
vShareable = "shareable"
vState = "state"
vStatus = "status"
vLabels = "labels"
vWWN = "wwn"
vStoragePool = "storage_pool"
vStoragePoolID = "storage_pool_id"
vCollection = "volume_collection"
vCollectionID = "volume_collection_id"
vUnManaged = "unmanaged"
vActiveSite = "active_site"
vCreatedSite = "created_site"
vReplicationEnabled = "replication_enabled"

// volume Info constants.
vID = "id"
Expand Down Expand Up @@ -100,6 +105,14 @@ func volumeSchema() map[string]*schema.Schema {
},
},

vSizeInUse: {
Type: schema.TypeFloat,
Required: false,
Optional: false,
Computed: true,
Description: "The amount of the volume currently used as reported by the array in GBytes.",
},

vShareable: {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -157,6 +170,38 @@ func volumeSchema() map[string]*schema.Schema {
Computed: true,
Description: "The volume collection ID of the volume to be created.",
},

vUnManaged: {
Type: schema.TypeBool,
Required: false,
Optional: false,
Computed: true,
Description: "Indicates whether the volume is a native Metal created one or an external one.",
},

vReplicationEnabled: {
Type: schema.TypeBool,
Required: false,
Optional: false,
Computed: true,
Description: "Indicates whether replication is enabled for this volume.",
},

vActiveSite: {
Type: schema.TypeString,
Required: false,
Optional: false,
Computed: true,
Description: "The site where the remote copy role for the volume is Primary at the time of most recent import.",
},

vCreatedSite: {
Type: schema.TypeString,
Required: false,
Optional: false,
Computed: true,
Description: "The site where the volume was originally created.",
},
}
}

Expand Down Expand Up @@ -326,6 +371,26 @@ func resourceMetalVolumeRead(d *schema.ResourceData, meta interface{}) (err erro
return fmt.Errorf("set Size: %v", err)
}

if err = d.Set(vSizeInUse, math.Round(float64(volume.CapacityUsed)/KiBToGBConversion)); err != nil {
return fmt.Errorf("set %s : %v", vSizeInUse, err)
}

if err := d.Set(vActiveSite, volume.ActiveSite); err != nil {
return fmt.Errorf("set %s : %v", vActiveSite, err)
}

if err := d.Set(vCreatedSite, volume.CreatedSite); err != nil {
return fmt.Errorf("set %s : %v", vCreatedSite, err)
}

if err := d.Set(vUnManaged, volume.UnmanagedVolume); err != nil {
return fmt.Errorf("set %s : %v", vUnManaged, err)
}

if err := d.Set(vReplicationEnabled, volume.ReplicationEnabled); err != nil {
return fmt.Errorf("set %s : %v", vReplicationEnabled, err)
}

d.Set(vName, volume.Name)
d.Set(vDescription, volume.Description)
flavorName, _ := p.GetVolumeFlavorName(volume.FlavorID)
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.59
1.3.61

0 comments on commit 850d1d0

Please sign in to comment.