fix(region): set storage with snapshot id when change vm disk config

This commit is contained in:
Qu Xuan
2021-10-22 11:45:35 +08:00
parent 4c6069a222
commit c6a1d5f3f9
+9 -1
View File
@@ -2545,7 +2545,15 @@ func (self *SGuest) PerformChangeConfig(ctx context.Context, userCred mcclient.T
var diskIdx = 1
for i := range input.Disks {
disk := input.Disks[i]
if len(disk.Backend) == 0 {
if len(disk.SnapshotId) > 0 {
snapObj, err := SnapshotManager.FetchById(disk.SnapshotId)
if err != nil {
return nil, httperrors.NewResourceNotFoundError("snapshot %s not found", disk.SnapshotId)
}
snap := snapObj.(*SSnapshot)
disk.Storage = snap.StorageId
}
if len(disk.Backend) == 0 && len(disk.Storage) == 0 {
disk.Backend = self.getDefaultStorageType()
}
if disk.SizeMb > 0 {