|
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; |
@@ -5113,14 +5114,17 @@ public UserVm restoreVMInternal(Account caller, UserVmVO vm, Long newTemplateId) |
5113 | 5114 | _volsDao.detachVolume(root.getId()); |
5114 | 5115 | volumeMgr.destroyVolume(root); |
5115 | 5116 |
|
5116 | | - // For VMware hypervisor since the old root volume is replaced by the new root volume in storage, force expunge old root volume |
| 5117 | + // 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 |
5117 | 5118 | if (vm.getHypervisorType() == HypervisorType.VMware) { |
5118 | | - s_logger.info("Expunging volume " + root.getId() + " from primary data store"); |
5119 | | - AsyncCallFuture<VolumeApiResult> future = _volService.expungeVolumeAsync(volFactory.getVolume(root.getId())); |
5120 | | - try { |
5121 | | - future.get(); |
5122 | | - } catch (Exception e) { |
5123 | | - s_logger.debug("Failed to expunge volume:" + root.getId(), e); |
| 5119 | + VolumeInfo volumeInStorage = volFactory.getVolume(root.getId()); |
| 5120 | + if (volumeInStorage != null) { |
| 5121 | + s_logger.info("Expunging volume " + root.getId() + " from primary data store"); |
| 5122 | + AsyncCallFuture<VolumeApiResult> future = _volService.expungeVolumeAsync(volFactory.getVolume(root.getId())); |
| 5123 | + try { |
| 5124 | + future.get(); |
| 5125 | + } catch (Exception e) { |
| 5126 | + s_logger.debug("Failed to expunge volume:" + root.getId(), e); |
| 5127 | + } |
5124 | 5128 | } |
5125 | 5129 | } |
5126 | 5130 |
|
|
0 commit comments