[GitHub] DaanHoogland closed pull request #2423: CLOUDSTACK-10250: Reinstall VM from bypassed registered template
DaanHoogland closed pull request #2423: CLOUDSTACK-10250: Reinstall VM from bypassed registered template URL: https://github.com/apache/cloudstack/pull/2423 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index dab741c3c27..a5bfc47584d 100644 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -313,6 +313,7 @@ import com.cloud.vm.snapshot.VMSnapshotVO; import com.cloud.vm.snapshot.dao.VMSnapshotDao; import com.cloud.storage.snapshot.SnapshotApiService; +import com.cloud.storage.VMTemplateStorageResourceAssoc; public class UserVmManagerImpl extends ManagerBase implements UserVmManager, VirtualMachineGuru, UserVmService, Configurable { private static final Logger s_logger = Logger.getLogger(UserVmManagerImpl.class); @@ -6100,10 +6101,8 @@ public UserVm restoreVMInternal(Account caller, UserVmVO vm, Long newTemplateId) throw ex; } } -TemplateDataStoreVO tmplStore = _templateStoreDao.findByTemplateZoneReady(template.getId(), vm.getDataCenterId()); -if (tmplStore == null) { -throw new InvalidParameterValueException("Cannot restore the vm as the template " + template.getUuid() + " isn't available in the zone"); -} + +checkRestoreVmFromTemplate(vm, template); if (needRestart) { try { @@ -6217,6 +6216,27 @@ public UserVm restoreVMInternal(Account caller, UserVmVO vm, Long newTemplateId) } +/** + * Perform basic checkings to make sure restore is possible. If not, #InvalidParameterValueException is thrown + * @param vm vm + * @param template template + * @throws InvalidParameterValueException if restore is not possible + */ +private void checkRestoreVmFromTemplate(UserVmVO vm, VMTemplateVO template) { +TemplateDataStoreVO tmplStore; +if (!template.isDirectDownload()) { +tmplStore = _templateStoreDao.findByTemplateZoneReady(template.getId(), vm.getDataCenterId()); +if (tmplStore == null) { +throw new InvalidParameterValueException("Cannot restore the vm as the template " + template.getUuid() + " isn't available in the zone"); +} +} else { +tmplStore = _templateStoreDao.findByTemplate(template.getId(), DataStoreRole.Image); +if (tmplStore == null || (tmplStore != null && !tmplStore.getDownloadState().equals(VMTemplateStorageResourceAssoc.Status.BYPASSED))) { +throw new InvalidParameterValueException("Cannot restore the vm as the bypassed template " + template.getUuid() + " isn't available in the zone"); +} +} +} + private void handleManagedStorage(UserVmVO vm, VolumeVO root) { if (Volume.State.Allocated.equals(root.getState())) { return; This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services
[GitHub] DaanHoogland closed pull request #2423: CLOUDSTACK-10250: Reinstall VM from bypassed registered template
DaanHoogland closed pull request #2423: CLOUDSTACK-10250: Reinstall VM from bypassed registered template URL: https://github.com/apache/cloudstack/pull/2423 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index dab741c3c27..a5bfc47584d 100644 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -313,6 +313,7 @@ import com.cloud.vm.snapshot.VMSnapshotVO; import com.cloud.vm.snapshot.dao.VMSnapshotDao; import com.cloud.storage.snapshot.SnapshotApiService; +import com.cloud.storage.VMTemplateStorageResourceAssoc; public class UserVmManagerImpl extends ManagerBase implements UserVmManager, VirtualMachineGuru, UserVmService, Configurable { private static final Logger s_logger = Logger.getLogger(UserVmManagerImpl.class); @@ -6100,10 +6101,8 @@ public UserVm restoreVMInternal(Account caller, UserVmVO vm, Long newTemplateId) throw ex; } } -TemplateDataStoreVO tmplStore = _templateStoreDao.findByTemplateZoneReady(template.getId(), vm.getDataCenterId()); -if (tmplStore == null) { -throw new InvalidParameterValueException("Cannot restore the vm as the template " + template.getUuid() + " isn't available in the zone"); -} + +checkRestoreVmFromTemplate(vm, template); if (needRestart) { try { @@ -6217,6 +6216,27 @@ public UserVm restoreVMInternal(Account caller, UserVmVO vm, Long newTemplateId) } +/** + * Perform basic checkings to make sure restore is possible. If not, #InvalidParameterValueException is thrown + * @param vm vm + * @param template template + * @throws InvalidParameterValueException if restore is not possible + */ +private void checkRestoreVmFromTemplate(UserVmVO vm, VMTemplateVO template) { +TemplateDataStoreVO tmplStore; +if (!template.isDirectDownload()) { +tmplStore = _templateStoreDao.findByTemplateZoneReady(template.getId(), vm.getDataCenterId()); +if (tmplStore == null) { +throw new InvalidParameterValueException("Cannot restore the vm as the template " + template.getUuid() + " isn't available in the zone"); +} +} else { +tmplStore = _templateStoreDao.findByTemplate(template.getId(), DataStoreRole.Image); +if (tmplStore == null || (tmplStore != null && !tmplStore.getDownloadState().equals(VMTemplateStorageResourceAssoc.Status.BYPASSED))) { +throw new InvalidParameterValueException("Cannot restore the vm as the bypassed template " + template.getUuid() + " isn't available in the zone"); +} +} +} + private void handleManagedStorage(UserVmVO vm, VolumeVO root) { if (Volume.State.Allocated.equals(root.getState())) { return; This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services