mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
Merge pull request #809 from wanyaoqi/bugfix/wyq/disable-clean-iptables
bugfix: disable clean iptables && fix mac equal
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/util/netutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/hostman/hostutils"
|
||||
@@ -78,7 +79,7 @@ func (m *SGuestManager) PrepareImportFromLibvirt(
|
||||
|
||||
func IsMacInGuestConfig(guestConfig *compute.SImportGuestDesc, mac string) bool {
|
||||
for _, nic := range guestConfig.Nics {
|
||||
if nic.Mac == mac {
|
||||
if netutils.FormatMacAddr(nic.Mac) == netutils.FormatMacAddr(mac) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -90,18 +91,20 @@ func setAttributeFromLibvirtConfig(
|
||||
) (int, error) {
|
||||
var Matched = true
|
||||
for i, server := range libvirtConfig.Servers {
|
||||
macMap := make(map[string]string, 0)
|
||||
for mac := range server.MacIp {
|
||||
if !IsMacInGuestConfig(guestConfig, mac) {
|
||||
Matched = false
|
||||
break
|
||||
} else {
|
||||
macMap[netutils.FormatMacAddr(mac)] = server.MacIp[mac]
|
||||
Matched = true
|
||||
}
|
||||
}
|
||||
|
||||
if Matched {
|
||||
for idx, nic := range guestConfig.Nics {
|
||||
guestConfig.Nics[idx].Ip = server.MacIp[nic.Mac]
|
||||
guestConfig.Nics[idx].Ip = macMap[netutils.FormatMacAddr(nic.Mac)]
|
||||
}
|
||||
|
||||
log.Infof("Import guest %s", guestConfig.Name)
|
||||
|
||||
@@ -114,19 +114,19 @@ func (l *SLinuxBridgeDriver) RegisterHostlocalServer(mac, ip string) error {
|
||||
metadataServerLoc := fmt.Sprintf("%s:%d", ip, metadataPort)
|
||||
hostDnsServerLoc := fmt.Sprintf("%s:%d", ip, 53)
|
||||
|
||||
cmd := "iptables -t nat -F"
|
||||
cmd1 := strings.Split(cmd, " ")
|
||||
output, err := procutils.NewCommand(cmd1[0], cmd1[1:]...).Run()
|
||||
if err != nil {
|
||||
log.Errorf("Clean iptables failed: %s", output)
|
||||
return err
|
||||
}
|
||||
// cmd := "iptables -t nat -F"
|
||||
// cmd1 := strings.Split(cmd, " ")
|
||||
// output, err := procutils.NewCommand(cmd1[0], cmd1[1:]...).Run()
|
||||
// if err != nil {
|
||||
// log.Errorf("Clean iptables failed: %s", output)
|
||||
// return err
|
||||
// }
|
||||
|
||||
cmd = "iptables -t nat -A PREROUTING -s 0.0.0.0/0"
|
||||
cmd := "iptables -t nat -A PREROUTING -s 0.0.0.0/0"
|
||||
cmd += " -d 169.254.169.254/32 -p tcp -m tcp --dport 80"
|
||||
cmd += fmt.Sprintf(" -j DNAT --to-destination %s", metadataServerLoc)
|
||||
cmd1 = strings.Split(cmd, " ")
|
||||
output, err = procutils.NewCommand(cmd1[0], cmd1[1:]...).Run()
|
||||
cmd1 := strings.Split(cmd, " ")
|
||||
output, err := procutils.NewCommand(cmd1[0], cmd1[1:]...).Run()
|
||||
if err != nil {
|
||||
log.Errorf("Inject DNAT rule failed: %s", output)
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user