mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix: netplan empty bond address (#19940)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
@@ -952,6 +952,7 @@ func (d *sDebianLikeRootFs) DeployNetworkingScripts(rootFs IDiskPartition, nics
|
||||
cmds.WriteString(fmt.Sprintf("iface %s inet static\n", nicDesc.Name))
|
||||
cmds.WriteString(fmt.Sprintf(" address %s\n", nicDesc.Ip))
|
||||
cmds.WriteString(fmt.Sprintf(" netmask %s\n", netmask))
|
||||
cmds.WriteString(fmt.Sprintf(" hwaddress ether %s\n", nicDesc.Mac))
|
||||
if len(nicDesc.Gateway) > 0 && nicDesc.Ip == mainIp {
|
||||
cmds.WriteString(fmt.Sprintf(" gateway %s\n", nicDesc.Gateway))
|
||||
}
|
||||
@@ -1380,15 +1381,20 @@ func (r *sRedhatLikeRootFs) deployNetworkingScripts(rootFs IDiskPartition, nics
|
||||
cmds.WriteString(fmt.Sprintf("MTU=%d\n", nicDesc.Mtu))
|
||||
}
|
||||
if len(nicDesc.Mac) > 0 && nicDesc.NicType != api.NIC_TYPE_INFINIBAND {
|
||||
cmds.WriteString("HWADDR=")
|
||||
cmds.WriteString(nicDesc.Mac)
|
||||
cmds.WriteString("\n")
|
||||
if len(nicDesc.TeamingSlaves) == 0 {
|
||||
// only real physical nic can set HWADDR
|
||||
cmds.WriteString("HWADDR=")
|
||||
cmds.WriteString(nicDesc.Mac)
|
||||
cmds.WriteString("\n")
|
||||
}
|
||||
cmds.WriteString("MACADDR=")
|
||||
cmds.WriteString(nicDesc.Mac)
|
||||
cmds.WriteString("\n")
|
||||
}
|
||||
if len(nicDesc.TeamingSlaves) != 0 {
|
||||
cmds.WriteString(`BONDING_OPTS="mode=4 miimon=100"\n`)
|
||||
if len(nicDesc.TeamingSlaves) > 0 {
|
||||
// bonding
|
||||
cmds.WriteString(`BONDING_OPTS="mode=4 miimon=100"`)
|
||||
cmds.WriteString("\n")
|
||||
}
|
||||
if nicDesc.TeamingMaster != nil {
|
||||
cmds.WriteString("BOOTPROTO=none\n")
|
||||
|
||||
@@ -69,16 +69,13 @@ func newNetplanNetwork(allNics []*types.SServerNic, bondNics []*types.SServerNic
|
||||
network.AddEthernet(sn.Name, nicConf)
|
||||
}
|
||||
|
||||
primaryNic := bondNic
|
||||
netConf := getNetplanEthernetConfig(primaryNic, true)
|
||||
netConf.MacAddress = bondNic.Mac
|
||||
netConf := getNetplanEthernetConfig(bondNic, true)
|
||||
|
||||
if netConf.Mtu == 0 {
|
||||
netConf.Mtu = defaultMtu
|
||||
}
|
||||
|
||||
// TODO: implement kinds of bond mode config
|
||||
// bondConf := netplan.NewBondMode4(netConf, interfaces)
|
||||
bondConf := netplan.NewBondMode4(netConf, interfaces)
|
||||
|
||||
network.AddBond(bondNic.Name, bondConf)
|
||||
@@ -120,6 +117,7 @@ func getNetplanEthernetConfig(nic *types.SServerNic, isBond bool) *netplan.Ether
|
||||
netutils2.GetNicDns(nic),
|
||||
routes,
|
||||
)
|
||||
nicConf.MacAddress = nic.Mac
|
||||
if nic.Mtu > 0 {
|
||||
nicConf.Mtu = nic.Mtu
|
||||
}
|
||||
|
||||
@@ -110,8 +110,8 @@ func TestNewNetplanConfig(t *testing.T) {
|
||||
Addresses: []string{
|
||||
"10.168.222.175/24",
|
||||
},
|
||||
// MacAddress: "00:24:c7:16:80:f2",
|
||||
Gateway4: "10.168.222.1",
|
||||
MacAddress: "00:24:c7:16:80:f2",
|
||||
Gateway4: "10.168.222.1",
|
||||
Nameservers: &netplan.Nameservers{
|
||||
Search: []string{
|
||||
"cloud.local",
|
||||
|
||||
@@ -131,7 +131,8 @@ func convertNicConfigs(nics []*types.SServerNic) ([]*types.SServerNic, []*types.
|
||||
tnic.Gateway6 = ""
|
||||
master.Name = fmt.Sprintf("bond%d", len(bondNics))
|
||||
master.TeamingSlaves = []*types.SServerNic{&nnic, &tnic}
|
||||
master.Mac = ""
|
||||
// why reset master.Mac?
|
||||
// master.Mac = ""
|
||||
allNics = append(allNics, &nnic, &tnic, master)
|
||||
bondNics = append(bondNics, master)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user