Skip to content

Commit 1db51ba

Browse files
committed
Add hypervisor type to response and fix VMs listing guest OS
1 parent 64c6a7b commit 1db51ba

8 files changed

Lines changed: 60 additions & 6 deletions

File tree

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,12 @@ public class UnmanagedInstanceResponse extends BaseResponse {
5151
@Param(description = "The name of the host to which Instance belongs")
5252
private String hostName;
5353

54+
@SerializedName(ApiConstants.HYPERVISOR)
55+
@Param(description = "The hypervisor to which Instance belongs")
56+
private String hypervisor;
57+
5458
@SerializedName(ApiConstants.HYPERVISOR_VERSION)
55-
@Param(description = "The version of the host to which Instance belongs")
59+
@Param(description = "The hypervisor version of the host to which Instance belongs")
5660
private String hypervisorVersion;
5761

5862
@SerializedName(ApiConstants.POWER_STATE)
@@ -144,6 +148,14 @@ public void setHostName(String hostName) {
144148
this.hostName = hostName;
145149
}
146150

151+
public String getHypervisor() {
152+
return hypervisor;
153+
}
154+
155+
public void setHypervisor(String hypervisor) {
156+
this.hypervisor = hypervisor;
157+
}
158+
147159
public String getHypervisorVersion() {
148160
return hypervisorVersion;
149161
}

api/src/main/java/org/apache/cloudstack/vm/UnmanagedInstanceTO.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public enum PowerState {
5555

5656
private String hostName;
5757

58+
private String hypervisorType;
5859
private String hostHypervisorVersion;
5960

6061
private List<Disk> disks;
@@ -170,6 +171,14 @@ public void setHostName(String hostName) {
170171
this.hostName = hostName;
171172
}
172173

174+
public String getHypervisorType() {
175+
return hypervisorType;
176+
}
177+
178+
public void setHypervisorType(String hypervisorType) {
179+
this.hypervisorType = hypervisorType;
180+
}
181+
173182
public String getHostHypervisorVersion() {
174183
return hostHypervisorVersion;
175184
}

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetRemoteVmsCommandWrapper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.cloud.agent.api.Answer;
2323
import com.cloud.agent.api.GetRemoteVmsAnswer;
2424
import com.cloud.agent.api.GetRemoteVmsCommand;
25+
import com.cloud.hypervisor.Hypervisor;
2526
import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource;
2627
import com.cloud.hypervisor.kvm.resource.LibvirtConnection;
2728
import com.cloud.hypervisor.kvm.resource.LibvirtDomainXMLParser;
@@ -97,6 +98,7 @@ private UnmanagedInstanceTO getUnmanagedInstance(LibvirtComputingResource libvir
9798
if (parser.getCpuTuneDef() !=null) {
9899
instance.setCpuSpeed(parser.getCpuTuneDef().getShares());
99100
}
101+
instance.setHypervisorType(Hypervisor.HypervisorType.KVM.name());
100102
instance.setPowerState(getPowerState(libvirtComputingResource.getVmState(conn,domain.getName())));
101103
instance.setNics(getUnmanagedInstanceNics(parser.getInterfaces()));
102104
instance.setDisks(getUnmanagedInstanceDisks(parser.getDisks(),libvirtComputingResource, domain));

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetUnmanagedInstancesCommandWrapper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import com.cloud.agent.api.GetUnmanagedInstancesAnswer;
2121
import com.cloud.agent.api.GetUnmanagedInstancesCommand;
22+
import com.cloud.hypervisor.Hypervisor;
2223
import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource;
2324
import com.cloud.hypervisor.kvm.resource.LibvirtDomainXMLParser;
2425
import com.cloud.hypervisor.kvm.resource.LibvirtVMDef;
@@ -130,6 +131,7 @@ private UnmanagedInstanceTO getUnmanagedInstance(LibvirtComputingResource libvir
130131
if (parser.getCpuModeDef() != null) {
131132
instance.setCpuCoresPerSocket(parser.getCpuModeDef().getCoresPerSocket());
132133
}
134+
instance.setHypervisorType(Hypervisor.HypervisorType.KVM.name());
133135
instance.setPowerState(getPowerState(libvirtComputingResource.getVmState(conn,domain.getName())));
134136
instance.setMemory((int) LibvirtComputingResource.getDomainMemory(domain) / 1024);
135137
instance.setNics(getUnmanagedInstanceNics(libvirtComputingResource, parser.getInterfaces()));

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5339,12 +5339,18 @@ public UnmanagedInstanceResponse createUnmanagedInstanceResponse(UnmanagedInstan
53395339
if (host != null) {
53405340
response.setHostId(host.getUuid());
53415341
response.setHostName(host.getName());
5342+
if (host.getHypervisorType() != null) {
5343+
response.setHypervisor(host.getHypervisorType().name());
5344+
}
53425345
response.setHypervisorVersion(host.getHypervisorVersion());
53435346
} else {
53445347
// In case the unmanaged instance is on an external host
53455348
if (instance.getHostName() != null) {
53465349
response.setHostName(instance.getHostName());
53475350
}
5351+
if (instance.getHypervisorType() != null) {
5352+
response.setHypervisor(instance.getHypervisorType());
5353+
}
53485354
if (instance.getHostHypervisorVersion() != null) {
53495355
response.setHypervisorVersion(instance.getHostHypervisorVersion());
53505356
}

server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,9 @@ private UnmanagedInstanceResponse createUnmanagedInstanceResponse(UnmanagedInsta
350350
if (host != null) {
351351
response.setHostId(host.getUuid());
352352
response.setHostName(host.getName());
353+
if (host.getHypervisorType() != null) {
354+
response.setHypervisor(host.getHypervisorType().toString());
355+
}
353356
response.setHypervisorVersion(host.getHypervisorVersion());
354357
} else {
355358
// In case the unmanaged instance is on an external host
@@ -359,6 +362,9 @@ private UnmanagedInstanceResponse createUnmanagedInstanceResponse(UnmanagedInsta
359362
if (instance.getHostHypervisorVersion() != null) {
360363
response.setHypervisorVersion(instance.getHostHypervisorVersion());
361364
}
365+
if (instance.getHypervisorType() != null) {
366+
response.setHypervisor(instance.getHypervisorType());
367+
}
362368
}
363369
response.setPowerState(instance.getPowerState().toString());
364370
response.setCpuCores(instance.getCpuCores());

vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/BaseMO.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717
package com.cloud.hypervisor.vmware.mo;
1818

19+
import com.cloud.hypervisor.Hypervisor;
1920
import org.apache.logging.log4j.Logger;
2021
import org.apache.logging.log4j.LogManager;
2122

@@ -45,9 +46,9 @@ public class BaseMO {
4546
protected VmwareContext _context;
4647
protected ManagedObjectReference _mor;
4748

48-
protected static String[] propertyPathsForUnmanagedVmsThinListing = new String[] {"name", "config.template",
49-
"runtime.powerState", "summary.guest.guestId", "summary.guest.guestFullName", "runtime.host",
50-
"config.bootOptions", "config.firmware"};
49+
protected static String[] propertyPathsForUnmanagedVmsThinListing = new String[] {"name", "config.template", "runtime.powerState",
50+
"config.guestId", "config.guestFullName", "summary.guest.guestId", "summary.guest.guestFullName",
51+
"runtime.host", "config.bootOptions", "config.firmware"};
5152

5253
private String _name;
5354

@@ -207,6 +208,11 @@ private UnmanagedInstanceTO createUnmanagedInstanceTOFromThinListingDynamicPrope
207208
boolean isTemplate = false;
208209
boolean excludeByKeyword = false;
209210

211+
String configGuestId = null;
212+
String configGuestFullName = null;
213+
String summaryGuestId = null;
214+
String summaryGuestFullName = null;
215+
210216
for (DynamicProperty objProp : objProps) {
211217
if (objProp.getName().equals("name")) {
212218
vmName = (String) objProp.getVal();
@@ -219,10 +225,14 @@ private UnmanagedInstanceTO createUnmanagedInstanceTOFromThinListingDynamicPrope
219225
} else if (objProp.getName().equals("runtime.powerState")) {
220226
VirtualMachinePowerState powerState = (VirtualMachinePowerState) objProp.getVal();
221227
vm.setPowerState(convertPowerState(powerState));
228+
} else if (objProp.getName().equals("config.guestFullName")) {
229+
configGuestFullName = (String) objProp.getVal();
230+
} else if (objProp.getName().equals("config.guestId")) {
231+
configGuestId = (String) objProp.getVal();
222232
} else if (objProp.getName().equals("summary.guest.guestFullName")) {
223-
vm.setOperatingSystem((String) objProp.getVal());
233+
summaryGuestFullName = (String) objProp.getVal();
224234
} else if (objProp.getName().equals("summary.guest.guestId")) {
225-
vm.setOperatingSystemId((String) objProp.getVal());
235+
summaryGuestId = (String) objProp.getVal();
226236
} else if (objProp.getName().equals("config.bootOptions")) {
227237
VirtualMachineBootOptions bootOptions = (VirtualMachineBootOptions) objProp.getVal();
228238
String bootMode = "LEGACY";
@@ -238,6 +248,11 @@ private UnmanagedInstanceTO createUnmanagedInstanceTOFromThinListingDynamicPrope
238248
setUnmanagedInstanceTOHostAndCluster(vm, hostMor, hostClusterNamesMap);
239249
}
240250
}
251+
252+
vm.setHypervisorType(Hypervisor.HypervisorType.VMware.name());
253+
vm.setOperatingSystem(StringUtils.isNotBlank(summaryGuestFullName) ? summaryGuestFullName : configGuestFullName);
254+
vm.setOperatingSystemId(StringUtils.isNotBlank(summaryGuestId) ? summaryGuestId : configGuestId);
255+
241256
if (isTemplate || excludeByKeyword) {
242257
return null;
243258
}

vmware-base/src/main/java/com/cloud/hypervisor/vmware/util/VmwareHelper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import javax.xml.datatype.XMLGregorianCalendar;
4242

4343
import com.cloud.agent.api.to.DiskTO;
44+
import com.cloud.hypervisor.Hypervisor;
4445
import com.cloud.hypervisor.vmware.mo.ClusterMO;
4546
import com.cloud.hypervisor.vmware.mo.DatastoreFile;
4647
import com.cloud.hypervisor.vmware.mo.DistributedVirtualSwitchMO;
@@ -833,6 +834,7 @@ public static UnmanagedInstanceTO getUnmanagedInstance(VmwareHypervisorHost hype
833834
}
834835

835836
instance.setHostName(hyperHost.getHyperHostName());
837+
instance.setHypervisorType(Hypervisor.HypervisorType.VMware.name());
836838
instance.setHostHypervisorVersion(getVmwareHostVersion(hyperHost));
837839

838840
if (StringUtils.isEmpty(instance.getOperatingSystemId()) && configSummary != null) {

0 commit comments

Comments
 (0)