mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #11610 from swordqiu/hotfix/qj-host-detach-wire-bugs
fix: host detach wire not update netinterface
This commit is contained in:
@@ -805,7 +805,7 @@ func (f *ResourceHandlers) detachHandle(ctx context.Context, w http.ResponseWrit
|
||||
jmod, e := modulebase.GetJointModule2(session, module, module2)
|
||||
var obj jsonutils.JSONObject
|
||||
if e == nil { // joint detach
|
||||
obj, e = jmod.Detach(session, req.ResID(), req.ResID2(), nil)
|
||||
obj, e = jmod.Detach(session, req.ResID(), req.ResID2(), req.Query())
|
||||
} else {
|
||||
obj, e = module2.DeleteInContextWithParam(session, req.ResID2(), req.Query(), req.Body(), module, req.ResID())
|
||||
}
|
||||
|
||||
@@ -4453,6 +4453,9 @@ func (self *SHost) PerformDisableNetif(ctx context.Context, userCred mcclient.To
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
/*
|
||||
* Disable a net interface, remove IP address if assigned
|
||||
*/
|
||||
func (self *SHost) DisableNetif(ctx context.Context, userCred mcclient.TokenCredential, netif *SNetInterface, reserve bool) error {
|
||||
bn := netif.GetBaremetalNetwork()
|
||||
var ipAddr string
|
||||
|
||||
@@ -156,7 +156,11 @@ func (self *SHostwire) ValidateDeleteCondition(ctx context.Context) error {
|
||||
return httperrors.NewInternalServerError("GetGuestnicsCount fail %s", err)
|
||||
}
|
||||
if cnt > 0 {
|
||||
return httperrors.NewNotEmptyError("guest on the host are using networks on this wire")
|
||||
// check if this is the last one
|
||||
host := self.GetHost()
|
||||
if len(host.getHostwiresOfId(self.WireId)) == 1 {
|
||||
return httperrors.NewNotEmptyError("guest on the host are using networks on this wire")
|
||||
}
|
||||
}
|
||||
return self.SHostJointsBase.ValidateDeleteCondition(ctx)
|
||||
}
|
||||
@@ -165,6 +169,29 @@ func (self *SHostwire) Delete(ctx context.Context, userCred mcclient.TokenCreden
|
||||
return db.DeleteModel(ctx, userCred, self)
|
||||
}
|
||||
|
||||
func (self *SHostwire) PreDelete(ctx context.Context, userCred mcclient.TokenCredential) {
|
||||
host := self.GetHost()
|
||||
if host == nil {
|
||||
log.Errorf("no host found??")
|
||||
return
|
||||
}
|
||||
netif := host.GetNetInterface(self.MacAddr)
|
||||
if netif == nil {
|
||||
log.Errorf("no netinterface for %s", self.MacAddr)
|
||||
return
|
||||
}
|
||||
err := host.DisableNetif(ctx, userCred, netif, false)
|
||||
if err != nil {
|
||||
log.Errorf("host.DisableNetif fail %s", err)
|
||||
return
|
||||
}
|
||||
err = netif.UnsetWire()
|
||||
if err != nil {
|
||||
log.Errorf("netif.UnsetWire fail %s", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SHostwire) Detach(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
return db.DetachJoint(ctx, userCred, self)
|
||||
}
|
||||
|
||||
@@ -78,6 +78,14 @@ func (manager *SNetInterfaceManager) FetchByMac(mac string) (*SNetInterface, err
|
||||
return netif.(*SNetInterface), nil
|
||||
}
|
||||
|
||||
func (netif *SNetInterface) UnsetWire() error {
|
||||
_, err := db.Update(netif, func() error {
|
||||
netif.WireId = ""
|
||||
return nil
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func (netif *SNetInterface) GetWire() *SWire {
|
||||
if len(netif.WireId) > 0 {
|
||||
wireModel, _ := WireManager.FetchById(netif.WireId)
|
||||
|
||||
Reference in New Issue
Block a user