use of com.vmware.vim25.GuestInfo in project cloudstack by apache.
the class VmwareResource method execute.
protected Answer execute(GetVmIpAddressCommand cmd) {
if (s_logger.isTraceEnabled()) {
s_logger.trace("Executing resource command GetVmIpAddressCommand: " + _gson.toJson(cmd));
}
String details = "Unable to find IP Address of VM. ";
String vmName = cmd.getVmName();
boolean result = false;
String ip = null;
Answer answer = null;
VmwareContext context = getServiceContext();
VmwareHypervisorHost hyperHost = getHyperHost(context);
if (vmName == null || vmName.isEmpty()) {
details += "Name of instance provided is NULL or empty.";
return new Answer(cmd, result, details);
}
try {
VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(vmName);
if (vmMo != null) {
GuestInfo guestInfo = vmMo.getGuestInfo();
VirtualMachineToolsStatus toolsStatus = guestInfo.getToolsStatus();
if (toolsStatus == VirtualMachineToolsStatus.TOOLS_NOT_INSTALLED) {
details += "Vmware tools not installed.";
} else {
ip = guestInfo.getIpAddress();
if (ip != null) {
result = true;
}
details = ip;
}
} else {
details += "VM " + vmName + " no longer exists on vSphere host: " + hyperHost.getHyperHostName();
s_logger.info(details);
}
} catch (Throwable e) {
if (e instanceof RemoteException) {
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
invalidateServiceContext();
}
details += "Encountered exception : " + VmwareHelper.getExceptionMessage(e);
s_logger.error(details);
}
answer = new Answer(cmd, result, details);
if (s_logger.isTraceEnabled()) {
s_logger.trace("Returning GetVmIpAddressAnswer: " + _gson.toJson(answer));
}
return answer;
}
Aggregations