This is an automated email from the ASF dual-hosted git repository.

harikrishna pushed a commit to branch 4.20
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/4.20 by this push:
     new ff0cfc9148a Add ability to filter by version for listHosts and 
listMgmtServers APIs (#12472)
ff0cfc9148a is described below

commit ff0cfc9148a63d340133beb451afaa4699097f43
Author: Nicolas Vazquez <[email protected]>
AuthorDate: Tue Jan 27 04:15:46 2026 -0300

    Add ability to filter by version for listHosts and listMgmtServers APIs 
(#12472)
    
    * Add ability to filter by version for listHosts and listMgmtServers APIs
    
    * Address review comment
    
    * Fix listMgmtServers API
---
 .../cloudstack/api/command/admin/host/ListHostsCmd.java  |  7 +++++++
 .../api/command/admin/management/ListMgmtsCmd.java       |  8 ++++++++
 .../main/java/com/cloud/api/query/QueryManagerImpl.java  | 16 ++++++++++++++++
 3 files changed, 31 insertions(+)

diff --git 
a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ListHostsCmd.java
 
b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ListHostsCmd.java
index a73a0d00ffb..972a9c8950c 100644
--- 
a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ListHostsCmd.java
+++ 
b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ListHostsCmd.java
@@ -109,6 +109,9 @@ public class ListHostsCmd extends BaseListCmd {
     @Parameter(name = ApiConstants.ARCH, type = CommandType.STRING, 
description = "CPU Arch of the host", since = "4.20.1")
     private String arch;
 
+    @Parameter(name = ApiConstants.VERSION, type = CommandType.STRING, 
description = "the host version", since = "4.20.3")
+    private String version;
+
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
@@ -197,6 +200,10 @@ public class ListHostsCmd extends BaseListCmd {
         return StringUtils.isBlank(arch) ? null : CPU.CPUArch.fromType(arch);
     }
 
+    public String getVersion() {
+        return version;
+    }
+
     /////////////////////////////////////////////////////
     /////////////// API Implementation///////////////////
     /////////////////////////////////////////////////////
diff --git 
a/api/src/main/java/org/apache/cloudstack/api/command/admin/management/ListMgmtsCmd.java
 
b/api/src/main/java/org/apache/cloudstack/api/command/admin/management/ListMgmtsCmd.java
index ecc59f7cab8..293cb34e702 100644
--- 
a/api/src/main/java/org/apache/cloudstack/api/command/admin/management/ListMgmtsCmd.java
+++ 
b/api/src/main/java/org/apache/cloudstack/api/command/admin/management/ListMgmtsCmd.java
@@ -45,6 +45,10 @@ public class ListMgmtsCmd extends BaseListCmd {
             since = "4.20.1.0")
     private Boolean peers;
 
+    @Parameter(name = ApiConstants.VERSION, type = CommandType.STRING,
+            description = "the version of the management server", since = 
"4.20.3")
+    private String version;
+
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
@@ -61,6 +65,10 @@ public class ListMgmtsCmd extends BaseListCmd {
         return BooleanUtils.toBooleanDefaultIfNull(peers, false);
     }
 
+    public String getVersion() {
+        return version;
+    }
+
     /////////////////////////////////////////////////////
     /////////////// API Implementation///////////////////
     /////////////////////////////////////////////////////
diff --git a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java 
b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
index 5833ede550e..a89a1eed87b 100644
--- a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
+++ b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
@@ -2309,6 +2309,7 @@ public class QueryManagerImpl extends 
MutualExclusiveIdsManagerBase implements Q
         Long pageSize = cmd.getPageSizeVal();
         Hypervisor.HypervisorType hypervisorType = cmd.getHypervisor();
         final CPU.CPUArch arch = cmd.getArch();
+        String version = cmd.getVersion();
 
         Filter searchFilter = new Filter(HostVO.class, "id", Boolean.TRUE, 
startIndex, pageSize);
 
@@ -2325,11 +2326,13 @@ public class QueryManagerImpl extends 
MutualExclusiveIdsManagerBase implements Q
         hostSearchBuilder.and("resourceState", 
hostSearchBuilder.entity().getResourceState(), SearchCriteria.Op.EQ);
         hostSearchBuilder.and("hypervisor_type", 
hostSearchBuilder.entity().getHypervisorType(), SearchCriteria.Op.EQ);
         hostSearchBuilder.and("arch", hostSearchBuilder.entity().getArch(), 
SearchCriteria.Op.EQ);
+        hostSearchBuilder.and("version", 
hostSearchBuilder.entity().getVersion(), SearchCriteria.Op.EQ);
 
         if (keyword != null) {
             hostSearchBuilder.and().op("keywordName", 
hostSearchBuilder.entity().getName(), SearchCriteria.Op.LIKE);
             hostSearchBuilder.or("keywordStatus", 
hostSearchBuilder.entity().getStatus(), SearchCriteria.Op.LIKE);
             hostSearchBuilder.or("keywordType", 
hostSearchBuilder.entity().getType(), SearchCriteria.Op.LIKE);
+            hostSearchBuilder.or("keywordVersion", 
hostSearchBuilder.entity().getVersion(), SearchCriteria.Op.LIKE);
             hostSearchBuilder.cp();
         }
 
@@ -2360,6 +2363,7 @@ public class QueryManagerImpl extends 
MutualExclusiveIdsManagerBase implements Q
             sc.setParameters("keywordName", "%" + keyword + "%");
             sc.setParameters("keywordStatus", "%" + keyword + "%");
             sc.setParameters("keywordType", "%" + keyword + "%");
+            sc.setParameters("keywordVersion", "%" + keyword + "%");
         }
 
         if (id != null) {
@@ -2409,6 +2413,10 @@ public class QueryManagerImpl extends 
MutualExclusiveIdsManagerBase implements Q
             sc.setParameters("arch", arch);
         }
 
+        if (version != null) {
+            sc.setParameters("version", version);
+        }
+
         Pair<List<HostVO>, Integer> uniqueHostPair = 
hostDao.searchAndCount(sc, searchFilter);
         Integer count = uniqueHostPair.second();
         List<Long> hostIds = 
uniqueHostPair.first().stream().map(HostVO::getId).collect(Collectors.toList());
@@ -5397,6 +5405,8 @@ public class QueryManagerImpl extends 
MutualExclusiveIdsManagerBase implements Q
     protected Pair<List<ManagementServerJoinVO>, Integer> 
listManagementServersInternal(ListMgmtsCmd cmd) {
         Long id = cmd.getId();
         String name = cmd.getHostName();
+        String version = cmd.getVersion();
+        String keyword = cmd.getKeyword();
 
         SearchBuilder<ManagementServerJoinVO> sb = 
managementServerJoinDao.createSearchBuilder();
         SearchCriteria<ManagementServerJoinVO> sc = sb.create();
@@ -5406,6 +5416,12 @@ public class QueryManagerImpl extends 
MutualExclusiveIdsManagerBase implements Q
         if (name != null) {
             sc.addAnd("name", SearchCriteria.Op.EQ, name);
         }
+        if (version != null) {
+            sc.addAnd("version", SearchCriteria.Op.EQ, version);
+        }
+        if (keyword != null) {
+            sc.addAnd("version", SearchCriteria.Op.LIKE, "%" + keyword + "%");
+        }
         return managementServerJoinDao.searchAndCount(sc, null);
     }
 

Reply via email to