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

addeed the replication repoorts datasource #226

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
283 changes: 283 additions & 0 deletions docs/data-sources/replication_report.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Copyright (c) 2024 Dell Inc., or its subsidiaries. All Rights Reserved.

Licensed under the Mozilla Public License Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://mozilla.org/MPL/2.0/


Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

# This Terraform DataSource is used to query the details of existing Replication Report from PowerScale array.

# Returns the entire list of PowerScale replication report.
data "powerscale_replication_report" "all" {
}

# Output value of above block by executing 'terraform output' command
# You can use the the fetched information by the variable data.powerscale_replication_report.all
output "powerscale_replication_report_all" {
value = data.powerscale_replication_report.all
}

# Returns a list of PowerScale Replication Report based on the filters specified in the filter block.
data "powerscale_replication_report" "filtering" {
filter {
policy_name = "Policy"
reports_per_policy = 2
sort = "policy_name"
dir = "ASC"
}
}

# Output value of above block by executing 'terraform output' command
# You can use the the fetched information by the variable data.powerscale_replication_report.filtering
output "powerscale_replication_report_filter" {
value = data.powerscale_replication_report.filtering
}
30 changes: 30 additions & 0 deletions examples/data-sources/powerscale_replication_report/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
Copyright (c) 2024 Dell Inc., or its subsidiaries. All Rights Reserved.

Licensed under the Mozilla Public License Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://mozilla.org/MPL/2.0/


Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
terraform {
required_providers {
powerscale = {
source = "registry.terraform.io/dell/powerscale"
}
}
}

provider "powerscale" {
username = var.username
password = var.password
endpoint = var.endpoint
insecure = var.insecure
}
3 changes: 3 additions & 0 deletions powerscale/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,4 +461,7 @@ const (

// ReadSnapshotRestoreJobReportErrorMsg specifies error details occurred while reading snapshot restore job reports.
ReadSnapshotRestoreJobReportErrorMsg = "Could not read snapshot restore job reports "

// ReadReplicationReportsErrorMsg specifies error details occurred while reading replication reports.
ReadReplicationReportsErrorMsg = "Could not read Replication Reports"
)
68 changes: 68 additions & 0 deletions powerscale/helper/replication_reports_helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
Copyright (c) 2024 Dell Inc., or its subsidiaries. All Rights Reserved.

Licensed under the Mozilla Public License Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://mozilla.org/MPL/2.0/


Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package helper

import (
"context"
powerscale "dell/powerscale-go-client"
"terraform-provider-powerscale/client"
"terraform-provider-powerscale/powerscale/models"
)

// GetRoles Get a list of replication reports.
func GetReplicationReports(ctx context.Context, client *client.Client, state models.ReplicationReportsDatasourceModel) (*powerscale.V15SyncReports, error) {
listRRParam := client.PscaleOpenAPIClient.SyncApi.GetSyncv15SyncReports(ctx)
if state.ReplicationReportFilter != nil {
if !state.ReplicationReportFilter.Sort.IsNull() {
listRRParam = listRRParam.Sort(state.ReplicationReportFilter.Sort.ValueString())
}
if !state.ReplicationReportFilter.Resume.IsNull() {
listRRParam = listRRParam.Resume(state.ReplicationReportFilter.Resume.ValueString())
}
if !state.ReplicationReportFilter.NewerThan.IsNull() {
listRRParam = listRRParam.NewerThan(int32(state.ReplicationReportFilter.NewerThan.ValueInt64()))
}
if !state.ReplicationReportFilter.PolicyName.IsNull() {
listRRParam = listRRParam.PolicyName(state.ReplicationReportFilter.PolicyName.ValueString())
}
if !state.ReplicationReportFilter.State.IsNull() {
listRRParam = listRRParam.State(state.ReplicationReportFilter.State.ValueString())
}
if !state.ReplicationReportFilter.Limit.IsNull() {
listRRParam = listRRParam.Limit(int32(state.ReplicationReportFilter.Limit.ValueInt64()))
}
if !state.ReplicationReportFilter.ReportsPerPolicy.IsNull() {
listRRParam = listRRParam.ReportsPerPolicy(int32(state.ReplicationReportFilter.ReportsPerPolicy.ValueInt64()))
}
if !state.ReplicationReportFilter.Dir.IsNull() {
listRRParam = listRRParam.Dir(state.ReplicationReportFilter.Dir.ValueString())
}
if !state.ReplicationReportFilter.Summary.IsNull() {
listRRParam = listRRParam.Summary(state.ReplicationReportFilter.Summary.ValueBool())
}

}
resp, _, err := listRRParam.Execute()
return resp, err
}

func ReplicationReportDetailMapper(ctx context.Context, rr *powerscale.V15SyncReport) (models.ReplicationReportsDetail, error) {
model := models.ReplicationReportsDetail{}
err := CopyFields(ctx, rr, &model)
return model, err
}
193 changes: 193 additions & 0 deletions powerscale/models/replication_reports.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
/*
Copyright (c) 2024 Dell Inc., or its subsidiaries. All Rights Reserved.

Licensed under the Mozilla Public License Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://mozilla.org/MPL/2.0/

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package models

import "github.com/hashicorp/terraform-plugin-framework/types"

type ReplicationReportsDatasourceModel struct {
ID types.String `tfsdk:"id"`
Reports []ReplicationReportsDetail `tfsdk:"replication_reports"`
ReplicationReportFilter *ReplicationReportFilterType `tfsdk:"filter"`
}

type ReplicationReportFilterType struct {
Sort types.String `tfsdk:"sort"`
Resume types.String `tfsdk:"resume"`
NewerThan types.Int64 `tfsdk:"newer_than"`
PolicyName types.String `tfsdk:"policy_name"`
State types.String `tfsdk:"state"`
Limit types.Int64 `tfsdk:"limit"`
ReportsPerPolicy types.Int64 `tfsdk:"reports_per_policy"`
Summary types.Bool `tfsdk:"summary"`
Dir types.String `tfsdk:"dir"`
}

type ReplicationReportsDetail struct {
Action types.String `tfsdk:"action"`
AdsStreamsReplicated types.Int64 `tfsdk:"ads_streams_replicated"`
BlockSpecsReplicated types.Int64 `tfsdk:"block_specs_replicated"`
BytesRecoverable types.Int64 `tfsdk:"bytes_recoverable"`
BytesTransferred types.Int64 `tfsdk:"bytes_transferred"`
CharSpecsReplicated types.Int64 `tfsdk:"char_specs_replicated"`
CommittedFiles types.Int64 `tfsdk:"committed_files"`
CorrectedLins types.Int64 `tfsdk:"corrected_lins"`
DeadNode types.Bool `tfsdk:"dead_node"`
DirectoriesReplicated types.Int64 `tfsdk:"directories_replicated"`
DirsChanged types.Int64 `tfsdk:"dirs_changed"`
DirsDeleted types.Int64 `tfsdk:"dirs_deleted"`
DirsMoved types.Int64 `tfsdk:"dirs_moved"`
DirsNew types.Int64 `tfsdk:"dirs_new"`
Duration types.Int64 `tfsdk:"duration"`
Encrypted types.Bool `tfsdk:"encrypted"`
EndTime types.Int64 `tfsdk:"end_time"`
Error types.String `tfsdk:"error"`
ErrorChecksumFilesSkipped types.Int64 `tfsdk:"error_checksum_files_skipped"`
ErrorIoFilesSkipped types.Int64 `tfsdk:"error_io_files_skipped"`
ErrorNetFilesSkipped types.Int64 `tfsdk:"error_net_files_skipped"`
Errors types.List `tfsdk:"errors"`
FailedChunks types.Int64 `tfsdk:"failed_chunks"`
FifosReplicated types.Int64 `tfsdk:"fifos_replicated"`
FileDataBytes types.Int64 `tfsdk:"file_data_bytes"`
FilesChanged types.Int64 `tfsdk:"files_changed"`
FilesLinked types.Int64 `tfsdk:"files_linked"`
FilesNew types.Int64 `tfsdk:"files_new"`
FilesSelected types.Int64 `tfsdk:"files_selected"`
FilesTransferred types.Int64 `tfsdk:"files_transferred"`
FilesUnlinked types.Int64 `tfsdk:"files_unlinked"`
FilesWithAdsReplicated types.Int64 `tfsdk:"files_with_ads_replicated"`
FlippedLins types.Int64 `tfsdk:"flipped_lins"`
HardLinksReplicated types.Int64 `tfsdk:"hard_links_replicated"`
HashExceptionsFixed types.Int64 `tfsdk:"hash_exceptions_fixed"`
HashExceptionsFound types.Int64 `tfsdk:"hash_exceptions_found"`
ID types.String `tfsdk:"id"`
JobID types.Int64 `tfsdk:"job_id"`
LinsTotal types.Int64 `tfsdk:"lins_total"`
NetworkBytesToSource types.Int64 `tfsdk:"network_bytes_to_source"`
NetworkBytesToTarget types.Int64 `tfsdk:"network_bytes_to_target"`
NewFilesReplicated types.Int64 `tfsdk:"new_files_replicated"`
NumRetransmittedFiles types.Int64 `tfsdk:"num_retransmitted_files"`
Phases []PhasesDetail `tfsdk:"phases"`
Policy PolicyDetail `tfsdk:"policy"`
PolicyAction types.String `tfsdk:"policy_action"`
PolicyID types.String `tfsdk:"policy_id"`
PolicyName types.String `tfsdk:"policy_name"`
QuotasDeleted types.Int64 `tfsdk:"quotas_deleted"`
RegularFilesReplicated types.Int64 `tfsdk:"regular_files_replicated"`
ResyncedLins types.Int64 `tfsdk:"resynced_lins"`
RetransmittedFiles types.List `tfsdk:"retransmitted_files"`
Retry types.Int64 `tfsdk:"retry"`
RunningChunks types.Int64 `tfsdk:"running_chunks"`
SocketsReplicated types.Int64 `tfsdk:"sockets_replicated"`
SourceBytesRecovered types.Int64 `tfsdk:"source_bytes_recovered"`
SourceDirectoriesCreated types.Int64 `tfsdk:"source_directories_created"`
SourceDirectoriesDeleted types.Int64 `tfsdk:"source_directories_deleted"`
SourceDirectoriesLinked types.Int64 `tfsdk:"source_directories_linked"`
SourceDirectoriesUnlinked types.Int64 `tfsdk:"source_directories_unlinked"`
SourceDirectoriesVisited types.Int64 `tfsdk:"source_directories_visited"`
SourceFilesDeleted types.Int64 `tfsdk:"source_files_deleted"`
SourceFilesLinked types.Int64 `tfsdk:"source_files_linked"`
SourceFilesUnlinked types.Int64 `tfsdk:"source_files_unlinked"`
SparseDataBytes types.Int64 `tfsdk:"sparse_data_bytes"`
StartTime types.Int64 `tfsdk:"start_time"`
State types.String `tfsdk:"state"`
SubreportCount types.Int64 `tfsdk:"subreport_count"`
SucceededChunks types.Int64 `tfsdk:"succeeded_chunks"`
SymlinksReplicated types.Int64 `tfsdk:"symlinks_replicated"`
SyncType types.String `tfsdk:"sync_type"`
TargetBytesRecovered types.Int64 `tfsdk:"target_bytes_recovered"`
TargetDirectoriesCreated types.Int64 `tfsdk:"target_directories_created"`
TargetDirectoriesDeleted types.Int64 `tfsdk:"target_directories_deleted"`
TargetDirectoriesLinked types.Int64 `tfsdk:"target_directories_linked"`
TargetDirectoriesUnlinked types.Int64 `tfsdk:"target_directories_unlinked"`
TargetFilesDeleted types.Int64 `tfsdk:"target_files_deleted"`
TargetFilesLinked types.Int64 `tfsdk:"target_files_linked"`
TargetFilesUnlinked types.Int64 `tfsdk:"target_files_unlinked"`
TargetSnapshots types.List `tfsdk:"target_snapshots"`
Throughput types.String `tfsdk:"throughput"`
TotalChunks types.Int64 `tfsdk:"total_chunks"`
TotalDataBytes types.Int64 `tfsdk:"total_data_bytes"`
TotalFiles types.Int64 `tfsdk:"total_files"`
TotalNetworkBytes types.Int64 `tfsdk:"total_network_bytes"`
TotalPhases types.Int64 `tfsdk:"total_phases"`
UnchangedDataBytes types.Int64 `tfsdk:"unchanged_data_bytes"`
UpToDateFilesSkipped types.Int64 `tfsdk:"up_to_date_files_skipped"`
UpdatedFilesReplicated types.Int64 `tfsdk:"updated_files_replicated"`
UserConflictFilesSkipped types.Int64 `tfsdk:"user_conflict_files_skipped"`
Warnings types.List `tfsdk:"warnings"`
WormCommittedFileConflicts types.Int64 `tfsdk:"worm_committed_file_conflicts"`
}

type PolicyDetail struct {
Action types.String `tfsdk:"action"`
FileMatchingPattern FileMatchingPatternDetail `tfsdk:"file_matching_pattern"`
Name types.String `tfsdk:"name"`
SourceExcludeDirectories []types.String `tfsdk:"source_exclude_directories"`
SourceIncludeDirectories []types.String `tfsdk:"source_include_directories"`
SourceRootPath types.String `tfsdk:"source_root_path"`
TargetHost types.String `tfsdk:"target_host"`
TargetPath types.String `tfsdk:"target_path"`
}

type OrCriteriaDetail struct {
AndCriteria []AndCriteriaDetail `tfsdk:"and_criteria"`
}

type AndCriteriaDetail struct {
AttributeExists types.Bool `tfsdk:"attribute_exists"`
CaseSensitive types.Bool `tfsdk:"case_sensitive"`
Field types.String `tfsdk:"field"`
Operator types.String `tfsdk:"operator"`
Type types.String `tfsdk:"type"`
Value types.String `tfsdk:"value"`
WholeWord types.Bool `tfsdk:"whole_word"`
}

type StatisticsDetail struct {
ComplianceDirLinks types.String `tfsdk:"compliance_dir_links"`
CorrectedLins types.String `tfsdk:"corrected_lins"`
DeletedDirs types.String `tfsdk:"deleted_dirs"`
DeletedFiles types.String `tfsdk:"deleted_files"`
Dirs types.String `tfsdk:"dirs"`
Files types.String `tfsdk:"files"`
FlippedLins types.String `tfsdk:"flipped_lins"`
HashExceptions types.String `tfsdk:"hash_exceptions"`
LinkedDirs types.String `tfsdk:"linked_dirs"`
LinkedFiles types.String `tfsdk:"linked_files"`
MarkedDirectories types.String `tfsdk:"marked_directories"`
MarkedFiles types.String `tfsdk:"marked_files"`
ModifiedDirs types.String `tfsdk:"modified_dirs"`
ModifiedFiles types.String `tfsdk:"modified_files"`
ModifiedLins types.String `tfsdk:"modified_lins"`
NewComplianceDirs types.String `tfsdk:"new_compliance_dirs"`
NewDirs types.String `tfsdk:"new_dirs"`
NewFiles types.String `tfsdk:"new_files"`
NewResyncedFiles types.String `tfsdk:"new_resynced_files"`
ResyncedFileLinks types.String `tfsdk:"resynced_file_links"`
ResyncedLins types.String `tfsdk:"resynced_lins"`
UnlinkedFiles types.String `tfsdk:"unlinked_files"`
}

type PhasesDetail struct {
EndTime types.Int64 `tfsdk:"end_time"`
Phase types.String `tfsdk:"phase"`
StartTime types.Int64 `tfsdk:"start_time"`
Statistics StatisticsDetail `tfsdk:"statistics"`
}

type FileMatchingPatternDetail struct {
OrCriteria []OrCriteriaDetail `tfsdk:"or_criteria"`
}
1 change: 1 addition & 0 deletions powerscale/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ func (p *PscaleProvider) DataSources(ctx context.Context) []func() datasource.Da
NewSyncIQRuleDataSource,
NewSyncIQGlobalSettingsDataSource,
NewSyncIQPeerCertificateDataSource,
NewReplicationReportDataSource,
}
}

Expand Down
Loading
Loading