mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-10-24 23:41:52 +08:00
fix: allow disk attach to multiple guests
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user