From 7de45f5ef2b2aaeb305ea192ef7902f27be9ca34 Mon Sep 17 00:00:00 2001 From: Connor Doria <128822122+doriac11@users.noreply.github.com> Date: Tue, 29 Oct 2024 03:37:49 -0400 Subject: [PATCH] Peer System CRUD Actions (#141) --- inttests/replication_test.go | 110 +++++++++++++++++++++++++++++++++ replication.go | 115 +++++++++++++++++++++++++++++++++++ types/v1/types.go | 36 +++++++++++ 3 files changed, 261 insertions(+) diff --git a/inttests/replication_test.go b/inttests/replication_test.go index a16fd1a..64c28c9 100644 --- a/inttests/replication_test.go +++ b/inttests/replication_test.go @@ -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) diff --git a/replication.go b/replication.go index 699edde..69a996c 100644 --- a/replication.go +++ b/replication.go @@ -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 diff --git a/types/v1/types.go b/types/v1/types.go index 9ef1e4b..54b6bad 100644 --- a/types/v1/types.go +++ b/types/v1/types.go @@ -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"`