diff --git a/server/src/com/cloud/api/query/QueryManagerImpl.java b/server/src/com/cloud/api/query/QueryManagerImpl.java index 462a2761b31..efd2023d3dc 100644 --- a/server/src/com/cloud/api/query/QueryManagerImpl.java +++ b/server/src/com/cloud/api/query/QueryManagerImpl.java @@ -2875,17 +2875,6 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { sc.addAnd("state", SearchCriteria.Op.SC, readySc); } - if (zoneId != null) { - SearchCriteria zoneSc = _templateJoinDao.createSearchCriteria(); - zoneSc.addOr("dataCenterId", SearchCriteria.Op.EQ, zoneId); - zoneSc.addOr("dataStoreScope", SearchCriteria.Op.EQ, ScopeType.REGION); - // handle the case where xs-tools.iso and vmware-tools.iso do not have data_center information in template_view - SearchCriteria isoPerhostSc = _templateJoinDao.createSearchCriteria(); - isoPerhostSc.addAnd("format", SearchCriteria.Op.EQ, ImageFormat.ISO); - isoPerhostSc.addAnd("templateType", SearchCriteria.Op.EQ, TemplateType.PERHOST); - zoneSc.addOr("templateType", SearchCriteria.Op.SC, isoPerhostSc); - sc.addAnd("dataCenterId", SearchCriteria.Op.SC, zoneSc); - } if (!showDomr) { // excluding system template @@ -2893,6 +2882,19 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { } } + if (zoneId != null) { + SearchCriteria zoneSc = _templateJoinDao.createSearchCriteria(); + zoneSc.addOr("dataCenterId", SearchCriteria.Op.EQ, zoneId); + zoneSc.addOr("dataStoreScope", SearchCriteria.Op.EQ, ScopeType.REGION); + // handle the case where xs-tools.iso and vmware-tools.iso do not + // have data_center information in template_view + SearchCriteria isoPerhostSc = _templateJoinDao.createSearchCriteria(); + isoPerhostSc.addAnd("format", SearchCriteria.Op.EQ, ImageFormat.ISO); + isoPerhostSc.addAnd("templateType", SearchCriteria.Op.EQ, TemplateType.PERHOST); + zoneSc.addOr("templateType", SearchCriteria.Op.SC, isoPerhostSc); + sc.addAnd("dataCenterId", SearchCriteria.Op.SC, zoneSc); + } + // don't return removed template, this should not be needed since we // changed annotation for removed field in TemplateJoinVO. // sc.addAnd("removed", SearchCriteria.Op.NULL);