From 84d2389aaf29764919c8f194f51869b600690844 Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Thu, 13 Apr 2023 11:06:37 +0200 Subject: [PATCH] return the primary network interface for discoverd close #775 Signed-off-by: Christian Goll --- CHANGELOG.md | 1 + internal/pkg/node/constructors.go | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 213a6b97..645de56c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -98,6 +98,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 or "runtime") rather than a concatenated list of individual overlays. This removes a limit on the number of overlays that could be included in a node or profile. #852, #876, #883, #896, #903 +- During node discovery, prefer the primary network interface, if defined. #775 ## [4.4.0] 2023-01-18 diff --git a/internal/pkg/node/constructors.go b/internal/pkg/node/constructors.go index 02882e26..3b4109a4 100644 --- a/internal/pkg/node/constructors.go +++ b/internal/pkg/node/constructors.go @@ -309,6 +309,14 @@ func (config *NodeYaml) ListAllProfiles() []string { return ret } +/* +FindDiscoverableNode returns the first discoverable node and an +interface to associate with the discovered interface. If the node has +a primary interface, it is returned; otherwise, the first interface +without a hardware address is returned. + +If no unconfigured nodes are found, an error is returned. +*/ func (config *NodeYaml) FindDiscoverableNode() (NodeInfo, string, error) { var ret NodeInfo @@ -318,6 +326,9 @@ func (config *NodeYaml) FindDiscoverableNode() (NodeInfo, string, error) { if !node.Discoverable.GetB() { continue } + if _, ok := node.NetDevs[node.PrimaryNetDev.Get()]; ok { + return node, node.PrimaryNetDev.Get(), nil + } for netdev, dev := range node.NetDevs { if !dev.Hwaddr.Defined() { return node, netdev, nil