use of org.apache.cloudstack.vm.UnmanagedInstanceTO in project cloudstack by apache.
the class VmwareResource method execute.
private Answer execute(GetUnmanagedInstancesCommand cmd) {
VmwareContext context = getServiceContext();
HashMap<String, UnmanagedInstanceTO> unmanagedInstances = new HashMap<>();
try {
VmwareHypervisorHost hyperHost = getHyperHost(context);
String vmName = cmd.getInstanceName();
List<VirtualMachineMO> vmMos = hyperHost.listVmsOnHyperHostWithHypervisorName(vmName);
for (VirtualMachineMO vmMo : vmMos) {
if (vmMo == null) {
continue;
}
if (vmMo.isTemplate()) {
continue;
}
// Filter managed instances
if (cmd.hasManagedInstance(vmMo.getName())) {
continue;
}
// Filter instance if answer is requested for a particular instance name
if (StringUtils.isNotEmpty(cmd.getInstanceName()) && !cmd.getInstanceName().equals(vmMo.getVmName())) {
continue;
}
UnmanagedInstanceTO instance = getUnmanagedInstance(hyperHost, vmMo);
if (instance != null) {
unmanagedInstances.put(instance.getName(), instance);
}
}
} catch (Exception e) {
s_logger.info("GetUnmanagedInstancesCommand failed due to " + VmwareHelper.getExceptionMessage(e));
}
return new GetUnmanagedInstancesAnswer(cmd, "", unmanagedInstances);
}
use of org.apache.cloudstack.vm.UnmanagedInstanceTO in project cloudstack by apache.
the class VmwareResource method getUnmanagedInstance.
private UnmanagedInstanceTO getUnmanagedInstance(VmwareHypervisorHost hyperHost, VirtualMachineMO vmMo) {
UnmanagedInstanceTO instance = null;
try {
instance = new UnmanagedInstanceTO();
instance.setName(vmMo.getVmName());
instance.setInternalCSName(vmMo.getInternalCSName());
instance.setCpuCores(vmMo.getConfigSummary().getNumCpu());
instance.setCpuCoresPerSocket(vmMo.getCoresPerSocket());
instance.setCpuSpeed(vmMo.getConfigSummary().getCpuReservation());
instance.setMemory(vmMo.getConfigSummary().getMemorySizeMB());
instance.setOperatingSystemId(vmMo.getVmGuestInfo().getGuestId());
if (StringUtils.isEmpty(instance.getOperatingSystemId())) {
instance.setOperatingSystemId(vmMo.getConfigSummary().getGuestId());
}
VirtualMachineGuestOsIdentifier osIdentifier = VirtualMachineGuestOsIdentifier.OTHER_GUEST;
try {
osIdentifier = VirtualMachineGuestOsIdentifier.fromValue(instance.getOperatingSystemId());
} catch (IllegalArgumentException iae) {
if (StringUtils.isNotEmpty(instance.getOperatingSystemId()) && instance.getOperatingSystemId().contains("64")) {
osIdentifier = VirtualMachineGuestOsIdentifier.OTHER_GUEST_64;
}
}
instance.setOperatingSystem(vmMo.getGuestInfo().getGuestFullName());
if (StringUtils.isEmpty(instance.getOperatingSystem())) {
instance.setOperatingSystem(vmMo.getConfigSummary().getGuestFullName());
}
UnmanagedInstanceTO.PowerState powerState = UnmanagedInstanceTO.PowerState.PowerUnknown;
if (vmMo.getPowerState().toString().equalsIgnoreCase("POWERED_ON")) {
powerState = UnmanagedInstanceTO.PowerState.PowerOn;
}
if (vmMo.getPowerState().toString().equalsIgnoreCase("POWERED_OFF")) {
powerState = UnmanagedInstanceTO.PowerState.PowerOff;
}
instance.setPowerState(powerState);
instance.setDisks(getUnmanageInstanceDisks(vmMo));
instance.setNics(getUnmanageInstanceNics(hyperHost, vmMo));
} catch (Exception e) {
s_logger.info("Unable to retrieve unmanaged instance info. " + e.getMessage());
}
return instance;
}
Aggregations