Skip to content

Commit

Permalink
adding replication rule modify function (#156)
Browse files Browse the repository at this point in the history
* adding replication rule modify function

Signed-off-by: shenda1 <[email protected]>

* addressed linting issues

Signed-off-by: shenda1 <[email protected]>

* addressing comments

Signed-off-by: shenda1 <[email protected]>

* adding mock for ModifyReplicationRule

Signed-off-by: shenda1 <[email protected]>

* addressing fmt issues

Signed-off-by: shenda1 <[email protected]>

---------

Signed-off-by: shenda1 <[email protected]>
  • Loading branch information
shenda1 authored Dec 16, 2024
1 parent 23e251f commit e3e9d2a
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 1 deletion.
1 change: 1 addition & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ type Client interface {
ModifyFS(ctx context.Context, modifyParams *FSModify, volID string) (EmptyResponse, error)
CloneFS(ctx context.Context, createParams *FsClone, fsID string) (CreateResponse, error)
CreateReplicationRule(ctx context.Context, createParams *ReplicationRuleCreate) (CreateResponse, error)
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)
CreateProtectionPolicy(ctx context.Context, createParams *ProtectionPolicyCreate) (CreateResponse, error)
Expand Down
28 changes: 28 additions & 0 deletions mocks/Client.go

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

14 changes: 14 additions & 0 deletions replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,17 @@ func (c *ClientIMPL) ExecuteActionOnReplicationSession(ctx context.Context, id s
&res)
return resp, WrapErr(err)
}

// ModifyReplicationRule modifies replication rule
func (c *ClientIMPL) ModifyReplicationRule(ctx context.Context, modifyParams *ReplicationRuleModify, id string) (resp EmptyResponse, err error) {
_, err = c.APIClient().Query(
ctx,
RequestConfig{
Method: "PATCH",
Endpoint: replicationRuleURL,
ID: id,
Body: modifyParams,
},
&resp)
return resp, WrapErr(err)
}
16 changes: 16 additions & 0 deletions replication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,22 @@ func TestClientIMPL_CreateReplicationRuleSync(t *testing.T) {
assert.Equal(t, volID, resp.ID)
}

func TestClientIMPL_ModifyReplicationRule(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
httpmock.RegisterResponder("PATCH", fmt.Sprintf("%s/%s", replicationRuleMockURL, replicationRuleID),
httpmock.NewStringResponder(204, ""))

modifyParams := ReplicationRuleModify{
Name: "rr-test-modified",
Rpo: "One_Day",
}

resp, err := C.ModifyReplicationRule(context.Background(), &modifyParams, replicationRuleID)
assert.Nil(t, err)
assert.Equal(t, EmptyResponse(""), resp)
}

func TestClientIMPL_DeleteProtectionPolicy(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
Expand Down
18 changes: 17 additions & 1 deletion replication_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ type ReplicationRuleCreate struct {
Rpo RPOEnum `json:"rpo"`
// Unique identifier of the remote system to which this rule will replicate the associated resources
RemoteSystemID string `json:"remote_system_id"`
AlertThreshold int `json:"alert_threshold,omitempty"`
IsReadOnly bool `json:"is_read_only,omitempty"`
}

type ReplicationRule struct {
Expand All @@ -80,10 +82,12 @@ type ReplicationRule struct {
// 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"`
}

func (rule *ReplicationRule) Fields() []string {
return []string{"id", "name", "rpo", "remote_system_id"}
return []string{"id", "name", "rpo", "remote_system_id", "alert_threshold", "is_read_only"}
}

// VirtualMachines - Details of virtual machine
Expand Down Expand Up @@ -187,3 +191,15 @@ const (
ReplicationRoleMetroPreferred ReplicationRoleEnum = "Metro_Preferred"
ReplicationRoleMetroNonPreferred ReplicationRoleEnum = "Metro_Non_Preferred"
)

// ReplicationRuleModify modifies replication rule
type ReplicationRuleModify struct {
// Name of the replication rule.
Name string `json:"name,omitempty"`
// Recovery point objective (RPO), which is the acceptable amount of data, measured in units of time, that may be lost in case of a failure.
// If RPO is Zero, it indicates the replication_type is 'sync'.
Rpo RPOEnum `json:"rpo,omitempty"`
// Unique identifier of the remote system to which this rule will replicate the associated resources
RemoteSystemID string `json:"remote_system_id,omitempty"`
AlertThreshold int `json:"alert_threshold,omitempty"`
}

0 comments on commit e3e9d2a

Please sign in to comment.