fix(region): ignore params.Disks when cloning vm from snapshot

This commit is contained in:
rainzm
2020-11-25 18:23:14 +08:00
parent be76d1eb47
commit da03a979f8
+6 -1
View File
@@ -973,6 +973,7 @@ func (self *SHost) DoCreateVM(ctx context.Context, ds *SDatastore, params SCreat
return evm, nil
}
// If snapshot is not nil, params.Disks will be ignored
func (host *SHost) CloneVM(ctx context.Context, from *SVirtualMachine, snapshot *types.ManagedObjectReference, ds *SDatastore, params SCreateVMParam) (*SVirtualMachine, error) {
ovm := from.getVmObj()
@@ -1027,7 +1028,7 @@ func (host *SHost) CloneVM(ctx context.Context, from *SVirtualMachine, snapshot
}
}
if len(params.Disks) > 0 {
if len(params.Disks) > 0 && snapshot == nil {
driver := params.Disks[0].Driver
if driver == "scsi" || driver == "pvscsi" {
scsiDevs, err := from.FindController(ctx, "scsi")
@@ -1119,6 +1120,10 @@ func (host *SHost) CloneVM(ctx context.Context, from *SVirtualMachine, snapshot
return nil, errors.Error("clone successfully but unable to NewVirtualMachine")
}
if snapshot != nil {
return vm, nil
}
deviceChange = addDeviceChange
// adjust disk
var i int