Skip to content

Commit

Permalink
Merge pull request #179 from NetApp/integration/main
Browse files Browse the repository at this point in the history
Integration/main
  • Loading branch information
wenjun666 authored Oct 25, 2023
2 parents b1d23ba + e3a5fcf commit f00f813
Show file tree
Hide file tree
Showing 7 changed files with 259 additions and 64 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
## 23.10.0
BUG FIXES:
* resource/aws_fsx: handling for a situation in which the status does not exist yet.
* resource/cifs_server: fix the read function on domain, dns_domain and netbios checking with case insensitive.
* resource/volume: add `export_policy_rule_super_user` and `export_policy_rule_access_control` options. Fix export policy update error.

## 23.8.2
BUG FIXES:
* resource/volume: fix schema structure for export policy response in volume.

ENHANCEMENTS:
* support dev environment.
* resources/cvo: update the documentation on the `ontap_version` naming convention and the way to find the available upgrade versions on `upgrade_ontap_version`.
Expand Down
4 changes: 3 additions & 1 deletion cloudmanager/aws_fsx.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ func (c *Client) checkTaskStatusFSX(id string, tenantID string) (providerDetails
code, result, _, err := c.CallAPIMethod("GET", baseURL, nil, c.Token, hostType, "")
if err != nil {
if networkRetries > 0 {
time.Sleep(1 * time.Second)
time.Sleep(2 * time.Second)
networkRetries--
} else {
log.Print("checkTaskStatusFSX request failed ", code)
Expand Down Expand Up @@ -391,6 +391,8 @@ func (c *Client) checkTaskStatusFSX(id string, tenantID string) (providerDetails
}

func (c *Client) waitOnCompletionFSX(id string, tenantID string, actionName string, task string, retries int, waitInterval int) error {
// below timeout is for handling for a situation in which the status does not exist yet
time.Sleep(5 * time.Second)
for {
fsxStatus, failureErrorMessage, err := c.checkTaskStatusFSX(id, tenantID)
if err != nil {
Expand Down
7 changes: 3 additions & 4 deletions cloudmanager/cifs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ type cifsRequest struct {

type cifsResponse struct {
Domain string `json:"activeDirectoryDomain"`
Username string `json:"activeDirectoryUsername"`
Password string `json:"activeDirectoryPassword"`
DNSDomain string `json:"dnsDomain"`
IPAddresses []string `json:"ipAddresses"`
NetBIOS string `json:"netBIOS"`
OrganizationalUnit string `json:"organizationalUnit"`
AuthenticationType string `json:"authenticationType"`
}

type cifsDeleteRequest struct {
Expand Down Expand Up @@ -72,10 +71,10 @@ func (c *Client) getCIFS(cifs cifsRequest, clientID string) ([]cifsResponse, err
hostType := "CloudManagerHost"
statusCode, response, _, err := c.CallAPIMethod("GET", baseURL, nil, c.Token, hostType, clientID)
if err != nil {
log.Print("createCIFS request failed ", statusCode)
log.Print("getCIFS request failed ", statusCode)
return result, err
}
responseError := apiResponseChecker(statusCode, response, "createCifs")
responseError := apiResponseChecker(statusCode, response, "getCIFS")
if responseError != nil {
return result, responseError
}
Expand Down
7 changes: 4 additions & 3 deletions cloudmanager/resource_netapp_cloudmanager_cifs_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,10 @@ func resourceCVOCIFSRead(d *schema.ResourceData, meta interface{}) error {
return err
}
for _, cifsConfig := range res {
log.Printf("cifs config: %v", cifsConfig)
if cifsConfig.Domain == d.Get("domain").(string) && cifsConfig.DNSDomain == d.Get("dns_domain").(string) &&
cifsConfig.NetBIOS == d.Get("netbios").(string) && cifsConfig.OrganizationalUnit == d.Get("organizational_unit").(string) {
log.Printf("cifs config: %#v", cifsConfig)
// domain, dns_domain, netbios are all converted to low case in the API response
if cifsConfig.Domain == strings.ToLower(d.Get("domain").(string)) && cifsConfig.DNSDomain == strings.ToLower(d.Get("dns_domain").(string)) &&
cifsConfig.NetBIOS == strings.ToLower(d.Get("netbios").(string)) && cifsConfig.OrganizationalUnit == d.Get("organizational_unit").(string) {
d.Set("ip_addresses", cifsConfig.IPAddresses)
return nil
}
Expand Down
194 changes: 166 additions & 28 deletions cloudmanager/resource_netapp_cloudmanager_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func resourceCVOVolume() *schema.Resource {
Optional: true,
},
"export_policy_ip": {
Type: schema.TypeSet,
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
Expand All @@ -93,6 +93,15 @@ func resourceCVOVolume() *schema.Resource {
Type: schema.TypeString,
},
},
"export_policy_rule_access_control": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"readonly", "readwrite", "none"}, false),
},
"export_policy_rule_super_user": {
Type: schema.TypeBool,
Optional: true,
},
"iops": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -297,6 +306,75 @@ func resourceCVOVolumeCreate(d *schema.ResourceData, meta interface{}) error {
}
}
}
// exmaple of the export policy info in volume creation from the UI timeline. Be aware that it might be out of date as time changes.
// Note that for update, export policy info has different structure.
// "exportPolicyInfo": {
// "policyType": "custom",
// "rules": [
// {
// "nfsVersion": [
// "nfs4",
// "nfs3"
// ],
// "superuser": false,
// "ruleAccessControl": "readonly",
// "ips": [
// "0.0.0.0"
// ],
// "index": 1
// }
// ]
// }
if d.HasChange("export_policy_name") || d.HasChange("export_policy_type") || d.HasChange("export_policy_ip") || d.HasChange("export_policy_nfs_version") || d.HasChange("export_policy_rule_access_control") || d.HasChange("export_policy_rule_super_user") {
var exportPolicyTypeOK, exportPolicyIPOK, exportPolicyNfsVersionOK, exportPolicyRuleAccessControlOK, exportPolicyRuleSuperUserOK bool
var nfsVersion, policyIps []string
if v, ok := d.GetOk("export_policy_name"); ok {
volume.ExportPolicyInfo.Name = v.(string)
}
if v, ok := d.GetOk("export_policy_ip"); ok {
ips := make([]string, 0, len(v.([]interface{})))
for _, x := range v.([]interface{}) {
ips = append(ips, x.(string))
}
policyIps = ips
exportPolicyIPOK = true
}
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))
}
nfsVersion = nfs
exportPolicyNfsVersionOK = true
}
if _, ok := d.GetOk("export_policy_rule_access_control"); ok {
exportPolicyRuleAccessControlOK = true
}
if _, ok := d.GetOkExists("export_policy_rule_super_user"); ok {
exportPolicyRuleSuperUserOK = true
}
if v, ok := d.GetOk("export_policy_type"); ok {
volume.ExportPolicyInfo.PolicyType = v.(string)
exportPolicyTypeOK = true
}
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(policyIps))
for i, x := range policyIps {
rules[i] = ExportPolicyRule{}
eachRule := make([]string, 1)
eachRule[0] = x
rules[i].Ips = eachRule
rules[i].NfsVersion = nfsVersion
rules[i].Superuser = d.Get("export_policy_rule_super_user").(bool)
rules[i].RuleAccessControl = d.Get("export_policy_rule_access_control").(string)
rules[i].Index = int32(i + 1)
}
volume.ExportPolicyInfo.Rules = rules
}

response, err := client.quoteVolume(quote, clientID)
if err != nil {
log.Printf("Error quoting volume")
Expand All @@ -313,29 +391,9 @@ func resourceCVOVolumeCreate(d *schema.ResourceData, meta interface{}) error {
volume.Size.Size = d.Get("size").(float64)
volume.Size.Unit = d.Get("unit").(string)
volumeProtocol := d.Get("volume_protocol").(string)
if v, ok := d.GetOk("export_policy_name"); ok {
volume.ExportPolicyInfo.Name = v.(string)
}
if v, ok := d.GetOk("comment"); ok {
volume.Comment = v.(string)
}
if v, ok := d.GetOk("export_policy_type"); ok {
volume.ExportPolicyInfo.PolicyType = v.(string)
}
if v, ok := d.GetOk("export_policy_ip"); ok {
ips := make([]string, 0, v.(*schema.Set).Len())
for _, x := range v.(*schema.Set).List() {
ips = append(ips, x.(string))
}
volume.ExportPolicyInfo.Ips = ips
}
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
}
if v, ok := d.GetOk("iops"); ok {
volume.Iops = v.(int)
}
Expand Down Expand Up @@ -614,14 +672,94 @@ func resourceCVOVolumeUpdate(d *schema.ResourceData, meta interface{}) error {
volume := volumeRequest{}
var svm string
volume.Name = d.Get("name").(string)
volume.ExportPolicyInfo.PolicyType = d.Get("export_policy_type").(string)
if v, ok := d.GetOk("export_policy_ip"); ok {
ips := make([]string, 0, v.(*schema.Set).Len())
for _, x := range v.(*schema.Set).List() {
ips = append(ips, x.(string))
if d.HasChange("export_policy_ip") || d.HasChange("export_policy_nfs_version") || d.HasChange("export_policy_rule_super_user") || d.HasChange("export_policy_rule_access_control") {
var exportPolicyTypeOK, exportPolicyIPOK, exportPolicyNfsVersionOK, exportPolicyRuleAccessControlOK, exportPolicyRuleSuperUserOK bool
if v, ok := d.GetOk("export_policy_name"); ok {
volume.ExportPolicyInfo.Name = v.(string)
}
if v, ok := d.GetOk("export_policy_nfs_version"); ok {
nfsVersions := make([]string, 0, v.(*schema.Set).Len())
for _, x := range v.(*schema.Set).List() {
nfsVersions = append(nfsVersions, x.(string))
}
volume.ExportPolicyInfo.NfsVersion = nfsVersions
exportPolicyNfsVersionOK = true
}
if v, ok := d.GetOk("export_policy_type"); ok {
volume.ExportPolicyInfo.PolicyType = v.(string)
exportPolicyTypeOK = true
}
if v, ok := d.GetOk("export_policy_ip"); ok {
ips := make([]string, 0, len(v.([]interface{})))
for _, x := range v.([]interface{}) {
ips = append(ips, x.(string))
}
volume.ExportPolicyInfo.Ips = ips
exportPolicyIPOK = true
}
if _, ok := d.GetOkExists("export_policy_rule_super_user"); ok {
exportPolicyRuleSuperUserOK = true
}
volume.ExportPolicyInfo.Ips = ips
if _, ok := d.GetOk("export_policy_rule_access_control"); ok {
exportPolicyRuleAccessControlOK = true
}
// example of export poliy info for update.
// "exportPolicyInfo": {
// "ips": [
// "0.0.0.0",
// "0.0.0.1"
// ],
// "nfsVersion": [
// "nfs4",
// "nfs3"
// ],
// "policyType": "custom",
// "rules": [
// {
// "nfsVersion": [
// "nfs4",
// "nfs3"
// ],
// "superuser": false,
// "ruleAccessControl": "readonly",
// "ips": [
// "10.0.0.0"
// ],
// "index": 1
// },
// {
// "nfsVersion": [
// "nfs4",
// "nfs3"
// ],
// "superuser": false,
// "ruleAccessControl": "readonly",
// "ips": [
// "10.0.0.1"
// ],
// "index": 2
// }
// ]
// }
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))
for i, x := range volume.ExportPolicyInfo.Ips {
rules[i] = ExportPolicyRule{}
eachRule := make([]string, 1)
eachRule[0] = x
rules[i].Ips = eachRule
rules[i].NfsVersion = volume.ExportPolicyInfo.NfsVersion
rules[i].Superuser = d.Get("export_policy_rule_super_user").(bool)
rules[i].RuleAccessControl = d.Get("export_policy_rule_access_control").(string)
rules[i].Index = int32(i + 1)
}
volume.ExportPolicyInfo.Rules = rules

}

if v, ok := d.GetOk("svm_name"); ok {
svm = v.(string)
}
Expand Down Expand Up @@ -676,7 +814,7 @@ 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"}
"share_name", "permission", "users", "tiering_policy", "snapshot_policy_name", "export_policy_rule_access_control", "export_policy_rule_super_user"}
changedKeys := diff.GetChangedKeysPrefix("")
for _, key := range changedKeys {
found := false
Expand Down
Loading

0 comments on commit f00f813

Please sign in to comment.