[ 
https://issues.apache.org/jira/browse/CLOUDSTACK-10250?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16361373#comment-16361373
 ] 

ASF GitHub Bot commented on CLOUDSTACK-10250:
---------------------------------------------

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


> Reinstall VM from bypassed registered template
> ----------------------------------------------
>
>                 Key: CLOUDSTACK-10250
>                 URL: https://issues.apache.org/jira/browse/CLOUDSTACK-10250
>             Project: CloudStack
>          Issue Type: Bug
>      Security Level: Public(Anyone can view this level - this is the 
> default.) 
>    Affects Versions: 4.11.0.0
>            Reporter: Nicolas Vazquez
>            Assignee: Nicolas Vazquez
>            Priority: Major
>
> This fix allows users to restore a VM from a previously registered template 
> using the Direct Download option (only for KVM currently)
> NOTE: As Reinstall VM button prompts only featured templates, to be able to 
> restore a vm to a Direct Download template, it should be registered as 
> Featured



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to