server: use host record related to a ssvm/cpvm (#3876)

This implements the systemvm list API response creator to find and use
the host record for a ssvm/cpvm to get the agent status and other
details like last disconnected date and agent version.

Fixes 3875

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
Rohit Yadav 2020-02-10 19:01:34 +05:30 committed by GitHub
parent afcbbc4b3e
commit 78cc0a44c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 10 deletions

View File

@ -154,9 +154,9 @@ public class SystemVmResponse extends BaseResponse {
@Param(description = "public vlan range")
private List<String> publicVlan;
@SerializedName("lastpinged")
@Param(description = "the date and time the host was last pinged", since = "4.13.1")
private Date lastPinged;
@SerializedName("disconnected")
@Param(description = "the last disconnected date of host", since = "4.13.1")
private Date disconnectedOn;
@SerializedName("version")
@Param(description = "the systemvm agent version", since = "4.13.1")
@ -403,12 +403,12 @@ public class SystemVmResponse extends BaseResponse {
this.publicVlan = publicVlan;
}
public Date getLastPinged() {
return lastPinged;
public Date getDisconnectedOn() {
return disconnectedOn;
}
public void setLastPinged(Date lastPinged) {
this.lastPinged = lastPinged;
public void setDisconnectedOn(Date disconnectedOn) {
this.disconnectedOn = disconnectedOn;
}
public String getVersion() {

View File

@ -1039,6 +1039,10 @@ public class ApiDBUtils {
return s_hostDao.findByIdIncludingRemoved(hostId);
}
public static HostVO findHostByTypeNameAndZoneId(Long zoneId, String name, Host.Type type) {
return s_hostDao.findByTypeNameAndZoneId(zoneId, name, type);
}
public static IPAddressVO findIpAddressById(long addressId) {
return s_ipAddressDao.findById(addressId);
}

View File

@ -1375,9 +1375,16 @@ public class ApiResponseHelper implements ResponseGenerator {
vmResponse.setHostId(host.getUuid());
vmResponse.setHostName(host.getName());
vmResponse.setHypervisor(host.getHypervisorType().toString());
vmResponse.setAgentState(host.getStatus());
vmResponse.setLastPinged(new Date(host.getLastPinged()));
vmResponse.setVersion(host.getVersion());
}
}
if (vm.getType() == Type.SecondaryStorageVm || vm.getType() == Type.ConsoleProxy) {
Host systemVmHost = ApiDBUtils.findHostByTypeNameAndZoneId(vm.getDataCenterId(), vm.getHostName(),
Type.SecondaryStorageVm.equals(vm.getType()) ? Host.Type.SecondaryStorageVM : Host.Type.ConsoleProxy);
if (systemVmHost != null) {
vmResponse.setAgentState(systemVmHost.getStatus());
vmResponse.setDisconnectedOn(systemVmHost.getDisconnectedOn());
vmResponse.setVersion(systemVmHost.getVersion());
}
}