From db89640dfe9c4bf441d36db1d1ce07490691d8d0 Mon Sep 17 00:00:00 2001 From: Yousong Zhou Date: Fri, 23 Apr 2021 16:30:56 +0800 Subject: [PATCH] hostman: ovn: do not set external_ids:iface-id for backup --- pkg/hostman/guestman/qemu-kvmhelper.go | 5 +++-- pkg/hostman/hostinfo/hostbridge/hostbridge.go | 16 ++++++++-------- pkg/hostman/hostinfo/hostbridge/linux_bridge.go | 12 ++++++------ pkg/hostman/hostinfo/hostbridge/ovs.go | 16 +++++++++------- 4 files changed, 26 insertions(+), 23 deletions(-) diff --git a/pkg/hostman/guestman/qemu-kvmhelper.go b/pkg/hostman/guestman/qemu-kvmhelper.go index 1e381025ad..47c1e8060a 100644 --- a/pkg/hostman/guestman/qemu-kvmhelper.go +++ b/pkg/hostman/guestman/qemu-kvmhelper.go @@ -222,11 +222,12 @@ func (s *SKVMGuestInstance) generateNicScripts(nic jsonutils.JSONObject) error { if dev == nil { return fmt.Errorf("Can't find bridge %s", bridge) } - if err := dev.GenerateIfupScripts(s.getNicUpScriptPath(nic), nic); err != nil { + isSlave := s.IsSlave() + if err := dev.GenerateIfupScripts(s.getNicUpScriptPath(nic), nic, isSlave); err != nil { log.Errorln(err) return err } - if err := dev.GenerateIfdownScripts(s.getNicDownScriptPath(nic), nic); err != nil { + if err := dev.GenerateIfdownScripts(s.getNicDownScriptPath(nic), nic, isSlave); err != nil { log.Errorln(err) return err } diff --git a/pkg/hostman/hostinfo/hostbridge/hostbridge.go b/pkg/hostman/hostinfo/hostbridge/hostbridge.go index 5c106be47b..9919decb80 100644 --- a/pkg/hostman/hostinfo/hostbridge/hostbridge.go +++ b/pkg/hostman/hostinfo/hostbridge/hostbridge.go @@ -52,12 +52,12 @@ type IBridgeDriver interface { PersistentMac() error DisableDHCPClient() (bool, error) - GenerateIfupScripts(scriptPath string, nic jsonutils.JSONObject) error - GenerateIfdownScripts(scriptPath string, nic jsonutils.JSONObject) error + GenerateIfupScripts(scriptPath string, nic jsonutils.JSONObject, isSlave bool) error + GenerateIfdownScripts(scriptPath string, nic jsonutils.JSONObject, isSlave bool) error RegisterHostlocalServer(mac, ip string) error - getUpScripts(nic jsonutils.JSONObject) (string, error) - getDownScripts(nic jsonutils.JSONObject) (string, error) + getUpScripts(nic jsonutils.JSONObject, isSlave bool) (string, error) + getDownScripts(nic jsonutils.JSONObject, isSlave bool) (string, error) } type SBaseBridgeDriver struct { @@ -303,8 +303,8 @@ func (d *SBaseBridgeDriver) saveFileExecutable(scriptPath, script string) error return os.Chmod(scriptPath, syscall.S_IRUSR|syscall.S_IWUSR|syscall.S_IXUSR) } -func (d *SBaseBridgeDriver) generateIfdownScripts(driver IBridgeDriver, scriptPath string, nic jsonutils.JSONObject) error { - script, err := driver.getDownScripts(nic) +func (d *SBaseBridgeDriver) generateIfdownScripts(driver IBridgeDriver, scriptPath string, nic jsonutils.JSONObject, isSlave bool) error { + script, err := driver.getDownScripts(nic, isSlave) if err != nil { log.Errorln(err) return err @@ -312,8 +312,8 @@ func (d *SBaseBridgeDriver) generateIfdownScripts(driver IBridgeDriver, scriptPa return d.saveFileExecutable(scriptPath, script) } -func (d *SBaseBridgeDriver) generateIfupScripts(driver IBridgeDriver, scriptPath string, nic jsonutils.JSONObject) error { - script, err := driver.getUpScripts(nic) +func (d *SBaseBridgeDriver) generateIfupScripts(driver IBridgeDriver, scriptPath string, nic jsonutils.JSONObject, isSlave bool) error { + script, err := driver.getUpScripts(nic, isSlave) if err != nil { log.Errorln(err) return err diff --git a/pkg/hostman/hostinfo/hostbridge/linux_bridge.go b/pkg/hostman/hostinfo/hostbridge/linux_bridge.go index 60d781eff7..bf7553b323 100644 --- a/pkg/hostman/hostinfo/hostbridge/linux_bridge.go +++ b/pkg/hostman/hostinfo/hostbridge/linux_bridge.go @@ -83,15 +83,15 @@ func (l *SLinuxBridgeDriver) Interfaces() ([]string, error) { return infs, nil } -func (l *SLinuxBridgeDriver) GenerateIfdownScripts(scriptPath string, nic jsonutils.JSONObject) error { - return l.generateIfdownScripts(l, scriptPath, nic) +func (l *SLinuxBridgeDriver) GenerateIfdownScripts(scriptPath string, nic jsonutils.JSONObject, isSlave bool) error { + return l.generateIfdownScripts(l, scriptPath, nic, isSlave) } -func (l *SLinuxBridgeDriver) GenerateIfupScripts(scriptPath string, nic jsonutils.JSONObject) error { - return l.generateIfupScripts(l, scriptPath, nic) +func (l *SLinuxBridgeDriver) GenerateIfupScripts(scriptPath string, nic jsonutils.JSONObject, isSlave bool) error { + return l.generateIfupScripts(l, scriptPath, nic, isSlave) } -func (l *SLinuxBridgeDriver) getUpScripts(nic jsonutils.JSONObject) (string, error) { +func (l *SLinuxBridgeDriver) getUpScripts(nic jsonutils.JSONObject, isSlave bool) (string, error) { s := "#!/bin/bash\n\n" s += fmt.Sprintf("switch='%s'\n", l.bridge) if options.HostOptions.TunnelPaddingBytes > 0 { @@ -103,7 +103,7 @@ func (l *SLinuxBridgeDriver) getUpScripts(nic jsonutils.JSONObject) (string, err return s, nil } -func (l *SLinuxBridgeDriver) getDownScripts(nic jsonutils.JSONObject) (string, error) { +func (l *SLinuxBridgeDriver) getDownScripts(nic jsonutils.JSONObject, isSlave bool) (string, error) { s := "#!/bin/sh\n\n" s += fmt.Sprintf("switch='%s'\n", l.bridge) s += "brctl show ${switch} | grep $1\n" diff --git a/pkg/hostman/hostinfo/hostbridge/ovs.go b/pkg/hostman/hostinfo/hostbridge/ovs.go index 2243dc4165..d4ff069c79 100644 --- a/pkg/hostman/hostinfo/hostbridge/ovs.go +++ b/pkg/hostman/hostinfo/hostbridge/ovs.go @@ -110,15 +110,15 @@ func (d *SOVSBridgeDriver) PersistentMac() error { return nil } -func (o *SOVSBridgeDriver) GenerateIfdownScripts(scriptPath string, nic jsonutils.JSONObject) error { - return o.generateIfdownScripts(o, scriptPath, nic) +func (o *SOVSBridgeDriver) GenerateIfdownScripts(scriptPath string, nic jsonutils.JSONObject, isSlave bool) error { + return o.generateIfdownScripts(o, scriptPath, nic, isSlave) } -func (o *SOVSBridgeDriver) GenerateIfupScripts(scriptPath string, nic jsonutils.JSONObject) error { - return o.generateIfupScripts(o, scriptPath, nic) +func (o *SOVSBridgeDriver) GenerateIfupScripts(scriptPath string, nic jsonutils.JSONObject, isSlave bool) error { + return o.generateIfupScripts(o, scriptPath, nic, isSlave) } -func (o *SOVSBridgeDriver) getUpScripts(nic jsonutils.JSONObject) (string, error) { +func (o *SOVSBridgeDriver) getUpScripts(nic jsonutils.JSONObject, isSlave bool) (string, error) { var ( bridge, _ = nic.GetString("bridge") ifname, _ = nic.GetString("ifname") @@ -166,7 +166,9 @@ func (o *SOVSBridgeDriver) getUpScripts(nic jsonutils.JSONObject) (string, error s += "fi\n" s += "ovs-vsctl add-port $SWITCH $IF $TAG\n" if vpcProvider == compute.VPC_PROVIDER_OVN { - s += "ovs-vsctl set Interface $IF external_ids:iface-id=iface-$NET_ID-$IF\n" + if !isSlave { + s += "ovs-vsctl set Interface $IF external_ids:iface-id=iface-$NET_ID-$IF\n" + } } s += "PORT=$(ovs-ofctl show $SWITCH | grep -w $IF)\n" s += "PORT=$(echo $PORT | awk 'BEGIN{FS=\"(\"}{print $1}')\n" @@ -186,7 +188,7 @@ func (o *SOVSBridgeDriver) getUpScripts(nic jsonutils.JSONObject) (string, error return s, nil } -func (o *SOVSBridgeDriver) getDownScripts(nic jsonutils.JSONObject) (string, error) { +func (o *SOVSBridgeDriver) getDownScripts(nic jsonutils.JSONObject, isSlave bool) (string, error) { var ( bridge, _ = nic.GetString("bridge") ifname, _ = nic.GetString("ifname")