Skip to content

Commit

Permalink
裸金属改为根据mac地址获取网卡 (#31)
Browse files Browse the repository at this point in the history
Co-authored-by: 郑守迪 <davis.zheng@ucloud.cn>
  • Loading branch information
NightRain233 and 郑守迪 committed Aug 22, 2023
1 parent 335eb13 commit 1eb7800
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 1eb7800

Please sign in to comment.