Skip to content

Commit a286dec

Browse files
Harikrishna Patnalakoushik-das
authored andcommitted
CLOUDSTACK-4908: CPU socket count of host Adding cpu socket count of the host in hostresponse
Signed-off-by: Koushik Das <koushik@apache.org>
1 parent 3a91500 commit a286dec

18 files changed

Lines changed: 170 additions & 3 deletions

File tree

api/src/com/cloud/host/Host.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ public static String[] toStrings(Host.Type... types) {
106106
*/
107107
Long getTotalMemory();
108108

109+
/**
110+
* @return # of cpu sockets in a machine.
111+
*/
112+
Integer getCpuSockets();
113+
109114
/**
110115
* @return # of cores in a machine. Note two cpus with two cores each returns 4.
111116
*/

api/src/org/apache/cloudstack/api/command/admin/host/ListHostsCmd.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.List;
2222
import java.util.Map;
2323

24+
import com.cloud.hypervisor.Hypervisor.HypervisorType;
2425
import org.apache.cloudstack.api.APICommand;
2526
import org.apache.cloudstack.api.ApiCommandJobType;
2627
import org.apache.cloudstack.api.ApiConstants;
@@ -88,6 +89,9 @@ public class ListHostsCmd extends BaseListCmd {
8889
@Parameter(name=ApiConstants.HA_HOST, type=CommandType.BOOLEAN, description="if true, list only hosts dedicated to HA")
8990
private Boolean haHost;
9091

92+
@Parameter(name=ApiConstants.HYPERVISOR, type=CommandType.STRING, description="hypervisor type of host: XenServer,KVM,VMware,Hyperv,BareMetal,Simulator")
93+
private String hypervisor;
94+
9195
/////////////////////////////////////////////////////
9296
/////////////////// Accessors ///////////////////////
9397
/////////////////////////////////////////////////////
@@ -128,6 +132,10 @@ public Long getVirtualMachineId() {
128132
return virtualMachineId;
129133
}
130134

135+
public HypervisorType getHypervisor() {
136+
return HypervisorType.getType(hypervisor);
137+
}
138+
131139
public EnumSet<HostDetails> getDetails() throws InvalidParameterValueException {
132140
EnumSet<HostDetails> dv;
133141
if (viewDetails==null || viewDetails.size() <=0){

api/src/org/apache/cloudstack/api/response/HostResponse.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ public class HostResponse extends BaseResponse {
7272
@SerializedName(ApiConstants.HYPERVISOR) @Param(description="the host hypervisor")
7373
private HypervisorType hypervisor;
7474

75+
@SerializedName("cpusockets") @Param(description="the number of CPU sockets on the host")
76+
private Integer cpuSockets;
77+
7578
@SerializedName("cpunumber") @Param(description="the CPU number of the host")
7679
private Integer cpuNumber;
7780

@@ -225,6 +228,10 @@ public void setHypervisor(HypervisorType hypervisor) {
225228
this.hypervisor = hypervisor;
226229
}
227230

231+
public void setCpuSockets(Integer cpuSockets) {
232+
this.cpuSockets = cpuSockets;
233+
}
234+
228235
public void setCpuNumber(Integer cpuNumber) {
229236
this.cpuNumber = cpuNumber;
230237
}

core/src/com/cloud/agent/api/StartupRoutingCommand.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public String getHost() {
4242
return host;
4343
}
4444
}
45+
Integer cpuSockets;
4546
int cpus;
4647
long speed;
4748
long memory;
@@ -133,6 +134,10 @@ public void setClusterVMStateChanges(HashMap<String, Ternary<String, State, Stri
133134
_clusterVMStates = allStates;
134135
}
135136

137+
public Integer getCpuSockets() {
138+
return cpuSockets;
139+
}
140+
136141
public int getCpus() {
137142
return cpus;
138143
}
@@ -165,6 +170,10 @@ public void setSpeed(long speed) {
165170
this.speed = speed;
166171
}
167172

173+
public void setCpuSockets(Integer cpuSockets) {
174+
this.cpuSockets = cpuSockets;
175+
}
176+
168177
public void setCpus(int cpus) {
169178
this.cpus = cpus;
170179
}

core/test/org/apache/cloudstack/api/agent/test/CheckOnHostCommandTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ public String getGuid() {
8686

8787
public Long getTotalMemory() {
8888
return 100000000000L;
89+
}
90+
91+
public Integer getCpuSockets() {
92+
return 1;
8993
};
9094

9195
public Integer getCpus() {
@@ -289,6 +293,12 @@ public void testGetTotalMemory() {
289293
assertTrue(m == 100000000000L);
290294
}
291295

296+
@Test
297+
public void testGetCpuSockets() {
298+
Integer cpuSockets = host.getCpuSockets();
299+
assertTrue(cpuSockets == 1);
300+
}
301+
292302
@Test
293303
public void testGetCpus() {
294304
int cpus = host.getCpus();

engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/EngineHostVO.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,9 @@ public void setHostTags(List<String> hostTags) {
325325
@Column(name="pod_id")
326326
private Long podId;
327327

328+
@Column(name="cpu_sockets")
329+
private Integer cpuSockets;
330+
328331
@Column(name="cpus")
329332
private Integer cpus;
330333

@@ -648,6 +651,11 @@ public void setGuid(String guid) {
648651
this.guid = guid;
649652
}
650653

654+
@Override
655+
public Integer getCpuSockets() {
656+
return cpuSockets;
657+
}
658+
651659
@Override
652660
public Integer getCpus() {
653661
return cpus;

engine/schema/src/com/cloud/host/HostVO.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,9 @@ public void setHostTags(List<String> hostTags) {
321321
@Column(name="pod_id")
322322
private Long podId;
323323

324+
@Column(name="cpu_sockets")
325+
private Integer cpuSockets;
326+
324327
@Column(name="cpus")
325328
private Integer cpus;
326329

@@ -501,6 +504,10 @@ public void setPrivateIpAddress(String ipAddress) {
501504
this.privateIpAddress = ipAddress;
502505
}
503506

507+
public void setCpuSockets(Integer cpuSockets) {
508+
this.cpuSockets = cpuSockets;
509+
}
510+
504511
public void setCpus(Integer cpus) {
505512
this.cpus = cpus;
506513
}
@@ -621,6 +628,11 @@ public void setGuid(String guid) {
621628
this.guid = guid;
622629
}
623630

631+
@Override
632+
public Integer getCpuSockets() {
633+
return cpuSockets;
634+
}
635+
624636
@Override
625637
public Integer getCpus() {
626638
return cpus;

plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3986,6 +3986,7 @@ public StartupCommand[] initialize() {
39863986
(Long) info.get(4), (String) info.get(3), _hypervisorType,
39873987
RouterPrivateIpStrategy.HostLocal);
39883988
cmd.setStateChanges(changes);
3989+
cmd.setCpuSockets((Integer)info.get(5));
39893990
fillNetworkInformation(cmd);
39903991
_privateIp = cmd.getPrivateIpAddress();
39913992
cmd.getHostDetails().putAll(getVersionStrings());
@@ -4311,6 +4312,7 @@ protected List<Object> getHostInfo() {
43114312
long speed = 0;
43124313
long cpus = 0;
43134314
long ram = 0;
4315+
int cpuSockets = 0;
43144316
String cap = null;
43154317
try {
43164318
Connect conn = LibvirtConnection.getConnection();
@@ -4334,6 +4336,7 @@ protected List<Object> getHostInfo() {
43344336
speed = hosts.mhz;
43354337
}
43364338

4339+
cpuSockets = hosts.sockets;
43374340
cpus = hosts.cpus;
43384341
ram = hosts.memory * 1024L;
43394342
LibvirtCapXMLParser parser = new LibvirtCapXMLParser();
@@ -4366,8 +4369,9 @@ protected List<Object> getHostInfo() {
43664369
// 768M
43674370
dom0ram = Math.max(dom0ram, _dom0MinMem);
43684371
info.add(dom0ram);
4372+
info.add(cpuSockets);
43694373
s_logger.debug("cpus=" + cpus + ", speed=" + speed + ", ram=" + ram
4370-
+ ", dom0ram=" + dom0ram);
4374+
+ ", dom0ram=" + dom0ram + ", cpu sockets=" + cpuSockets);
43714375

43724376
return info;
43734377
}

plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6040,6 +6040,7 @@ private void fillHostHardwareInfo(VmwareContext serviceContext, StartupRoutingCo
60406040
cmd.setCaps("hvm");
60416041
cmd.setDom0MinMemory(0);
60426042
cmd.setSpeed(summary.getCpuSpeed());
6043+
cmd.setCpuSockets(summary.getCpuSockets());
60436044
cmd.setCpus((int) summary.getCpuCount());
60446045
cmd.setMemory(summary.getMemoryBytes());
60456046
}

plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4829,7 +4829,10 @@ protected boolean getHostInfo(Connection conn) throws IllegalArgumentException{
48294829
if (_host.cpus <= 0) {
48304830
throw new CloudRuntimeException("Cannot get the numbers of cpu from XenServer host " + _host.ip);
48314831
}
4832-
4832+
Map<String, String> cpuInfo = myself.getCpuInfo(conn);
4833+
if (cpuInfo.get("socket_count") != null) {
4834+
_host.cpuSockets = Integer.parseInt(cpuInfo.get("socket_count"));
4835+
}
48334836
for (final HostCpu hc : hcs) {
48344837
_host.speed = hc.getSpeed(conn).intValue();
48354838
break;
@@ -5974,6 +5977,7 @@ protected void fillHostInfo(Connection conn, StartupRoutingCommand cmd) {
59745977
cmd.setCaps(caps.toString());
59755978

59765979
cmd.setSpeed(_host.speed);
5980+
cmd.setCpuSockets(_host.cpuSockets);
59775981
cmd.setCpus(_host.cpus);
59785982

59795983
HostMetrics hm = host.getMetrics(conn);
@@ -8074,6 +8078,7 @@ protected class XsHost {
80748078
public String storagePif2;
80758079
public String pool;
80768080
public int speed;
8081+
public Integer cpuSockets;
80778082
public int cpus;
80788083
public String product_version;
80798084
public String localSRuuid;

0 commit comments

Comments
 (0)