diff --git a/client.go b/client.go index 66253f4..2784cdf 100644 --- a/client.go +++ b/client.go @@ -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) diff --git a/mocks/Client.go b/mocks/Client.go index d138f0d..affb0a9 100644 --- a/mocks/Client.go +++ b/mocks/Client.go @@ -4364,6 +4364,34 @@ func (_m *Client) WearMetricsByDrive(ctx context.Context, entityID string, inter return r0, r1 } +// ModifyReplicationRule provides a mock function with given fields: ctx, modifyParams, id +func (_m *Client) ModifyReplicationRule(ctx context.Context, modifyParams *gopowerstore.ReplicationRuleModify, id string) (gopowerstore.EmptyResponse, error) { + ret := _m.Called(ctx, modifyParams, id) + + if len(ret) == 0 { + panic("no return value specified for ModifyReplicationRule") + } + + var r0 gopowerstore.EmptyResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *gopowerstore.ReplicationRuleModify, string) (gopowerstore.EmptyResponse, error)); ok { + return rf(ctx, modifyParams, id) + } + if rf, ok := ret.Get(0).(func(context.Context, *gopowerstore.ReplicationRuleModify, string) gopowerstore.EmptyResponse); ok { + r0 = rf(ctx, modifyParams, id) + } else { + r0 = ret.Get(0).(gopowerstore.EmptyResponse) + } + + if rf, ok := ret.Get(1).(func(context.Context, *gopowerstore.ReplicationRuleModify, string) error); ok { + r1 = rf(ctx, modifyParams, id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // NewClient creates a new instance of Client. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. // The first argument is typically a *testing.T value. func NewClient(t interface { diff --git a/replication.go b/replication.go index 4f3e837..8243c18 100644 --- a/replication.go +++ b/replication.go @@ -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) +} diff --git a/replication_test.go b/replication_test.go index 5db8579..2104980 100644 --- a/replication_test.go +++ b/replication_test.go @@ -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() diff --git a/replication_types.go b/replication_types.go index 43a98e7..5056cd2 100644 --- a/replication_types.go +++ b/replication_types.go @@ -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 { @@ -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 @@ -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"` +}