Search in sources :

Example 1 with ToolsUnavailableFaultMsg

use of com.vmware.vim25.ToolsUnavailableFaultMsg in project cloudstack by apache.

the class VmwareResource method execute.

protected Answer execute(RebootCommand cmd) {
    if (s_logger.isInfoEnabled()) {
        s_logger.info("Executing resource RebootCommand: " + _gson.toJson(cmd));
    }
    boolean toolsInstallerMounted = false;
    VirtualMachineMO vmMo = null;
    VmwareContext context = getServiceContext();
    VmwareHypervisorHost hyperHost = getHyperHost(context);
    try {
        vmMo = hyperHost.findVmOnHyperHost(cmd.getVmName());
        if (vmMo != null) {
            if (vmMo.isToolsInstallerMounted()) {
                toolsInstallerMounted = true;
                s_logger.trace("Detected mounted vmware tools installer for :[" + cmd.getVmName() + "]");
            }
            try {
                vmMo.rebootGuest();
                return new RebootAnswer(cmd, "reboot succeeded", true);
            } catch (ToolsUnavailableFaultMsg e) {
                s_logger.warn("VMware tools is not installed at guest OS, we will perform hard reset for reboot");
            } catch (Exception e) {
                s_logger.warn("We are not able to perform gracefull guest reboot due to " + VmwareHelper.getExceptionMessage(e));
            }
            // continue to try with hard-reset
            if (vmMo.reset()) {
                return new RebootAnswer(cmd, "reboot succeeded", true);
            }
            String msg = "Reboot failed in vSphere. vm: " + cmd.getVmName();
            s_logger.warn(msg);
            return new RebootAnswer(cmd, msg, false);
        } else {
            String msg = "Unable to find the VM in vSphere to reboot. vm: " + cmd.getVmName();
            s_logger.warn(msg);
            return new RebootAnswer(cmd, msg, false);
        }
    } catch (Exception e) {
        if (e instanceof RemoteException) {
            s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
            invalidateServiceContext();
        }
        String msg = "RebootCommand failed due to " + VmwareHelper.getExceptionMessage(e);
        s_logger.error(msg);
        return new RebootAnswer(cmd, msg, false);
    } finally {
        if (toolsInstallerMounted) {
            try {
                vmMo.mountToolsInstaller();
                s_logger.debug("Successfully re-mounted vmware tools installer for :[" + cmd.getVmName() + "]");
            } catch (Exception e) {
                s_logger.warn("Unabled to re-mount vmware tools installer for :[" + cmd.getVmName() + "]");
            }
        }
    }
}
Also used : VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) VirtualMachineMO(com.cloud.hypervisor.vmware.mo.VirtualMachineMO) ToolsUnavailableFaultMsg(com.vmware.vim25.ToolsUnavailableFaultMsg) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) RebootAnswer(com.cloud.agent.api.RebootAnswer) RemoteException(java.rmi.RemoteException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException)

Aggregations

RebootAnswer (com.cloud.agent.api.RebootAnswer)1 CloudException (com.cloud.exception.CloudException)1 InternalErrorException (com.cloud.exception.InternalErrorException)1 VirtualMachineMO (com.cloud.hypervisor.vmware.mo.VirtualMachineMO)1 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)1 VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 ToolsUnavailableFaultMsg (com.vmware.vim25.ToolsUnavailableFaultMsg)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ConnectException (java.net.ConnectException)1 RemoteException (java.rmi.RemoteException)1 ConfigurationException (javax.naming.ConfigurationException)1