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

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


The following commit(s) were added to refs/heads/4.22 by this push:
     new 135922fa63b listHosts: add 'core' details (#13444)
135922fa63b is described below

commit 135922fa63ba7d2708e0026ac5d06d0dfd212792
Author: Nicolas Vazquez <[email protected]>
AuthorDate: Fri Jul 3 09:18:10 2026 -0300

    listHosts: add 'core' details (#13444)
    
    * listHosts: add 'core' details
    
    * Include msid response and integrate core details into the base response 
method
    
    Co-authored-by: abennatan <[email protected]>
---
 .../org/apache/cloudstack/api/ApiConstants.java    |   2 +-
 .../cloudstack/api/response/HostResponse.java      |  12 ++
 .../com/cloud/api/query/dao/HostJoinDaoImpl.java   | 203 +++++++++++----------
 3 files changed, 124 insertions(+), 93 deletions(-)

diff --git a/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java 
b/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java
index 03b73834a94..a8ff00c40ff 100644
--- a/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java
+++ b/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java
@@ -1407,7 +1407,7 @@ public class ApiConstants {
     }
 
     public enum HostDetails {
-        all, capacity, events, stats, min;
+        all, capacity, core, events, stats, min;
     }
 
     public enum VMDetails {
diff --git 
a/api/src/main/java/org/apache/cloudstack/api/response/HostResponse.java 
b/api/src/main/java/org/apache/cloudstack/api/response/HostResponse.java
index 5d085d1bee0..324cc31177a 100644
--- a/api/src/main/java/org/apache/cloudstack/api/response/HostResponse.java
+++ b/api/src/main/java/org/apache/cloudstack/api/response/HostResponse.java
@@ -197,6 +197,10 @@ public class HostResponse extends 
BaseResponseWithAnnotations {
     @Param(description = "the virtual machine id for host type ConsoleProxy 
and SecondaryStorageVM", since = "4.21.0")
     private String virtualMachineId;
 
+    @SerializedName("msid")
+    @Param(description = "(only for details=core) the msid of the host's 
management server")
+    private Long msId;
+
     @SerializedName(ApiConstants.MANAGEMENT_SERVER_ID)
     @Param(description = "The management server ID of the host")
     private String managementServerId;
@@ -488,6 +492,14 @@ public class HostResponse extends 
BaseResponseWithAnnotations {
         this.virtualMachineId = virtualMachineId;
     }
 
+    public Long getMsId() {
+        return msId;
+    }
+
+    public void setMsId(Long msId) {
+        this.msId = msId;
+    }
+
     public void setManagementServerId(String managementServerId) {
         this.managementServerId = managementServerId;
     }
diff --git a/server/src/main/java/com/cloud/api/query/dao/HostJoinDaoImpl.java 
b/server/src/main/java/com/cloud/api/query/dao/HostJoinDaoImpl.java
index e7265a7e3b9..7e149020cb0 100644
--- a/server/src/main/java/com/cloud/api/query/dao/HostJoinDaoImpl.java
+++ b/server/src/main/java/com/cloud/api/query/dao/HostJoinDaoImpl.java
@@ -131,21 +131,16 @@ public class HostJoinDaoImpl extends 
GenericDaoBase<HostJoinVO, Long> implements
             hostResponse.setHypervisor(hypervisorType);
         }
         hostResponse.setHostType(host.getType());
-        if (host.getType().equals(Host.Type.ConsoleProxy) || 
host.getType().equals(Host.Type.SecondaryStorageVM)) {
+        if (!details.contains(HostDetails.core) && 
(host.getType().equals(Host.Type.ConsoleProxy) || 
host.getType().equals(Host.Type.SecondaryStorageVM))) {
             VMInstanceVO vm = 
virtualMachineDao.findVMByInstanceNameIncludingRemoved(host.getName());
             if (vm != null) {
                 hostResponse.setVirtualMachineId(vm.getUuid());
             }
         }
         hostResponse.setLastPinged(new Date(host.getLastPinged()));
-        Long mshostId = host.getManagementServerId();
-        if (mshostId != null) {
-            ManagementServerHostVO managementServer = 
managementServerHostDao.findByMsid(host.getManagementServerId());
-            if (managementServer != null) {
-                hostResponse.setManagementServerId(managementServer.getUuid());
-                
hostResponse.setManagementServerName(managementServer.getName());
-            }
-        }
+
+        setManagementServerResponse(hostResponse, host, details);
+
         hostResponse.setName(host.getName());
         hostResponse.setPodId(host.getPodUuid());
         hostResponse.setRemoved(host.getRemoved());
@@ -155,41 +150,44 @@ public class HostJoinDaoImpl extends 
GenericDaoBase<HostJoinVO, Long> implements
         hostResponse.setVersion(host.getVersion());
         hostResponse.setCreated(host.getCreated());
 
-        List<HostGpuGroupsVO> gpuGroups = 
ApiDBUtils.getGpuGroups(host.getId());
-        if (gpuGroups != null && !gpuGroups.isEmpty()) {
-            List<GpuResponse> gpus = new ArrayList<GpuResponse>();
-            long gpuRemaining = 0;
-            long gpuTotal = 0;
-            for (HostGpuGroupsVO entry : gpuGroups) {
-                GpuResponse gpuResponse = new GpuResponse();
-                gpuResponse.setGpuGroupName(entry.getGroupName());
-                List<VGPUTypesVO> vgpuTypes = 
ApiDBUtils.getVgpus(entry.getId());
-                if (vgpuTypes != null && !vgpuTypes.isEmpty()) {
-                    List<VgpuResponse> vgpus = new ArrayList<VgpuResponse>();
-                    for (VGPUTypesVO vgpuType : vgpuTypes) {
-                        VgpuResponse vgpuResponse = new VgpuResponse();
-                        vgpuResponse.setName(vgpuType.getVgpuType());
-                        vgpuResponse.setVideoRam(vgpuType.getVideoRam());
-                        vgpuResponse.setMaxHeads(vgpuType.getMaxHeads());
-                        
vgpuResponse.setMaxResolutionX(vgpuType.getMaxResolutionX());
-                        
vgpuResponse.setMaxResolutionY(vgpuType.getMaxResolutionY());
-                        
vgpuResponse.setMaxVgpuPerPgpu(vgpuType.getMaxVgpuPerPgpu());
-                        
vgpuResponse.setRemainingCapacity(vgpuType.getRemainingCapacity());
-                        vgpuResponse.setmaxCapacity(vgpuType.getMaxCapacity());
-                        vgpus.add(vgpuResponse);
-                        gpuRemaining += vgpuType.getRemainingCapacity();
-                        gpuTotal += vgpuType.getMaxCapacity();
+        if (!details.contains(HostDetails.core)) {
+            List<HostGpuGroupsVO> gpuGroups = 
ApiDBUtils.getGpuGroups(host.getId());
+            if (gpuGroups != null && !gpuGroups.isEmpty()) {
+                List<GpuResponse> gpus = new ArrayList<GpuResponse>();
+                long gpuRemaining = 0;
+                long gpuTotal = 0;
+                for (HostGpuGroupsVO entry : gpuGroups) {
+                    GpuResponse gpuResponse = new GpuResponse();
+                    gpuResponse.setGpuGroupName(entry.getGroupName());
+                    List<VGPUTypesVO> vgpuTypes = 
ApiDBUtils.getVgpus(entry.getId());
+                    if (vgpuTypes != null && !vgpuTypes.isEmpty()) {
+                        List<VgpuResponse> vgpus = new 
ArrayList<VgpuResponse>();
+                        for (VGPUTypesVO vgpuType : vgpuTypes) {
+                            VgpuResponse vgpuResponse = new VgpuResponse();
+                            vgpuResponse.setName(vgpuType.getVgpuType());
+                            vgpuResponse.setVideoRam(vgpuType.getVideoRam());
+                            vgpuResponse.setMaxHeads(vgpuType.getMaxHeads());
+                            
vgpuResponse.setMaxResolutionX(vgpuType.getMaxResolutionX());
+                            
vgpuResponse.setMaxResolutionY(vgpuType.getMaxResolutionY());
+                            
vgpuResponse.setMaxVgpuPerPgpu(vgpuType.getMaxVgpuPerPgpu());
+                            
vgpuResponse.setRemainingCapacity(vgpuType.getRemainingCapacity());
+                            
vgpuResponse.setmaxCapacity(vgpuType.getMaxCapacity());
+                            vgpus.add(vgpuResponse);
+                            gpuRemaining += vgpuType.getRemainingCapacity();
+                            gpuTotal += vgpuType.getMaxCapacity();
+                        }
+                        gpuResponse.setVgpu(vgpus);
                     }
-                    gpuResponse.setVgpu(vgpus);
+                    gpus.add(gpuResponse);
                 }
-                gpus.add(gpuResponse);
+                hostResponse.setGpuTotal(gpuTotal);
+                hostResponse.setGpuUsed(gpuTotal - gpuRemaining);
+                hostResponse.setGpuGroup(gpus);
             }
-            hostResponse.setGpuTotal(gpuTotal);
-            hostResponse.setGpuUsed(gpuTotal - gpuRemaining);
-            hostResponse.setGpuGroup(gpus);
         }
-        if (details.contains(HostDetails.all) || 
details.contains(HostDetails.capacity) || details.contains(HostDetails.stats) 
|| details.contains(HostDetails.events)) {
 
+        if (details.contains(HostDetails.all) || 
details.contains(HostDetails.capacity) || details.contains(HostDetails.core) ||
+                details.contains(HostDetails.stats) || 
details.contains(HostDetails.events)) {
             hostResponse.setOsCategoryId(host.getOsCategoryUuid());
             hostResponse.setOsCategoryName(host.getOsCategoryName());
             hostResponse.setZoneName(host.getZoneName());
@@ -202,43 +200,45 @@ public class HostJoinDaoImpl extends 
GenericDaoBase<HostJoinVO, Long> implements
 
         DecimalFormat decimalFormat = new DecimalFormat("#.##");
         if (host.getType() == Host.Type.Routing) {
-            float cpuOverprovisioningFactor = 
ApiDBUtils.getCpuOverprovisioningFactor(host.getClusterId());
-            if (details.contains(HostDetails.all) || 
details.contains(HostDetails.capacity)) {
-                // set allocated capacities
-                Long mem = host.getMemReservedCapacity() + 
host.getMemUsedCapacity();
-                Long cpu = host.getCpuReservedCapacity() + 
host.getCpuUsedCapacity();
-
-                Float memWithOverprovisioning = host.getTotalMemory() * 
ApiDBUtils.getMemOverprovisioningFactor(host.getClusterId());
-                
hostResponse.setMemoryTotal(memWithOverprovisioning.longValue());
-                
hostResponse.setMemWithOverprovisioning(decimalFormat.format(memWithOverprovisioning));
-                hostResponse.setMemoryAllocated(mem);
-                hostResponse.setMemoryAllocatedBytes(mem);
-                
hostResponse.setMemoryAllocatedPercentage(calculateResourceAllocatedPercentage(mem,
 memWithOverprovisioning));
-
+            if (details.contains(HostDetails.all) || 
details.contains(HostDetails.capacity) || details.contains(HostDetails.core)) {
                 String hostTags = host.getTag();
                 hostResponse.setHostTags(hostTags);
-                hostResponse.setIsTagARule(host.getIsTagARule());
-                hostResponse.setHaHost(containsHostHATag(hostTags));
                 hostResponse.setExplicitHostTags(host.getExplicitTag());
                 hostResponse.setImplicitHostTags(host.getImplicitTag());
-
-                hostResponse.setHypervisorVersion(host.getHypervisorVersion());
-                if (host.getArch() != null) {
-                    hostResponse.setArch(host.getArch().getType());
-                }
-
                 
hostResponse.setStorageAccessGroups(host.getStorageAccessGroups());
                 
hostResponse.setClusterStorageAccessGroups(host.getClusterStorageAccessGroups());
                 
hostResponse.setPodStorageAccessGroups(host.getPodStorageAccessGroups());
                 
hostResponse.setZoneStorageAccessGroups(host.getZoneStorageAccessGroups());
+                hostResponse.setHypervisorVersion(host.getHypervisorVersion());
+
+                if (!details.contains(HostDetails.core)) {
+                    float cpuOverprovisioningFactor = 
ApiDBUtils.getCpuOverprovisioningFactor(host.getClusterId());
+                    // set allocated capacities
+                    Long mem = host.getMemReservedCapacity() + 
host.getMemUsedCapacity();
+                    Long cpu = host.getCpuReservedCapacity() + 
host.getCpuUsedCapacity();
+
+                    Float memWithOverprovisioning = host.getTotalMemory() * 
ApiDBUtils.getMemOverprovisioningFactor(host.getClusterId());
+                    
hostResponse.setMemoryTotal(memWithOverprovisioning.longValue());
+                    
hostResponse.setMemWithOverprovisioning(decimalFormat.format(memWithOverprovisioning));
+                    hostResponse.setMemoryAllocated(mem);
+                    hostResponse.setMemoryAllocatedBytes(mem);
+                    
hostResponse.setMemoryAllocatedPercentage(calculateResourceAllocatedPercentage(mem,
 memWithOverprovisioning));
+
+                    hostResponse.setIsTagARule(host.getIsTagARule());
+                    hostResponse.setHaHost(containsHostHATag(hostTags));
 
-                float cpuWithOverprovisioning = host.getCpus() * 
host.getSpeed() * cpuOverprovisioningFactor;
-                hostResponse.setCpuAllocatedValue(cpu);
-                String cpuAllocated = 
calculateResourceAllocatedPercentage(cpu, cpuWithOverprovisioning);
-                hostResponse.setCpuAllocated(cpuAllocated);
-                hostResponse.setCpuAllocatedPercentage(cpuAllocated);
-                hostResponse.setCpuAllocatedWithOverprovisioning(cpuAllocated);
-                
hostResponse.setCpuWithOverprovisioning(decimalFormat.format(cpuWithOverprovisioning));
+                    if (host.getArch() != null) {
+                        hostResponse.setArch(host.getArch().getType());
+                    }
+
+                    float cpuWithOverprovisioning = host.getCpus() * 
host.getSpeed() * cpuOverprovisioningFactor;
+                    hostResponse.setCpuAllocatedValue(cpu);
+                    String cpuAllocated = 
calculateResourceAllocatedPercentage(cpu, cpuWithOverprovisioning);
+                    hostResponse.setCpuAllocated(cpuAllocated);
+                    hostResponse.setCpuAllocatedPercentage(cpuAllocated);
+                    
hostResponse.setCpuAllocatedWithOverprovisioning(cpuAllocated);
+                    
hostResponse.setCpuWithOverprovisioning(decimalFormat.format(cpuWithOverprovisioning));
+                }
             }
 
             if (details.contains(HostDetails.all) || 
details.contains(HostDetails.stats)) {
@@ -257,27 +257,29 @@ public class HostJoinDaoImpl extends 
GenericDaoBase<HostJoinVO, Long> implements
                 }
             }
 
-            Map<String, String> hostDetails = 
hostDetailsDao.findDetails(host.getId());
-            if (hostDetails != null) {
-                if (hostDetails.containsKey(Host.HOST_UEFI_ENABLE)) {
-                    
hostResponse.setUefiCapability(Boolean.parseBoolean((String) 
hostDetails.get(Host.HOST_UEFI_ENABLE)));
-                } else {
-                    hostResponse.setUefiCapability(new Boolean(false));
+            if (!details.contains(HostDetails.core)) {
+                Map<String, String> hostDetails = 
hostDetailsDao.findDetails(host.getId());
+                if (hostDetails != null) {
+                    if (hostDetails.containsKey(Host.HOST_UEFI_ENABLE)) {
+                        
hostResponse.setUefiCapability(Boolean.parseBoolean((String) 
hostDetails.get(Host.HOST_UEFI_ENABLE)));
+                    } else {
+                        hostResponse.setUefiCapability(new Boolean(false));
+                    }
                 }
-            }
-            if (details.contains(HostDetails.all) &&
-                    Arrays.asList(Hypervisor.HypervisorType.KVM,
-                            Hypervisor.HypervisorType.Custom,
-                            
Hypervisor.HypervisorType.External).contains(host.getHypervisorType())) {
-                //only kvm has the requirement to return host details
-                try {
-                    hostResponse.setDetails(hostDetails, 
host.getHypervisorType());
-                } catch (Exception e) {
-                    logger.debug("failed to get host details", e);
+                if (details.contains(HostDetails.all) &&
+                        Arrays.asList(Hypervisor.HypervisorType.KVM,
+                                Hypervisor.HypervisorType.Custom,
+                                
Hypervisor.HypervisorType.External).contains(host.getHypervisorType())) {
+                    //only kvm has the requirement to return host details
+                    try {
+                        hostResponse.setDetails(hostDetails, 
host.getHypervisorType());
+                    } catch (Exception e) {
+                        logger.debug("failed to get host details", e);
+                    }
                 }
             }
 
-        } else if (host.getType() == Host.Type.SecondaryStorage) {
+        } else if (host.getType() == Host.Type.SecondaryStorage && 
!details.contains(HostDetails.core)) {
             StorageStats secStorageStats = 
ApiDBUtils.getSecondaryStorageStatistics(host.getId());
             if (secStorageStats != null) {
                 
hostResponse.setDiskSizeTotal(secStorageStats.getCapacityBytes());
@@ -285,7 +287,16 @@ public class HostJoinDaoImpl extends 
GenericDaoBase<HostJoinVO, Long> implements
             }
         }
 
-        
hostResponse.setLocalStorageActive(ApiDBUtils.isLocalStorageActiveOnHost(host.getId()));
+        if (!details.contains(HostDetails.core)) {
+            
hostResponse.setLocalStorageActive(ApiDBUtils.isLocalStorageActiveOnHost(host.getId()));
+            
hostResponse.setHostHAResponse(haConfigDao.findHAResource(host.getId(), 
HAResource.ResourceType.Host));
+            
hostResponse.setOutOfBandManagementResponse(outOfBandManagementDao.findByHost(host.getId()));
+            
hostResponse.setHasAnnotation(annotationDao.hasAnnotations(host.getUuid(), 
AnnotationService.EntityType.HOST.name(),
+                    
accountManager.isRootAdmin(CallContext.current().getCallingAccount().getId())));
+            hostResponse.setAnnotation(host.getAnnotation());
+            hostResponse.setLastAnnotated(host.getLastAnnotated());
+            hostResponse.setUsername(host.getUsername());
+        }
 
         if (details.contains(HostDetails.all) || 
details.contains(HostDetails.events)) {
             Set<com.cloud.host.Status.Event> possibleEvents = 
host.getStatus().getPossibleEvents();
@@ -303,8 +314,6 @@ public class HostJoinDaoImpl extends 
GenericDaoBase<HostJoinVO, Long> implements
             }
         }
 
-        
hostResponse.setHostHAResponse(haConfigDao.findHAResource(host.getId(), 
HAResource.ResourceType.Host));
-        
hostResponse.setOutOfBandManagementResponse(outOfBandManagementDao.findByHost(host.getId()));
         hostResponse.setResourceState(host.getResourceState().toString());
 
         // set async job
@@ -312,15 +321,25 @@ public class HostJoinDaoImpl extends 
GenericDaoBase<HostJoinVO, Long> implements
             hostResponse.setJobId(host.getJobUuid());
             hostResponse.setJobStatus(host.getJobStatus());
         }
-        
hostResponse.setHasAnnotation(annotationDao.hasAnnotations(host.getUuid(), 
AnnotationService.EntityType.HOST.name(),
-                
accountManager.isRootAdmin(CallContext.current().getCallingAccount().getId())));
-        hostResponse.setAnnotation(host.getAnnotation());
-        hostResponse.setLastAnnotated(host.getLastAnnotated ());
-        hostResponse.setUsername(host.getUsername());
 
         hostResponse.setObjectName("host");
     }
 
+    private void setManagementServerResponse(HostResponse hostResponse, 
HostJoinVO host, EnumSet<HostDetails> details) {
+        if (host.getManagementServerId() != null) {
+            if (details.size() == 1 && details.contains(HostDetails.core)) {
+                // msid is returned as-is; callers resolve it to avoid a 
per-host lookup
+                hostResponse.setMsId(host.getManagementServerId());
+            } else {
+                ManagementServerHostVO managementServer = 
managementServerHostDao.findByMsid(host.getManagementServerId());
+                if (managementServer != null) {
+                    
hostResponse.setManagementServerId(managementServer.getUuid());
+                    
hostResponse.setManagementServerName(managementServer.getName());
+                }
+            }
+        }
+    }
+
     @Override
     public HostResponse newMinimalHostResponse(HostJoinVO host) {
         HostResponse hostResponse = new HostResponse();

Reply via email to