Skip to content

Commit

Permalink
Discover linux-kvm hosts
Browse files Browse the repository at this point in the history
Probably not the final convention, but that is
how the kvm-nodes have been deployed in qa
  • Loading branch information
fwiesel committed May 15, 2023
1 parent d1c066a commit 0022cda
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
5 changes: 5 additions & 0 deletions etc/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ discoveries:
manufacturer: "cisco"
region: "eu-west"
status: "1"
- custom_labels:
job: "linux-kvm"
target: 4
platform: "linux-kvm"
region: "eu-west"
virtualization:
vm:
- custom_labels:
Expand Down
2 changes: 2 additions & 0 deletions internal/discovery/netbox_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,8 @@ func (sd *NetboxDiscovery) getDeviceIP(t int, id int64, i *models.NestedIPAddres
ips = append(ips, ip)
case loopback10:
ips, err = sd.netbox.DeviceInterfaceNameIPs("Loopback10", strconv.FormatInt(id, 10))
case bond0:
ips, err = sd.netbox.DeviceInterfaceNameIPs("bond0", strconv.FormatInt(id, 10))
default:
return ips, fmt.Errorf("Error getting ip from device: %d. Error: %s", id, "unknown target in config")
}
Expand Down
1 change: 1 addition & 0 deletions internal/discovery/netbox_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const (
primaryIP int = 1
managementIP int = 2
loopback10 int = 3
bond0 int = 4
)

type (
Expand Down
8 changes: 4 additions & 4 deletions pkg/netbox/netbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,10 @@ func (nb *Netbox) DeviceInterfaceNameIPs(name, deviceID string) (ips []string, e
}

// Interface retrieves the interface on the device
func (nb *Netbox) Interface(deviceID string, interfaceName string) (*models.Interface, error) {
func (nb *Netbox) Interface(deviceID string, interfaceNamePrefix string) (*models.Interface, error) {
params := dcim.NewDcimInterfacesListParams()
params.DeviceID = &deviceID
params.Name = &interfaceName
params.NameIsw = &interfaceNamePrefix
params.WithContext(context.Background())

limit := int64(1)
Expand All @@ -349,10 +349,10 @@ func (nb *Netbox) Interface(deviceID string, interfaceName string) (*models.Inte
return nil, err
}
if *list.Payload.Count < 1 {
return nil, fmt.Errorf("no %s interface found for device %s", interfaceName, deviceID)
return nil, fmt.Errorf("no %s interface found for device %s", interfaceNamePrefix, deviceID)
}
if *list.Payload.Count > 1 {
return nil, fmt.Errorf("more than 1 %s interface found for device %s", interfaceName, deviceID)
return nil, fmt.Errorf("more than 1 %s interface found for device %s", interfaceNamePrefix, deviceID)
}

return list.Payload.Results[0], nil
Expand Down

0 comments on commit 0022cda

Please sign in to comment.