diff --git a/pkg/hostman/guestman/libvirt.go b/pkg/hostman/guestman/libvirt.go index f9c9b71e78..2e2c8286d3 100644 --- a/pkg/hostman/guestman/libvirt.go +++ b/pkg/hostman/guestman/libvirt.go @@ -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) diff --git a/pkg/hostman/hostinfo/hostbridge/linux_bridge.go b/pkg/hostman/hostinfo/hostbridge/linux_bridge.go index cf9d91c1dd..a08e137798 100644 --- a/pkg/hostman/hostinfo/hostbridge/linux_bridge.go +++ b/pkg/hostman/hostinfo/hostbridge/linux_bridge.go @@ -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