mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-08-29 03:51:54 +08:00
fix: host flush addrs instead of reset interface (#23947)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
@@ -298,7 +298,8 @@ func (d *SBaseBridgeDriver) MigrateSlaveConfigs(o IBridgeDriver) error {
|
||||
}
|
||||
}
|
||||
{
|
||||
err := d.inter.Reset()
|
||||
tryUnmanageInterface(d.inter.String())
|
||||
err := d.inter.FlushAddrs()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "ClearAddrs")
|
||||
}
|
||||
@@ -410,19 +411,23 @@ func (d *SBaseBridgeDriver) ConfirmToConfig() (bool, string, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func tryUnmanageInterface(ifname string) {
|
||||
// ensure the device is not managed by NetworkManager
|
||||
// nmcli dev set <interface_name> managed no
|
||||
output, err := procutils.NewRemoteCommandAsFarAsPossible("nmcli", "dev", "set", ifname, "managed", "no").Output()
|
||||
if err != nil {
|
||||
log.Errorf("run cmd: nmcli dev set %s managed no, output: %s, error: %s", ifname, string(output), err)
|
||||
}
|
||||
}
|
||||
|
||||
func (d *SBaseBridgeDriver) SetupAddresses() error {
|
||||
br := d.bridge.String()
|
||||
if d.inter != nil {
|
||||
// first shutdown the origin interface
|
||||
ifname := d.inter.String()
|
||||
if err := d.inter.Shutdown(); err != nil {
|
||||
return errors.Wrapf(err, "shutdown bridge %s slave ifname: %s", br, ifname)
|
||||
}
|
||||
// ensure the device is not managed by NetworkManager
|
||||
// nmcli dev set <interface_name> managed no
|
||||
output, err := procutils.NewRemoteCommandAsFarAsPossible("nmcli", "dev", "set", ifname, "managed", "no").Output()
|
||||
if err != nil {
|
||||
log.Errorf("run cmd: nmcli dev set %s managed no, output: %s, error: %s", ifname, string(output), err)
|
||||
tryUnmanageInterface(ifname)
|
||||
if err := d.inter.FlushAddrs(); err != nil {
|
||||
return errors.Wrapf(err, "bridge %s slave ifname: %s flush addrs fail", br, ifname)
|
||||
}
|
||||
}
|
||||
{
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package kmsg // import "yunion.io/x/onecloud/pkg/util/kmsg"
|
||||
@@ -0,0 +1,36 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package kmsg
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func Log(msg string) {
|
||||
f, err := os.OpenFile("/dev/kmsg", os.O_WRONLY, 0)
|
||||
if err != nil {
|
||||
// This will likely fail without root privileges
|
||||
log.Fatalf("failed to open /dev/kmsg: %v", err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
if !strings.HasSuffix(msg, "\n") {
|
||||
msg = msg + "\n"
|
||||
}
|
||||
|
||||
f.WriteString(msg)
|
||||
}
|
||||
@@ -115,6 +115,15 @@ func (n *SNetInterface) setStatus(status string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *SNetInterface) FlushAddrs() error {
|
||||
cmd := procutils.NewCommand("ip", "addr", "flush", "dev", n.name)
|
||||
msg, err := cmd.Output()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, strings.TrimSpace(string(msg)))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func getRouteSpecs(listFunc func() ([]iproute2.RouteSpec, error)) []iproute2.RouteSpec {
|
||||
routespecs, err := listFunc()
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user