Skip to content

Commit

Permalink
fix: uphost use mac address to match interface
Browse files Browse the repository at this point in the history
Co-authored-by: 郑守迪 <[email protected]>
  • Loading branch information
fioncat and 郑守迪 authored Aug 22, 2023
1 parent 335eb13 commit 85d8dde
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions pkg/iputils/addr.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,22 @@ func GetMasterInterface() string {
return UHostMasterInterface
}

var targetInterface string
if strings.HasPrefix(meta.InstanceId, "upm") {
targetInterface = UPHostMasterInterface
var targetMac string
// 裸金属根据mac地址匹配网卡
if strings.HasPrefix(meta.InstanceId, "upm") && len(meta.UPHost.NetworkInterfaces) > 0 {
mac := meta.UPHost.NetworkInterfaces[0].Mac
targetMac = strings.ToLower(mac)
} else {
targetInterface = UHostMasterInterface
// 云主机直接返回eth0
return UHostMasterInterface
}

for _, iface := range list {
if iface.Name == targetInterface {
return targetInterface
if iface.HardwareAddr.String() == targetMac {
return iface.Name
}
}
return targetInterface
return UPHostMasterInterface
}

// Get node master network interface ip and mac address
Expand Down

0 comments on commit 85d8dde

Please sign in to comment.