@@ -5028,35 +5028,29 @@ public UserVm restoreVMInternal(Account caller, UserVmVO vm, Long newTemplateId)
50285028 throw ex ;
50295029 }
50305030
5031- VolumeVO root = rootVols .get (0 );
5032- if ( !Volume .State .Allocated .equals (root .getState ()) || newTemplateId != null ){
5033- Long templateId = root .getTemplateId ();
5034- boolean isISO = false ;
5035- if (templateId == null ) {
5036- // Assuming that for a vm deployed using ISO, template ID is set to NULL
5037- isISO = true ;
5038- templateId = vm .getIsoId ();
5039- }
5031+ // If target VM has associated VM snapshots then don't allow restore of VM
5032+ List <VMSnapshotVO > vmSnapshots = _vmSnapshotDao .findByVm (vmId );
5033+ if (vmSnapshots .size () > 0 ) {
5034+ throw new InvalidParameterValueException ("Unable to restore VM, please remove VM snapshots before restoring VM" );
5035+ }
50405036
5041- // If target VM has associated VM snapshots then don't allow restore of VM
5042- List <VMSnapshotVO > vmSnapshots = _vmSnapshotDao .findByVm (vmId );
5043- if (vmSnapshots .size () > 0 ) {
5044- throw new InvalidParameterValueException ("Unable to restore VM, please remove VM snapshots before restoring VM" );
5045- }
5037+ VolumeVO root = rootVols .get (0 );
5038+ Long templateId = root .getTemplateId ();
5039+ boolean isISO = false ;
5040+ if (templateId == null ) {
5041+ // Assuming that for a vm deployed using ISO, template ID is set to NULL
5042+ isISO = true ;
5043+ templateId = vm .getIsoId ();
5044+ }
50465045
5047- VMTemplateVO template = null ;
5048- //newTemplateId can be either template or ISO id. In the following snippet based on the vm deployment (from template or ISO) it is handled accordingly
5049- if (newTemplateId != null ) {
5050- template = _templateDao .findById (newTemplateId );
5051- _accountMgr .checkAccess (caller , null , true , template );
5052- if (isISO ) {
5053- if (!template .getFormat ().equals (ImageFormat .ISO )) {
5054- throw new InvalidParameterValueException ("Invalid ISO id provided to restore the VM " );
5055- }
5056- } else {
5057- if (template .getFormat ().equals (ImageFormat .ISO )) {
5058- throw new InvalidParameterValueException ("Invalid template id provided to restore the VM " );
5059- }
5046+ VMTemplateVO template = null ;
5047+ //newTemplateId can be either template or ISO id. In the following snippet based on the vm deployment (from template or ISO) it is handled accordingly
5048+ if (newTemplateId != null ) {
5049+ template = _templateDao .findById (newTemplateId );
5050+ _accountMgr .checkAccess (caller , null , true , template );
5051+ if (isISO ) {
5052+ if (!template .getFormat ().equals (ImageFormat .ISO )) {
5053+ throw new InvalidParameterValueException ("Invalid ISO id provided to restore the VM " );
50605054 }
50615055 } else {
50625056 if (template .getFormat ().equals (ImageFormat .ISO )) {
0 commit comments