Merge pull request #8865 from swordqiu/hotfix/qj-allow-disk-attach-to-multiple-servers

fix: allow disk attach to multiple guests
This commit is contained in:
yunion-ci-robot
2020-11-21 19:25:00 +08:00
committed by GitHub
2 changed files with 19 additions and 10 deletions
+9 -6
View File
@@ -670,13 +670,16 @@ func (self *SGuest) ValidateAttachDisk(ctx context.Context, disk *SDisk) error {
}
}
attached, err := disk.isAttached()
if err != nil {
return httperrors.NewInternalServerError("isAttached check failed %s", err)
}
if attached {
return httperrors.NewInputParameterError("Disk %s has been attached", disk.Name)
if disk.IsLocal() {
attached, err := disk.isAttached()
if err != nil {
return httperrors.NewInternalServerError("isAttached check failed %s", err)
}
if attached {
return httperrors.NewInputParameterError("Disk %s has been attached", disk.Name)
}
}
if len(disk.GetPathAtHost(self.GetHost())) == 0 {
return httperrors.NewInputParameterError("Disk %s not belong the guest's host", disk.Name)
}
+10 -4
View File
@@ -3709,11 +3709,17 @@ func (self *SGuest) DeleteAllDisksInDB(ctx context.Context, userCred mcclient.To
}
if disk != nil {
db.OpsLog.LogEvent(disk, db.ACT_DELETE, nil, userCred)
db.OpsLog.LogEvent(disk, db.ACT_DELOCATE, nil, userCred)
err = disk.RealDelete(ctx, userCred)
cnt, err := disk.GetGuestDiskCount()
if err != nil {
return err
return errors.Wrap(err, "disk.GetGuestDiskCount")
}
if cnt == 0 {
db.OpsLog.LogEvent(disk, db.ACT_DELETE, nil, userCred)
db.OpsLog.LogEvent(disk, db.ACT_DELOCATE, nil, userCred)
err = disk.RealDelete(ctx, userCred)
if err != nil {
return errors.Wrap(err, "disk.RealDelete")
}
}
}
}