Skip to content
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

remove duplicated method from netbox.go #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 1 addition & 1 deletion internal/discovery/netbox_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (sd *NetboxDiscovery) getData() (tgroups []*targetgroup.Group, err error) {

func (sd *NetboxDiscovery) loadDcimDevices(d dcimDevice) (tgroups []*targetgroup.Group, err error) {
var dcims []models.Device
dcims, err = sd.netbox.DevicesByParams(d.DcimDevicesListParams)
dcims, err = sd.netbox.DevicesByParams(&d.DcimDevicesListParams)
if err != nil {
return tgroups, err
}
Expand Down
31 changes: 2 additions & 29 deletions pkg/netbox/netbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (nb *Netbox) DevicesByRegion(query, manufacturer, region, status string) (r
}

//DevicesByRegion retrieves devices by region, manufacturer and status
func (nb *Netbox) DevicesByParams(params dcim.DcimDevicesListParams) (res []models.Device, err error) {
func (nb *Netbox) DevicesByParams(params *dcim.DcimDevicesListParams) (res []models.Device, err error) {
res = make([]models.Device, 0)
limit := int64(100)
params.WithLimit(&limit)
Expand All @@ -191,7 +191,7 @@ func (nb *Netbox) DevicesByParams(params dcim.DcimDevicesListParams) (res []mode
offset = *params.Offset + limit
}
params.Offset = &offset
list, err := nb.client.Dcim.DcimDevicesList(&params, nil)
list, err := nb.client.Dcim.DcimDevicesList(params, nil)
if err != nil {
return res, err
}
Expand Down Expand Up @@ -435,33 +435,6 @@ func (nb *Netbox) ServersByRegion(rackRole string, region string) ([]models.Devi
return results, nil
}

// AcitveDevicesByCustomParameters retrievs all active devices with custom parameters
func (nb *Netbox) ActiveDevicesByCustomParameters(query string, params *dcim.DcimDevicesListParams) ([]models.Device, error) {
res := make([]models.Device, 0)
activeStatus := "1"
limit := int64(100)
params.WithStatus(&activeStatus)
params.WithLimit(&limit)
for {
offset := int64(0)
if params.Offset != nil {
offset = *params.Offset + limit
}
params.Offset = &offset
list, err := nb.client.Dcim.DcimDevicesList(params, nil)
if err != nil {
return res, err
}
for _, device := range list.Payload.Results {
res = append(res, *device)
}
if list.Payload.Next == nil {
break
}
}
return res, nil
}

func client(host, token string) (*netboxclient.NetBox, error) {

tlsClient, err := runtimeclient.TLSClient(runtimeclient.TLSClientOptions{InsecureSkipVerify: true})
Expand Down