mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(region,host): fix hot remove nic
- region: check is hot remove nic enable - host: del qemu device after del netdev
This commit is contained in:
@@ -409,3 +409,7 @@ func (self *SBaseGuestDriver) RequestRemoteUpdate(ctx context.Context, guest *mo
|
||||
func (self *SBaseGuestDriver) ValidateRebuildRoot(ctx context.Context, userCred mcclient.TokenCredential, guest *models.SGuest, input *api.ServerRebuildRootInput) (*api.ServerRebuildRootInput, error) {
|
||||
return input, nil
|
||||
}
|
||||
|
||||
func (self *SBaseGuestDriver) ValidateDetachNetwork(ctx context.Context, userCred mcclient.TokenCredential, guest *models.SGuest) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -654,3 +654,10 @@ func (self *SKVMGuestDriver) CheckLiveMigrate(guest *models.SGuest, userCred mcc
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SKVMGuestDriver) ValidateDetachNetwork(ctx context.Context, userCred mcclient.TokenCredential, guest *models.SGuest) error {
|
||||
if guest.Status == api.VM_RUNNING && guest.GetMetadata("hot_remove_nic", nil) != "enable" {
|
||||
return httperrors.NewBadRequestError("Guest %s can't hot remove nic", guest.GetName())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -2131,6 +2131,9 @@ func (self *SGuest) PerformDetachnetwork(ctx context.Context, userCred mcclient.
|
||||
if !utils.IsInStringArray(self.Status, []string{api.VM_READY, api.VM_RUNNING}) {
|
||||
return nil, httperrors.NewInvalidStatusError("Cannot detach network in status %s", self.Status)
|
||||
}
|
||||
if err := self.GetDriver().ValidateDetachNetwork(ctx, userCred, self); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var (
|
||||
reserve = jsonutils.QueryBoolean(data, "reserve", false)
|
||||
netStr, _ = data.GetString("net_id")
|
||||
|
||||
@@ -146,6 +146,7 @@ type IGuestDriver interface {
|
||||
IsRebuildRootSupportChangeUEFI() bool
|
||||
|
||||
ValidateRebuildRoot(ctx context.Context, userCred mcclient.TokenCredential, guest *SGuest, input *api.ServerRebuildRootInput) (*api.ServerRebuildRootInput, error)
|
||||
ValidateDetachNetwork(ctx context.Context, userCred mcclient.TokenCredential, guest *SGuest) error
|
||||
|
||||
IsSupportdDcryptPasswordFromSecretKey() bool
|
||||
|
||||
|
||||
@@ -385,7 +385,20 @@ func (n *SGuestNetworkSyncTask) onNetdevDel(nic jsonutils.JSONObject) {
|
||||
log.Errorf("script down nic failed %s", output)
|
||||
n.errors = append(n.errors, err)
|
||||
}
|
||||
n.syncNetworkConf()
|
||||
n.delNicDevice(nic)
|
||||
}
|
||||
|
||||
func (n *SGuestNetworkSyncTask) delNicDevice(nic jsonutils.JSONObject) {
|
||||
callback := func(res string) {
|
||||
if len(res) > 0 {
|
||||
log.Errorf("network device del failed %s", res)
|
||||
n.errors = append(n.errors, fmt.Errorf("network device del failed %s", res))
|
||||
} else {
|
||||
n.syncNetworkConf()
|
||||
}
|
||||
}
|
||||
ifname, _ := nic.GetString("ifname")
|
||||
n.guest.Monitor.DeviceDel(fmt.Sprintf("netdev-%s", ifname), callback)
|
||||
}
|
||||
|
||||
func (n *SGuestNetworkSyncTask) addNic(nic jsonutils.JSONObject) {
|
||||
|
||||
@@ -404,6 +404,7 @@ func (s *SKVMGuestInstance) onImportGuestMonitorConnected(ctx context.Context) {
|
||||
s.QemuVersion = version
|
||||
meta := jsonutils.NewDict()
|
||||
meta.Set("hotplug_cpu_mem", jsonutils.NewString("disable"))
|
||||
meta.Set("hot_remove_nic", jsonutils.NewString("disable"))
|
||||
meta.Set("__qemu_version", jsonutils.NewString(s.GetQemuVersionStr()))
|
||||
s.SyncMetadata(meta)
|
||||
s.SyncStatus()
|
||||
@@ -1327,6 +1328,7 @@ func (s *SKVMGuestInstance) OnResumeSyncMetadataInfo() {
|
||||
meta.Set("__qemu_version", jsonutils.NewString(s.GetQemuVersionStr()))
|
||||
meta.Set("__vnc_port", jsonutils.NewInt(int64(s.GetVncPort())))
|
||||
meta.Set("hotplug_cpu_mem", jsonutils.NewString("enable"))
|
||||
meta.Set("hot_remove_nic", jsonutils.NewString("enable"))
|
||||
if len(s.VncPassword) > 0 {
|
||||
meta.Set("__vnc_password", jsonutils.NewString(s.VncPassword))
|
||||
}
|
||||
|
||||
@@ -285,6 +285,7 @@ func (s *SKVMGuestInstance) getVnicDesc(nic jsonutils.JSONObject) string {
|
||||
bw, _ := nic.Int("bw")
|
||||
|
||||
cmd := fmt.Sprintf(" -device %s", s.getNicDeviceModel(driver))
|
||||
cmd += fmt.Sprintf(",id=netdev-%s", ifname)
|
||||
cmd += fmt.Sprintf(",netdev=%s", ifname)
|
||||
cmd += fmt.Sprintf(",mac=%s", mac)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user