diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreDaoImpl.java b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreDaoImpl.java index d7478293fa2..e6a0e06a8bb 100644 --- a/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreDaoImpl.java +++ b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreDaoImpl.java @@ -81,10 +81,13 @@ public class ImageStoreDaoImpl extends GenericDaoBase implem public List findByScope(ZoneScope scope) { SearchCriteria sc = createSearchCriteria(); sc.addAnd("role", SearchCriteria.Op.EQ, DataStoreRole.Image); - SearchCriteria scc = createSearchCriteria(); - scc.addOr("scope", SearchCriteria.Op.EQ, ScopeType.REGION); - scc.addOr("dcId", SearchCriteria.Op.EQ, scope.getScopeId()); - sc.addAnd("scope", SearchCriteria.Op.SC, scc); + if (scope.getScopeId() != null) { + SearchCriteria scc = createSearchCriteria(); + scc.addOr("scope", SearchCriteria.Op.EQ, ScopeType.REGION); + scc.addOr("dcId", SearchCriteria.Op.EQ, scope.getScopeId()); + sc.addAnd("scope", SearchCriteria.Op.SC, scc); + } + // we should return all image stores if cross-zone scope is passed (scopeId = null) return listBy(sc); }