Skip to content

Commit

Permalink
Peer System CRUD Actions (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
doriac11 authored Oct 29, 2024
1 parent 756f3e4 commit 7de45f5
Show file tree
Hide file tree
Showing 3 changed files with 261 additions and 0 deletions.
110 changes: 110 additions & 0 deletions inttests/replication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,116 @@ func TestGetPeerMDMs(t *testing.T) {
}
}

// Get Specific Peer System
func TestGetPeerSystem(t *testing.T) {
srcpeer, err := getPeerMdm()
assert.Nil(t, err)

_, getErr := C.GetPeerMDM(srcpeer.ID)
assert.Nil(t, getErr)
}

// Remove a Peer System
func TestRemovePeerSystem(t *testing.T) {
srcpeer, err := getPeerMdm()
assert.Nil(t, err)

removeErr := C.RemovePeerMdm(srcpeer.ID)
assert.Nil(t, removeErr)
}

func TestAddPeerSystem(t *testing.T) {
if C2 == nil {
t.Skip("no client connection to replication target system")
}
system := getTargetSystem()
peerPayload := &siotypes.AddPeerMdm{
PeerSystemID: system.System.ID,
PeerSystemIps: system.System.MdmManagementIPList,
Port: "7611",
Name: "PeerSystemTestName",
}
// Add a Peer System
_, err := C.AddPeerMdm(peerPayload)
assert.Nil(t, err)
}

// Modify a Peer System name
func TestModifyPeerSystemName(t *testing.T) {
srcpeer, err := getPeerMdm()
assert.Nil(t, err)

// Modify name
modifyErr := C.ModifyPeerMdmName(srcpeer.ID, &siotypes.ModifyPeerMDMNameParam{
NewName: "testName",
})
assert.Nil(t, modifyErr)

// Modify Name back to original
modifyErr = C.ModifyPeerMdmName(srcpeer.ID, &siotypes.ModifyPeerMDMNameParam{
NewName: srcpeer.Name,
})
}

// Modify a Peer System name
func TestModifyPeerSystemPort(t *testing.T) {
srcpeer, err := getPeerMdm()
assert.Nil(t, err)

// Modify port
modifyErr := C.ModifyPeerMdmPort(srcpeer.ID, &siotypes.ModifyPeerMDMPortParam{
NewPort: "7612",
})
assert.Nil(t, modifyErr)

// Modify Name back to original
modifyErr = C.ModifyPeerMdmPort(srcpeer.ID, &siotypes.ModifyPeerMDMPortParam{
NewPort: fmt.Sprint(srcpeer.Port),
})
}

// Modify a Peer System Performance Parameters
func TestModifyPeerSystemPerformanceParameters(t *testing.T) {
srcpeer, err := getPeerMdm()
assert.Nil(t, err)

// Modify port
modifyErr := C.ModifyPeerMdmPerformanceParameters(srcpeer.ID, &siotypes.ModifyPeerMdmPerformanceParametersParam{
NewPreformanceProfile: "Compact",
})
assert.Nil(t, modifyErr)

// Modify Name back to original
modifyErr = C.ModifyPeerMdmPerformanceParameters(srcpeer.ID, &siotypes.ModifyPeerMdmPerformanceParametersParam{
NewPreformanceProfile: srcpeer.PerfProfile,
})
}

// Modify a Peer System Ips
func TestModifyPeerSystemIps(t *testing.T) {
srcpeer, err := getPeerMdm()
assert.Nil(t, err)

var ips []string
for _, ip := range srcpeer.IPList {
ips = append(ips, ip.IP)
}

// Modify ips
modifyErr := C.ModifyPeerMdmIP(srcpeer.ID, ips)
assert.Nil(t, modifyErr)
}

// Make it easier to get a Peer System to run the tests against
func getPeerMdm() (*siotypes.PeerMDM, error) {
srcpeers, err := C.GetPeerMDMs()

if err != nil || len(srcpeers) == 0 {
return nil, fmt.Errorf("no peer systems found")
}
return srcpeers[0], nil
}

// Get the Target System
func getTargetSystem() *goscaleio.System {
system := goscaleio.NewSystem(C2)
Expand Down
115 changes: 115 additions & 0 deletions replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,121 @@ func (c *Client) GetPeerMDMs() ([]*types.PeerMDM, error) {
return peerMdms, err
}

// GetPeerMDM returns a specific peer MDM
func (c *Client) GetPeerMDM(id string) (*types.PeerMDM, error) {
defer TimeSpent("GetPeerMDM", time.Now())

path := "/api/instances/PeerMdm::" + id
var peerMdm *types.PeerMDM

err := c.getJSONWithRetry(http.MethodGet, path, nil, &peerMdm)
return peerMdm, err
}

// ModifyPeerMdmIP updates a Peer MDM Ips
func (c *Client) ModifyPeerMdmIP(id string, ips []string) error {
defer TimeSpent("ModifyPeerMdmIP", time.Now())
// Format into the strucutre that the API expects
var ipMap []map[string]interface{}
for _, ip := range ips {
ipMap = append(ipMap, map[string]interface{}{"hostName": ip})
}
param := types.ModifyPeerMdmIPParam{
NewPeerMDMIps: ipMap,
}
path := "/api/instances/PeerMdm::" + id + "/action/modifyPeerMdmIp"

if err := c.getJSONWithRetry(http.MethodPost, path, param, nil); err != nil {
fmt.Printf("c.getJSONWithRetry(http.MethodPost, path, param, nil) returned %s", err)
return err
}

return nil
}

// ModifyPeerMdmName updates a Peer MDM Name
func (c *Client) ModifyPeerMdmName(id string, name *types.ModifyPeerMDMNameParam) error {
defer TimeSpent("ModifyPeerMdmName", time.Now())

path := "/api/instances/PeerMdm::" + id + "/action/modifyPeerMdmName"

if err := c.getJSONWithRetry(http.MethodPost, path, name, nil); err != nil {
fmt.Printf("c.getJSONWithRetry(http.MethodPost, path, name, nil) returned %s", err)
return err
}

return nil
}

// ModifyPeerMdmPort updates a Peer MDM Port
func (c *Client) ModifyPeerMdmPort(id string, port *types.ModifyPeerMDMPortParam) error {
defer TimeSpent("ModifyPeerMdmPort", time.Now())

path := "/api/instances/PeerMdm::" + id + "/action/modifyPeerMdmPort"

if err := c.getJSONWithRetry(http.MethodPost, path, port, nil); err != nil {
fmt.Printf("c.getJSONWithRetry(http.MethodPost, path, port, nil) returned %s", err)
return err
}

return nil
}

// ModifyPeerMdmPerformanceParameters updates a Peer MDM Performance Parameters
func (c *Client) ModifyPeerMdmPerformanceParameters(id string, param *types.ModifyPeerMdmPerformanceParametersParam) error {
defer TimeSpent("ModifyPeerMdmPerformanceParameters", time.Now())

path := "/api/instances/PeerMdm::" + id + "/action/setPeerMdmPerformanceParameters"

if err := c.getJSONWithRetry(http.MethodPost, path, param, nil); err != nil {
fmt.Printf("c.getJSONWithRetry(http.MethodPost, path, param, nil) returned %s", err)
return err
}

return nil
}

// AddPeerMdm Adds a Peer MDM
func (c *Client) AddPeerMdm(param *types.AddPeerMdm) (*types.PeerMDM, error) {
defer TimeSpent("AddPeerMdm", time.Now())
if param.PeerSystemID == "" || len(param.PeerSystemIps) == 0 {
return nil, errors.New("PeerSystemID and PeerSystemIps are required")
}
path := "/api/types/PeerMdm/instances"
peerMdm := &types.PeerMDM{}
var ipMap []map[string]interface{}
for _, ip := range param.PeerSystemIps {
ipMap = append(ipMap, map[string]interface{}{"hostName": ip})
}
paramCreate := types.AddPeerMdmParam{
PeerSystemID: param.PeerSystemID,
PeerSystemIps: ipMap,
Port: param.Port,
Name: param.Name,
}

if err := c.getJSONWithRetry(http.MethodPost, path, paramCreate, peerMdm); err != nil {
fmt.Printf("c.getJSONWithRetry(http.MethodPost, path, paramCreate, peerMdm) returned %s", err)
return nil, err
}

return peerMdm, nil
}

// RemovePeerMdm removes a Peer MDM
func (c *Client) RemovePeerMdm(id string) error {
defer TimeSpent("RemovePeerMdm", time.Now())

path := "/api/instances/PeerMdm::" + id + "/action/removePeerMdm"
params := types.EmptyPayload{}
if err := c.getJSONWithRetry(http.MethodPost, path, params, nil); err != nil {
fmt.Printf("c.getJSONWithRetry(http.MethodPost, path, params, nil) returned %s", err)
return err
}

return nil
}

// ReplicationConsistencyGroup encpsulates a types.ReplicationConsistencyGroup and a client.
type ReplicationConsistencyGroup struct {
ReplicationConsistencyGroup *types.ReplicationConsistencyGroup
Expand Down
36 changes: 36 additions & 0 deletions types/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,42 @@ type PeerMDM struct {
IPList []*IPListNoRole `json:"ipList"`
}

// ModifyPeerMdmIPParam defines struct for ModifyPeerMdmIPParam
type ModifyPeerMdmIPParam struct {
NewPeerMDMIps []map[string]interface{} `json:"newPeerSystemIps"`
}

// ModifyPeerMDMNameParam defines struct for ModifyPeerMDMNameParam
type ModifyPeerMDMNameParam struct {
NewName string `json:"newName"`
}

// ModifyPeerMDMPortParam defines struct for ModifyPeerMDMPortParam
type ModifyPeerMDMPortParam struct {
NewPort string `json:"newPort"`
}

// ModifyPeerMdmPerformanceParametersParam defines struct for ModifyPeerMdmPerformanceParametersParam
type ModifyPeerMdmPerformanceParametersParam struct {
NewPreformanceProfile string `json:"perfProfile"`
}

// AddPeerMdm defines struct for AddPeerMdm
type AddPeerMdm struct {
PeerSystemID string `json:"peerSystemId"`
PeerSystemIps []string `json:"peerSystemIps"`
Port string `json:"port"`
Name string `json:"name"`
}

// AddPeerMdmParam defines struct for AddPeerMdm
type AddPeerMdmParam struct {
PeerSystemID string `json:"peerSystemId"`
PeerSystemIps []map[string]interface{} `json:"peerSystemIps"`
Port string `json:"port"`
Name string `json:"name"`
}

// ReplicationConsistencyGroup (RCG) has information about a replication session
type ReplicationConsistencyGroup struct {
ID string `json:"id,omitempty"`
Expand Down

0 comments on commit 7de45f5

Please sign in to comment.