8000 feat: NE-add secondary device to primary device and delete secondary device from HA Pair by kpdhulipala · Pull Request #37 · equinix/ne-go · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: NE-add secondary device to primary device and delete secondary device from HA Pair #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions client.go
10000
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,14 @@ type Client interface {

CreateDevice(device Device) (*string, error)
CreateRedundantDevice(primary Device, secondary Device) (*string, *string, error)
AddSecondary(primaryUuid string, secondary Device) (*string, error)
GetDevice(uuid string) (*Device, error)
GetDevices(statuses []string) ([]Device, error)
GetDeviceAdditionalBandwidthDetails(uuid string) (*DeviceAdditionalBandwidthDetails, error)
GetDeviceACLDetails(uuid string) (*DeviceACLDetails, error)
NewDeviceUpdateRequest(uuid string) DeviceUpdateRequest
DeleteDevice(uuid string) error
DeleteSecondaryDevice(uuid string) error

CreateSSHUser(username string, password string, device string) (*string, error)
GetSSHUsers() ([]SSHUser, error)
Expand Down
6 changes: 6 additions & 0 deletions internal/api/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ type DeviceUpdateRequest struct {
ClusterName *string `json:"clusterName,omitempty"`
}

// AddSecondaryRequest Add Secondary Request
type AddSecondaryRequest struct {
PrimaryDeviceUUID *string `json:"primaryDeviceUuid,omitempty"`
Secondary *SecondaryDeviceRequest `json:"secondary,omitempty"`
}

// DeviceAdditionalBandwidthUpdateRequest describes network device additional bandwidth update request
type DeviceAdditionalBandwidthUpdateRequest struct {
AdditionalBandwidth *int `json:"additionalBandwidth"`
Expand Down
53 changes: 53 additions & 0 deletions rest_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ func (c RestClient) CreateRedundantDevice(primary Device, secondary Device) (*st
return respBody.UUID, respBody.SecondaryUUID, nil
}

func (c RestClient) AddSecondary(primaryUuid string, secondary Device) (*string, error) {
updateErr := UpdateError{}
secondaryUuid, err := c.addSecondaryDevice(primaryUuid, secondary)
if err != nil {
updateErr.AddChangeError(changeTypeUpdate, "secondary", secondary, err)
}
return secondaryUuid, nil
}

// GetDevice fetches details of a device with a given UUID
func (c RestClient) GetDevice(uuid string) (*Device, error) {
path := "/ne/v1/devices/" + url.PathEscape(uuid)
Expand Down Expand Up @@ -127,6 +136,15 @@ func (c RestClient) DeleteDevice(uuid string) error {
return nil
}

func (c RestClient) DeleteSecondaryDevice(uuid string) error {
path := "/ne/v1/devices/" + url.PathEscape(uuid)
req := c.R().SetQueryParam("deleteRedundantDevice", "false")
if err := c.Execute(req, http.MethodDelete, path); err != nil {
return err
}
return nil
}

// WithDeviceName sets new device name in a composite device update request
func (req *restDeviceUpdateRequest) WithDeviceName(deviceName string) DeviceUpdateRequest {
req.deviceFields["deviceName"] = deviceName
Expand Down Expand Up @@ -441,6 +459,28 @@ func createRedundantDeviceRequest(primary Device, secondary Device) api.DeviceRe
return req
}

func addSecondaryDeviceRequest(primaryDeviceUuid string, secondary Device) api.AddSecondaryRequest {
req := api.AddSecondaryRequest{}
req.PrimaryDeviceUUID = &primaryDeviceUuid
secReq := api.SecondaryDeviceRequest{}
secReq.MetroCode = secondary.MetroCode
secReq.LicenseToken = secondary.LicenseToken
secReq.LicenseFileID = secondary.LicenseFileID
secReq.CloudInitFileID = secondary.CloudInitFileID
secReq.VirtualDeviceName = secondary.Name
secReq.Notifications = secondary.Notifications
secReq.HostNamePrefix = secondary.HostName
secReq.AccountNumber = secondary.AccountNumber
secReq.AdditionalBandwidth = secondary.AdditionalBandwidth
secReq.SshInterfaceID = secondary.WanInterfaceId
secReq.ACLTemplateUUID = secondary.ACLTemplateUUID
secReq.MgmtAclTemplateUUID = secondary.MgmtAclTemplateUuid
secReq.VendorConfig = secondary.VendorConfiguration
secReq.UserPublicKey = mapDeviceUserPublicKeyDomainToAPI(secondary.UserPublicKey)
req.Secondary = &secReq
return req
}

func (c RestClient) replaceDeviceACLTemplate(uuid string, wanAclTemplateUuid *string, mgmtAclTemplateUuid *string) error {
path := "/ne/v1/devices/" + url.PathEscape(uuid) + "/acl"
reqBody := api.DeviceACLTemplateRequest{
Expand Down Expand Up @@ -497,6 +537,19 @@ func (c RestClient) replaceDeviceFields(uuid string, fields map[string]interface
return nil
}

func (c RestClient) addSecondaryDevice(uuid string, secondary Device) (*string, error) {
//build logic for post secondary device
//uuid = primary device uuid
path := "/ne/v1/devices"
reqBody := addSecondaryDeviceRequest(uuid, secondary)
respBody := api.DeviceRequestResponse{}
req := c.R().SetBody(&reqBody).SetResult(&respBody)
if err := c.Execute(req, http.MethodPost, path); err != nil {
return nil, err
}
return respBody.SecondaryUUID, nil
}

func buildQueryParamValueString(values []string) string {
var sb strings.Builder
for i := range values {
Expand Down
0