Skip to content

Commit

Permalink
Merge pull request #193 from NetApp/integration/main
Browse files Browse the repository at this point in the history
Sync bitbucket and GitHub
  • Loading branch information
wenjun666 authored May 1, 2024
2 parents 00272b4 + 8605b51 commit 7503b7b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 24.3.0
BUG FIXES:
* resoruce/volume: support `comment` update with adding 3 minutes wait time.

## 24.2.0
NEW FEATURES:
* resource/connector_aws: support `instance_metadata` block.
Expand Down
32 changes: 22 additions & 10 deletions cloudmanager/resource_netapp_cloudmanager_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"log"
"strings"
"time"

"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
Expand Down Expand Up @@ -515,14 +516,14 @@ func resourceCVOVolumeRead(d *schema.ResourceData, meta interface{}) error {
}
}
volume.SvmName = svm

res, err := client.getVolume(volume, clientID)
if err != nil {
log.Print("Error reading volume")
return err
}
for _, volume := range res {
if volume.ID == d.Id() {
log.Printf("### Fetching volume: %#v", volume)
if _, ok := d.GetOk("aggregate_name"); ok {
d.Set("aggregate_name", volume.AggregateName)
}
Expand Down Expand Up @@ -744,8 +745,8 @@ func resourceCVOVolumeUpdate(d *schema.ResourceData, meta interface{}) error {
if !exportPolicyTypeOK || !exportPolicyIPOK || !exportPolicyNfsVersionOK || !exportPolicyRuleAccessControlOK || !exportPolicyRuleSuperUserOK {
return fmt.Errorf("export_policy_type, export_policy_ip, export_policy_nfs_version, export_policy_rule_access_control and export_policy_rule_super_user are required for export policy")
}
var rules []ExportPolicyRule
rules = make([]ExportPolicyRule, len(volume.ExportPolicyInfo.Ips))

rules := make([]ExportPolicyRule, len(volume.ExportPolicyInfo.Ips))
for i, x := range volume.ExportPolicyInfo.Ips {
rules[i] = ExportPolicyRule{}
eachRule := make([]string, 1)
Expand Down Expand Up @@ -777,12 +778,15 @@ func resourceCVOVolumeUpdate(d *schema.ResourceData, meta interface{}) error {
if d.HasChange("export_policy_name") {
volume.ExportPolicyInfo.Name = d.Get("export_policy_name").(string)
}
if v, ok := d.GetOk("export_policy_nfs_version"); ok {
nfs := make([]string, 0, v.(*schema.Set).Len())
for _, x := range v.(*schema.Set).List() {
nfs = append(nfs, x.(string))
// set values on export policy nfs version only when export policy nfs version is changed
if d.HasChange("export_policy_nfs_version") {
if v, ok := d.GetOk("export_policy_nfs_version"); ok {
nfs := make([]string, 0, v.(*schema.Set).Len())
for _, x := range v.(*schema.Set).List() {
nfs = append(nfs, x.(string))
}
volume.ExportPolicyInfo.NfsVersion = nfs
}
volume.ExportPolicyInfo.NfsVersion = nfs
}
if d.HasChange("permission") || d.HasChange("users") {
volume.ShareInfoUpdate.ShareName = d.Get("share_name").(string)
Expand All @@ -801,20 +805,28 @@ func resourceCVOVolumeUpdate(d *schema.ResourceData, meta interface{}) error {
volume.TieringPolicy = d.Get("tiering_policy").(string)
}

if d.HasChange("comment") {
volume.Comment = d.Get("comment").(string)
}
log.Printf("###Updating volume: %#v", volume)
err = client.updateVolume(volume, clientID)
if err != nil {
log.Print("Error updating volume")
return err
}

// add sleep to wait for the volume to be updated NOC-37737
time.Sleep(3 * time.Minute)
return resourceCVOVolumeRead(d, meta)
}

func resourceVolumeCustomizeDiff(diff *schema.ResourceDiff, v interface{}) error {
// Check supported modification: Use volume name as an indication to know if this is a creation or modification
if !(diff.HasChange("name")) {
changeableParams := []string{"volume_protocol", "export_policy_type", "export_policy_ip", "export_policy_name", "export_policy_nfs_version",
"share_name", "permission", "users", "tiering_policy", "snapshot_policy_name", "export_policy_rule_access_control", "export_policy_rule_super_user"}
changeableParams := []string{"volume_protocol", "export_policy_type", "export_policy_ip",
"export_policy_name", "export_policy_nfs_version", "share_name", "permission", "users",
"tiering_policy", "snapshot_policy_name", "export_policy_rule_access_control",
"export_policy_rule_super_user", "comment"}
changedKeys := diff.GetChangedKeysPrefix("")
for _, key := range changedKeys {
found := false
Expand Down
7 changes: 6 additions & 1 deletion cloudmanager/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ func (c *Client) updateVolume(request volumeRequest, clientID string) error {
}
baseURL = fmt.Sprintf("%s/volumes/%s/%s/%s", baseURL, id, request.SvmName, request.Name)
params := structs.Map(request)
statusCode, response, _, err := c.CallAPIMethod("PUT", baseURL, params, c.Token, hostType, clientID)
statusCode, response, onCloudRequestID, err := c.CallAPIMethod("PUT", baseURL, params, c.Token, hostType, clientID)

responseError := apiResponseChecker(statusCode, response, "updateVolume")
if responseError != nil {
Expand All @@ -366,6 +366,11 @@ func (c *Client) updateVolume(request volumeRequest, clientID string) error {
log.Print("updateVolume request failed ", statusCode)
return err
}

err = c.waitOnCompletion(onCloudRequestID, "volume", "update", 40, 10, clientID)
if err != nil {
return err
}
return nil
}

Expand Down

0 comments on commit 7503b7b

Please sign in to comment.