Skip to content

Commit afcbbc4

Browse files
systemvm: list systemvm does not return agent state and version (apache#3870)
This makes the listSystemVms API to return the host status (agent state), version and last pinged information. This makes it possible for UIs to call a single API to get this information.
1 parent cd55674 commit afcbbc4

File tree

3 files changed

+51
-31
lines changed

3 files changed

+51
-31
lines changed

api/src/main/java/org/apache/cloudstack/api/response/SystemVmResponse.java

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
import java.util.Date;
2020
import java.util.List;
2121

22-
import com.google.gson.annotations.SerializedName;
23-
2422
import org.apache.cloudstack.api.ApiConstants;
2523
import org.apache.cloudstack.api.BaseResponse;
2624
import org.apache.cloudstack.api.EntityReference;
2725

26+
import com.cloud.host.Status;
2827
import com.cloud.serializer.Param;
2928
import com.cloud.vm.VirtualMachine;
29+
import com.google.gson.annotations.SerializedName;
3030

3131
@EntityReference(value = VirtualMachine.class)
3232
public class SystemVmResponse extends BaseResponse {
@@ -138,6 +138,10 @@ public class SystemVmResponse extends BaseResponse {
138138
@Param(description = "the state of the system VM")
139139
private String state;
140140

141+
@SerializedName("agentstate")
142+
@Param(description = "the agent state of the system VM", since = "4.13.1")
143+
private String agentState;
144+
141145
@SerializedName("activeviewersessions")
142146
@Param(description = "the number of active console sessions for the console proxy system vm")
143147
private Integer activeViewerSessions;
@@ -150,6 +154,14 @@ public class SystemVmResponse extends BaseResponse {
150154
@Param(description = "public vlan range")
151155
private List<String> publicVlan;
152156

157+
@SerializedName("lastpinged")
158+
@Param(description = "the date and time the host was last pinged", since = "4.13.1")
159+
private Date lastPinged;
160+
161+
@SerializedName("version")
162+
@Param(description = "the systemvm agent version", since = "4.13.1")
163+
private String version;
164+
153165
@Override
154166
public String getObjectId() {
155167
return this.getId();
@@ -331,6 +343,18 @@ public void setState(String state) {
331343
this.state = state;
332344
}
333345

346+
public String getAgentState() {
347+
return agentState;
348+
}
349+
350+
public void setAgentState(Status agentState) {
351+
if (agentState != null) {
352+
this.agentState = agentState.toString();
353+
} else {
354+
this.agentState = Status.Unknown.toString();
355+
}
356+
}
357+
334358
public Integer getActiveViewerSessions() {
335359
return activeViewerSessions;
336360
}
@@ -378,4 +402,20 @@ public List<String> getPublicVlan() {
378402
public void setPublicVlan(List<String> publicVlan) {
379403
this.publicVlan = publicVlan;
380404
}
405+
406+
public Date getLastPinged() {
407+
return lastPinged;
408+
}
409+
410+
public void setLastPinged(Date lastPinged) {
411+
this.lastPinged = lastPinged;
412+
}
413+
414+
public String getVersion() {
415+
return version;
416+
}
417+
418+
public void setVersion(String version) {
419+
this.version = version;
420+
}
381421
}

server/src/main/java/com/cloud/api/ApiResponseHelper.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131

3232
import javax.inject.Inject;
3333

34-
import com.cloud.vm.snapshot.VMSnapshotVO;
35-
import com.cloud.vm.snapshot.dao.VMSnapshotDao;
3634
import org.apache.cloudstack.acl.ControlledEntity;
3735
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
3836
import org.apache.cloudstack.affinity.AffinityGroup;
@@ -336,6 +334,8 @@
336334
import com.cloud.vm.dao.NicExtraDhcpOptionDao;
337335
import com.cloud.vm.dao.NicSecondaryIpVO;
338336
import com.cloud.vm.snapshot.VMSnapshot;
337+
import com.cloud.vm.snapshot.VMSnapshotVO;
338+
import com.cloud.vm.snapshot.dao.VMSnapshotDao;
339339

340340
public class ApiResponseHelper implements ResponseGenerator {
341341

@@ -1375,6 +1375,9 @@ public SystemVmResponse createSystemVmResponse(VirtualMachine vm) {
13751375
vmResponse.setHostId(host.getUuid());
13761376
vmResponse.setHostName(host.getName());
13771377
vmResponse.setHypervisor(host.getHypervisorType().toString());
1378+
vmResponse.setAgentState(host.getStatus());
1379+
vmResponse.setLastPinged(new Date(host.getLastPinged()));
1380+
vmResponse.setVersion(host.getVersion());
13781381
}
13791382
}
13801383

ui/scripts/system.js

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9368,7 +9368,7 @@
93689368
url: createURL('listSystemVms'),
93699369
data: data,
93709370
success: function (json) {
9371-
var systemvmObjs = json.listsystemvmsresponse.systemvm;
9371+
var systemvmObjs = json.listsystemvmsresponse.systemvm || [];
93729372
$(systemvmObjs).each(function(idx, item) {
93739373
var controlIp = item.linklocalip;
93749374
if (item.hypervisor == "VMware") {
@@ -9377,32 +9377,9 @@
93779377
item.controlip = controlIp;
93789378
});
93799379

9380-
if (systemvmObjs != undefined) {
9381-
$.ajax({
9382-
url: createURL('listHosts'),
9383-
data: {
9384-
details: 'min'
9385-
},
9386-
success: function (json) {
9387-
var hostObjs = json.listhostsresponse.host;
9388-
for (var i = 0; i < systemvmObjs.length; i++) {
9389-
for (var k = 0; k < hostObjs.length; k++) {
9390-
if (hostObjs[k].name == systemvmObjs[i].name) {
9391-
systemvmObjs[i].agentstate = hostObjs[k].state;
9392-
break;
9393-
}
9394-
}
9395-
}
9396-
args.response.success({
9397-
data: systemvmObjs
9398-
});
9399-
}
9400-
});
9401-
} else {
9402-
args.response.success({
9403-
data:[]
9404-
});
9405-
}
9380+
args.response.success({
9381+
data: systemvmObjs
9382+
});
94069383
}
94079384
});
94089385
},

0 commit comments

Comments
 (0)