|
71 | 71 | import org.apache.cloudstack.engine.subsystem.api.storage.TemplateDataFactory; |
72 | 72 | import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo; |
73 | 73 | import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory; |
| 74 | +import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo; |
74 | 75 | import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService; |
75 | 76 | import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult; |
76 | 77 | import org.apache.cloudstack.framework.async.AsyncCallFuture; |
@@ -4737,14 +4738,17 @@ public UserVm restoreVMInternal(Account caller, UserVmVO vm, Long newTemplateId) |
4737 | 4738 | _volsDao.detachVolume(root.getId()); |
4738 | 4739 | volumeMgr.destroyVolume(root); |
4739 | 4740 |
|
4740 | | - // For VMware hypervisor since the old root volume is replaced by the new root volume in storage, force expunge old root volume |
| 4741 | + // For VMware hypervisor since the old root volume is replaced by the new root volume, force expunge old root volume if it has been created in storage |
4741 | 4742 | if (vm.getHypervisorType() == HypervisorType.VMware) { |
4742 | | - s_logger.info("Expunging volume " + root.getId() + " from primary data store"); |
4743 | | - AsyncCallFuture<VolumeApiResult> future = _volService.expungeVolumeAsync(volFactory.getVolume(root.getId())); |
4744 | | - try { |
4745 | | - future.get(); |
4746 | | - } catch (Exception e) { |
4747 | | - s_logger.debug("Failed to expunge volume:" + root.getId(), e); |
| 4743 | + VolumeInfo volumeInStorage = volFactory.getVolume(root.getId()); |
| 4744 | + if (volumeInStorage != null) { |
| 4745 | + s_logger.info("Expunging volume " + root.getId() + " from primary data store"); |
| 4746 | + AsyncCallFuture<VolumeApiResult> future = _volService.expungeVolumeAsync(volFactory.getVolume(root.getId())); |
| 4747 | + try { |
| 4748 | + future.get(); |
| 4749 | + } catch (Exception e) { |
| 4750 | + s_logger.debug("Failed to expunge volume:" + root.getId(), e); |
| 4751 | + } |
4748 | 4752 | } |
4749 | 4753 | } |
4750 | 4754 |
|
|
0 commit comments