Skip to content

Commit

Permalink
Sync bitbucket and GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
carchi8py committed Aug 3, 2023
1 parent 3623d73 commit 6a2dba1
Show file tree
Hide file tree
Showing 6 changed files with 863 additions and 87 deletions.
46 changes: 43 additions & 3 deletions examples/resources/netapp-ontap_snapmiror_policy/resource.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,49 @@
resource "netapp-ontap_snapmirror_policy_resource" "snapmirror_policy" {
# required to know which system to interface with
cx_profile_name = "cluster4"
name = "carchitestme"
name = "testsp_basic"
svm_name = "ansibleSVM"
}

resource "netapp-ontap_snapmirror_policy_resource" "snapmirror_policy_async" {
# required to know which system to interface with
cx_profile_name = "cluster4"
name = "testsp_async_retention"
svm_name = "ansibleSVM"
identity_preservation = "full"
comment = "comment1"
type = "async"
retention = [{
label = "weekly"
count = 2
},
{
label = "daily",
count = 7
},
{
label = "newlabel1",
count = 3
}
]
}

resource "netapp-ontap_snapmirror_policy_resource" "snapmirror_policy_sync" {
# required to know which system to interface with
cx_profile_name = "cluster4"
name = "testsp_sync"
svm_name = "ansibleSVM"
type = "sync"
sync_type = "sync"
}

resource "netapp-ontap_snapmirror_policy_resource" "snapmirror_policy_sync_1" {
# required to know which system to interface with
cx_profile_name = "cluster4"
name = "testsp_sync"
svm_name = "ansibleSVM"
type = "sync"
sync_type = "sync"
retention = [{
count = 1
label = "hourly"
}]
}
8 changes: 4 additions & 4 deletions internal/interfaces/protocols_nfs_export_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ func GetExportPolicy(errorHandler *utils.ErrorHandler, r restclient.RestClient,
return nil, errorHandler.MakeAndReportError("error reading export policy info", fmt.Sprintf("error on GET protocols/nfs/export-policies/%s: %s", id, err))
}

var dataONTAP *ExportPolicyGetDataModelONTAP
var dataONTAP ExportPolicyGetDataModelONTAP
if err := mapstructure.Decode(response, &dataONTAP); err != nil {
return nil, errorHandler.MakeAndReportError("error decoding export policy info", fmt.Sprintf("error on decode protocols/nfs/export-policies/%s: %s, statusCode %d, response %#v", id, err, statusCode, response))
}
tflog.Debug(errorHandler.Ctx, fmt.Sprintf("Read export policy source - udata: %#v", dataONTAP))
return dataONTAP, nil
return &dataONTAP, nil
}

// GetExportPolicies to get export policy by name
Expand All @@ -79,12 +79,12 @@ func GetExportPolicies(errorHandler *utils.ErrorHandler, r restclient.RestClient
return nil, errorHandler.MakeAndReportError("error reading export policy info", fmt.Sprintf("error on GET protocols/nfs/export-policies: %s", err))
}

var dataONTAP *ExportPolicyGetDataModelONTAP
var dataONTAP ExportPolicyGetDataModelONTAP
if err := mapstructure.Decode(response, &dataONTAP); err != nil {
return nil, errorHandler.MakeAndReportError("error decoding export policy info", fmt.Sprintf("error on decode protocols/nfs/export-policies: %s, statusCode %d, response %#v", err, statusCode, response))
}
tflog.Debug(errorHandler.Ctx, fmt.Sprintf("Read export policy source - udata: %#v", dataONTAP))
return dataONTAP, nil
return &dataONTAP, nil
}

// DeleteExportPolicy to delete export policy
Expand Down
147 changes: 120 additions & 27 deletions internal/interfaces/snapmirror_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,45 +12,120 @@ import (
// SnapmirrorPolicyGetDataModelONTAP defines the resource get data model
type SnapmirrorPolicyGetDataModelONTAP struct {
Name string `mapstructure:"name"`
SVMName Vserver `mapstructure:"svm"`
Type string `mapstructure:"type"`
SVM Vserver `mapstructure:"svm"`
Type string `mapstructure:"type,omitempty"`
SyncType string `mapstructure:"sync_type,omitempty"`
Comment string `mapstructure:"comment"`
TransferSchedule string `mapstructure:"transfer_schedule"`
TransferSchedule TransferScheduleType `mapstructure:"transfer_schedule"`
NetworkCompressionEnabled bool `mapstructure:"network_compression_enabled"`
Retention []RetentionGetDataModel `mapstructure:"retention"`
IdentityPreservation string `mapstructure:"identity_preservation"`
CopyAllSourceSnapshots bool `mapstructure:"copy_all_source_snapshots"`
Retention []RetentionGetDataModel `mapstructure:"retention,omitempty"`
IdentityPreservation string `mapstructure:"identity_preservation,omitempty"`
CopyAllSourceSnapshots bool `mapstructure:"copy_all_source_snapshots,omitempty"`
CopyLatestSourceSnapshot bool `mapstructure:"copy_latest_source_snapshot,omitempty"`
UUID string `mapstructure:"uuid"`
}

// SnapmirrorPolicyGetRawDataModelONTAP defines the resource get data model
type SnapmirrorPolicyGetRawDataModelONTAP struct {
Name string `mapstructure:"name"`
SVM Vserver `mapstructure:"svm"`
Type string `mapstructure:"type,omitempty"`
SyncType string `mapstructure:"sync_type,omitempty"`
Comment string `mapstructure:"comment"`
TransferSchedule TransferScheduleType `mapstructure:"transfer_schedule"`
NetworkCompressionEnabled bool `mapstructure:"network_compression_enabled"`
Retention []RetentionGetRawDataModel `mapstructure:"retention"`
IdentityPreservation string `mapstructure:"identity_preservation,omitempty"`
CopyAllSourceSnapshots bool `mapstructure:"copy_all_source_snapshots,omitempty"`
CopyLatestSourceSnapshot bool `mapstructure:"copy_latest_source_snapshot,omitempty"`
CreateSnapshotOnSource bool `mapstructure:"create_snapshot_on_source,omitempty"`
UUID string `mapstructure:"uuid"`
}

// RetentionGetRawDataModel defines the resource get retention model
type RetentionGetRawDataModel struct {
CreationSchedule CreationScheduleModel `mapstructure:"creation_schedule,omitempty"`
Count string `mapstructure:"count"`
Label string `mapstructure:"label"`
Prefix string `mapstructure:"prefix,omitempty"`
}

// RetentionGetDataModel defines the resource get retention model
type RetentionGetDataModel struct {
CreationSchedule CreationScheduleModel `json:"creation_schedule"`
Count int64 `json:"count"`
Label string `json:"label"`
Prefix string `json:"prefix"`
CreationSchedule CreationScheduleModel `mapstructure:"creation_schedule,omitempty"`
Count int64 `mapstructure:"count"`
Label string `mapstructure:"label"`
Prefix string `mapstructure:"prefix,omitempty"`
}

// CreationScheduleModel defines the resource creationschedule model
type CreationScheduleModel struct {
Name string `json:"name"`
Name string `mapstructure:"name"`
}

// SnapmirrorPolicyResourceBodyDataModelONTAP defines the resource data model
type SnapmirrorPolicyResourceBodyDataModelONTAP struct {
Name string `mapstructure:"name"`
SVMName Vserver `mapstructure:"svm"`
Type string `mapstructure:"type,omitempty"`
Comment string `mapstructure:"comment,omitempty"`
TransferSchedule string `mapstructure:"transfer_schedule,omitempty"`
NetworkCompressionEnabled bool `mapstructure:"network_compression_enabled,omitempty"`
Retention []RetentionGetDataModel `mapstructure:"retention,omitempty"`
IdentityPreservation string `mapstructure:"identity_preservation,omitempty"`
CopyAllSourceSnapshots bool `mapstructure:"copy_all_source_snapshots,omitempty"`
Name string `mapstructure:"name"`
SVM Vserver `mapstructure:"svm"`
Type string `mapstructure:"type,omitempty"`
SyncType string `mapstructure:"sync_type,omitempty"`
Comment string `mapstructure:"comment"`
TransferSchedule TransferScheduleType `mapstructure:"transfer_schedule,omitempty"`
NetworkCompressionEnabled bool `mapstructure:"network_compression_enabled,omitempty"`
Retention []map[string]interface{} `mapstructure:"retention,omitempty"`
IdentityPreservation string `mapstructure:"identity_preservation,omitempty"`
CopyAllSourceSnapshots bool `mapstructure:"copy_all_source_snapshots,omitempty"`
CopyLatestSourceSnapshot bool `mapstructure:"copy_latest_source_snapshot,omitempty"`
CreateSnapshotOnSource bool `mapstructure:"create_snapshot_on_source,omitempty"`
}

// TransferScheduleType describes the transfer_schedule
type TransferScheduleType struct {
Name string `mapstructure:"name,omitempty"`
}

// UpdateSnapmirrorPolicyResourceBodyDataModelONTAP defines the resource update request body
type UpdateSnapmirrorPolicyResourceBodyDataModelONTAP struct {
Comment string `mapstructure:"comment"`
TransferSchedule map[string]interface{} `mapstructure:"transfer_schedule"`
NetworkCompressionEnabled bool `mapstructure:"network_compression_enabled"`
Retention []map[string]interface{} `mapstructure:"retention,omitempty"`
IdentityPreservation string `mapstructure:"identity_preservation,omitempty"`
}

// UpdateSyncSnapmirrorPolicyResourceBodyDataModelONTAP defins the sync type snapmirror policy update request body
type UpdateSyncSnapmirrorPolicyResourceBodyDataModelONTAP struct {
Comment string `mapstructure:"comment"`
NetworkCompressionEnabled bool `mapstructure:"network_compression_enabled"`
Retention []map[string]interface{} `mapstructure:"retention,omitempty"`
}

// UpdateTransferScheduleType describes the transfer_schedule data type in update request
type UpdateTransferScheduleType struct {
Name string `mapstructure:"name"`
UUID string `mapstructure:"uuid,omitempty"`
}

// GetSnapmirrorPolicy to get snapmirror policy info
func GetSnapmirrorPolicy(errorHandler *utils.ErrorHandler, r restclient.RestClient, name string, svmName string) (*SnapmirrorPolicyGetDataModelONTAP, error) {
// GetSnapmirrorPolicy by ID
func GetSnapmirrorPolicy(errorHandler *utils.ErrorHandler, r restclient.RestClient, id string) (*SnapmirrorPolicyGetRawDataModelONTAP, error) {
api := "snapmirror/policies/" + id
statusCode, response, err := r.GetNilOrOneRecord(api, nil, nil)
if err == nil && response == nil {
err = fmt.Errorf("no response for GET %s", api)
}
if err != nil {
return nil, errorHandler.MakeAndReportError("error reading snapmirror policy info", fmt.Sprintf("error on GET %s: %s", api, err))
}
var rawDataONTAP SnapmirrorPolicyGetRawDataModelONTAP
if err := mapstructure.Decode(response, &rawDataONTAP); err != nil {
return nil, errorHandler.MakeAndReportError("error decoding snapmirror policy info", fmt.Sprintf("error on decode %s: %s, statusCode %d, response %#v", api, err, statusCode, response))
}
tflog.Debug(errorHandler.Ctx, fmt.Sprintf("\n777Read snapmirror policy source - udata: %#v", rawDataONTAP))
return &rawDataONTAP, nil
}

// GetSnapmirrorPolicyByName to get snapmirror policy info
func GetSnapmirrorPolicyByName(errorHandler *utils.ErrorHandler, r restclient.RestClient, name string, svmName string) (*SnapmirrorPolicyGetDataModelONTAP, error) {
api := "snapmirror/policies"
query := r.NewQuery()
query.Set("name", name)
Expand Down Expand Up @@ -81,7 +156,7 @@ func GetSnapmirrorPolicy(errorHandler *utils.ErrorHandler, r restclient.RestClie
}

// CreateSnapmirrorPolicy to create snapmirror policy
func CreateSnapmirrorPolicy(errorHandler *utils.ErrorHandler, r restclient.RestClient, body SnapmirrorPolicyResourceBodyDataModelONTAP) (*SnapmirrorPolicyGetDataModelONTAP, error) {
func CreateSnapmirrorPolicy(errorHandler *utils.ErrorHandler, r restclient.RestClient, body SnapmirrorPolicyResourceBodyDataModelONTAP) (*SnapmirrorPolicyGetRawDataModelONTAP, error) {
api := "snapmirror/policies"
var bodyMap map[string]interface{}
if err := mapstructure.Decode(body, &bodyMap); err != nil {
Expand All @@ -94,12 +169,30 @@ func CreateSnapmirrorPolicy(errorHandler *utils.ErrorHandler, r restclient.RestC
return nil, errorHandler.MakeAndReportError("error creating snapmirror/policies", fmt.Sprintf("error on POST %s: %s, statusCode %d", api, err, statusCode))
}

var dataONTAP SnapmirrorPolicyGetDataModelONTAP
if err := mapstructure.Decode(response.Records[0], &dataONTAP); err != nil {
var rawDataONTAP SnapmirrorPolicyGetRawDataModelONTAP
if err := mapstructure.Decode(response.Records[0], &rawDataONTAP); err != nil {
return nil, errorHandler.MakeAndReportError("error decoding snapmirror/policies info", fmt.Sprintf("error on decode snapmirror/policies info: %s, statusCode %d, response %#v", err, statusCode, response))
}
tflog.Debug(errorHandler.Ctx, fmt.Sprintf("Create snapmirror/policies source - udata: %#v", dataONTAP))
return &dataONTAP, nil

tflog.Debug(errorHandler.Ctx, fmt.Sprintf("Create snapmirror/policies source - udata: %#v", rawDataONTAP))
return &rawDataONTAP, nil
}

// UpdateSnapmirrorPolicy to update snapmirror policy
func UpdateSnapmirrorPolicy(errorHandler *utils.ErrorHandler, r restclient.RestClient, data any, id string) error {
api := "snapmirror/policies/" + id
var body map[string]interface{}
if err := mapstructure.Decode(data, &body); err != nil {
return errorHandler.MakeAndReportError("error encoding update snapmirror/policies body", fmt.Sprintf("error on encoding %s body: %s, body: %#v", api, err, body))
}
query := r.NewQuery()
query.Add("return_records", "true")
statusCode, response, err := r.CallUpdateMethod(api, query, body)
if err != nil {
return errorHandler.MakeAndReportError("error updating export policy", fmt.Sprintf("error on PATCH %s: %s, statusCode %d, response %#v", api, err, statusCode, response))
}

return nil
}

// DeleteSnapmirrorPolicy to delete ip_interface
Expand Down
4 changes: 2 additions & 2 deletions internal/interfaces/storage_aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ func GetStorageAggregate(errorHandler *utils.ErrorHandler, r restclient.RestClie
return nil, errorHandler.MakeAndReportError("error reading storage aggregate info", fmt.Sprintf("error on GET storage/aggregates/%s: %s", uuid, err))
}

var dataONTAP *StorageAggregateGetDataModelONTAP
var dataONTAP StorageAggregateGetDataModelONTAP
if err := mapstructure.Decode(response, &dataONTAP); err != nil {
return nil, errorHandler.MakeAndReportError("error decoding storage aggregate info", fmt.Sprintf("error on decode storage/aggregates: %s, statusCode %d, response %#v", err, statusCode, response))
}
tflog.Debug(errorHandler.Ctx, fmt.Sprintf("Read aggregate source - udata: %#v", dataONTAP))
return dataONTAP, nil
return &dataONTAP, nil
}

// GetStorageAggregateByName to get aggregate info by name
Expand Down
Loading

0 comments on commit 6a2dba1

Please sign in to comment.