From 787491871a9a1580b95003220965d0be885f11bf Mon Sep 17 00:00:00 2001 From: Rakesh Date: Thu, 25 Feb 2021 17:35:31 +0100 Subject: [PATCH] server: Look for active templates for VR deployment (#4047) If the template from which VR is created got deleted, the state is set to inactive and removed to null. Since the template is already deleted, the VR can't be created using this template again. If someone restarts network with cleanup then it will try to deploy the vr from the old non existing template again. So search only for active template which are not yet deleted. --- .../src/main/java/com/cloud/storage/dao/VMTemplateDaoImpl.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateDaoImpl.java b/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateDaoImpl.java index 6caef20b2d7..a3bebfa332f 100644 --- a/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateDaoImpl.java @@ -376,6 +376,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase implem tmpltTypeHyperSearch2.and("templateType", tmpltTypeHyperSearch2.entity().getTemplateType(), SearchCriteria.Op.EQ); tmpltTypeHyperSearch2.and("hypervisorType", tmpltTypeHyperSearch2.entity().getHypervisorType(), SearchCriteria.Op.EQ); tmpltTypeHyperSearch2.and("templateName", tmpltTypeHyperSearch2.entity().getName(), SearchCriteria.Op.EQ); + tmpltTypeHyperSearch2.and("state", tmpltTypeHyperSearch2.entity().getState(), SearchCriteria.Op.EQ); tmpltTypeSearch = createSearchBuilder(); tmpltTypeSearch.and("state", tmpltTypeSearch.entity().getState(), SearchCriteria.Op.EQ); @@ -897,6 +898,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase implem SearchCriteria sc = tmpltTypeHyperSearch2.create(); sc.setParameters("templateType", TemplateType.ROUTING); sc.setParameters("hypervisorType", hType); + sc.setParameters("state", VirtualMachineTemplate.State.Active.toString()); if (templateName != null) { sc.setParameters("templateName", templateName); } @@ -911,6 +913,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase implem sc = tmpltTypeHyperSearch2.create(); sc.setParameters("templateType", TemplateType.SYSTEM); sc.setParameters("hypervisorType", hType); + sc.setParameters("state", VirtualMachineTemplate.State.Active.toString()); if (templateName != null) { sc.setParameters("templateName", templateName); }