Skip to content

Commit

Permalink
Merge pull request #160 from dell/add_collection_replication_rule
Browse files Browse the repository at this point in the history
added function for getting all the replication rules
  • Loading branch information
shenda1 authored Jan 3, 2025
2 parents d52931a + af402d9 commit b55f508
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 5 deletions.
1 change: 1 addition & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ type Client interface {
ModifyReplicationRule(ctx context.Context, modifyParams *ReplicationRuleModify, id string) (EmptyResponse, error)
GetReplicationRule(ctx context.Context, id string) (resp ReplicationRule, err error)
GetReplicationRuleByName(ctx context.Context, name string) (ReplicationRule, error)
GetReplicationRules(ctx context.Context) ([]ReplicationRule, error)
CreateProtectionPolicy(ctx context.Context, createParams *ProtectionPolicyCreate) (CreateResponse, error)
ModifyVolumeGroup(ctx context.Context, modifyParams *VolumeGroupModify, id string) (resp EmptyResponse, err error)
GetProtectionPolicy(ctx context.Context, id string) (ProtectionPolicy, error)
Expand Down
30 changes: 30 additions & 0 deletions mocks/Client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,29 @@ func (c *ClientIMPL) ModifyReplicationRule(ctx context.Context, modifyParams *Re
&resp)
return resp, WrapErr(err)
}

// GetReplicationRules returns a list of replication rules
func (c *ClientIMPL) GetReplicationRules(ctx context.Context) ([]ReplicationRule, error) {
var result []ReplicationRule
err := c.readPaginatedData(func(offset int) (api.RespMeta, error) {
var page []ReplicationRule
policy := ReplicationRule{}
qp := c.APIClient().QueryParamsWithFields(&policy)
qp.Order("name")
qp.Offset(offset).Limit(paginationDefaultPageSize)
meta, err := c.APIClient().Query(
ctx,
RequestConfig{
Method: "GET",
Endpoint: replicationRuleURL,
QueryParams: qp,
},
&page)
err = WrapErr(err)
if err == nil {
result = append(result, page...)
}
return meta, err
})
return result, err
}
13 changes: 13 additions & 0 deletions replication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var (
protectionPolicyID = "15c03067-c4f2-428b-b637-18b0266979f0"
protectionPolicyID2 = "3224ff5a-2e83-4a7f-a0c4-009df20e36db"
replicationRuleID = "6b930711-46bc-4a4b-9d6a-22c77a7838c4"
replicationRuleID2 = "2d0780e3-2ce7-4d8b-b2ec-349c5e9e26a9"
)

func TestClientIMPL_CreateProtectionPolicy(t *testing.T) {
Expand Down Expand Up @@ -244,3 +245,15 @@ func TestClientIMPL_GetProtectionPolicies(t *testing.T) {
assert.Len(t, policies, 2)
assert.Equal(t, protectionPolicyID, policies[0].ID)
}

func TestClientIMPL_GetReplicationRules(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
respData := fmt.Sprintf(`[{"id": "%s"}, {"id": "%s"}]`, replicationRuleID, replicationRuleID2)
httpmock.RegisterResponder("GET", replicationRuleMockURL,
httpmock.NewStringResponder(200, respData))
rules, err := C.GetReplicationRules(context.Background())
assert.Nil(t, err)
assert.Len(t, rules, 2)
assert.Equal(t, replicationRuleID, rules[0].ID)
}
15 changes: 10 additions & 5 deletions replication_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,19 @@ type ReplicationRule struct {
// If RPO is Zero, it indicates the replication_type is 'sync'.
Rpo RPOEnum `json:"rpo"`
// RemoteSystemID - unique identifier of the remote system to which this rule will replicate the associated resources.
RemoteSystemID string `json:"remote_system_id"`
ProtectionPolicies []ProtectionPolicy `json:"policies"`
AlertThreshold int `json:"alert_threshold"`
IsReadOnly bool `json:"is_read_only,omitempty"`
RemoteSystemID string `json:"remote_system_id"`
ProtectionPolicies []ProtectionPolicy `json:"policies"`
AlertThreshold int `json:"alert_threshold"`
IsReadOnly bool `json:"is_read_only,omitempty"`
IsReplica bool `json:"is_replica,omitempty"`
ManagedBy string `json:"managed_by,omitempty"`
ManagedByID string `json:"managed_by_id,omitempty"`
RemoteSystem RemoteSystem `json:"remote_system,omitempty"`
ReplicationSession []ReplicationSession `json:"replication_sessions,omitempty"`
}

func (rule *ReplicationRule) Fields() []string {
return []string{"id", "name", "rpo", "remote_system_id", "alert_threshold", "is_read_only"}
return []string{"id", "name", "rpo", "remote_system_id", "alert_threshold", "is_read_only", "is_replica", "managed_by", "managed_by_id", "policies(id,name)", "remote_system(id,name)", "replication_sessions(id,state)"}
}

// VirtualMachines - Details of virtual machine
Expand Down

0 comments on commit b55f508

Please sign in to comment.