Search in sources :

Example 6 with RebootAnswer

use of com.cloud.agent.api.RebootAnswer in project cloudstack by apache.

the class CitrixRebootCommandWrapper method execute.

@Override
public Answer execute(final RebootCommand command, final CitrixResourceBase citrixResourceBase) {
    final Connection conn = citrixResourceBase.getConnection();
    s_logger.debug("7. The VM " + command.getVmName() + " is in Starting state");
    try {
        Set<VM> vms = null;
        try {
            vms = VM.getByNameLabel(conn, command.getVmName());
        } catch (final XenAPIException e0) {
            s_logger.debug("getByNameLabel failed " + e0.toString());
            return new RebootAnswer(command, "getByNameLabel failed " + e0.toString(), false);
        } catch (final Exception e0) {
            s_logger.debug("getByNameLabel failed " + e0.getMessage());
            return new RebootAnswer(command, "getByNameLabel failed", false);
        }
        for (final VM vm : vms) {
            try {
                citrixResourceBase.rebootVM(conn, vm, vm.getNameLabel(conn));
            } catch (final Exception e) {
                final String msg = e.toString();
                s_logger.warn(msg, e);
                return new RebootAnswer(command, msg, false);
            }
        }
        return new RebootAnswer(command, "reboot succeeded", true);
    } finally {
        s_logger.debug("8. The VM " + command.getVmName() + " is in Running state");
    }
}
Also used : VM(com.xensource.xenapi.VM) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) RebootAnswer(com.cloud.agent.api.RebootAnswer) XenAPIException(com.xensource.xenapi.Types.XenAPIException)

Example 7 with RebootAnswer

use of com.cloud.agent.api.RebootAnswer in project cloudstack by apache.

the class LibvirtRebootCommandWrapper method execute.

@Override
public Answer execute(final RebootCommand command, final LibvirtComputingResource libvirtComputingResource) {
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
    try {
        final Connect conn = libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName());
        final String result = libvirtComputingResource.rebootVM(conn, command.getVmName());
        if (result == null) {
            Integer vncPort = null;
            try {
                vncPort = libvirtComputingResource.getVncPort(conn, command.getVmName());
            } catch (final LibvirtException e) {
                s_logger.trace("Ignoring libvirt error.", e);
            }
            libvirtComputingResource.getRuleLogsForVms();
            return new RebootAnswer(command, null, vncPort);
        } else {
            return new RebootAnswer(command, result, false);
        }
    } catch (final LibvirtException e) {
        return new RebootAnswer(command, e.getMessage(), false);
    }
}
Also used : LibvirtException(org.libvirt.LibvirtException) Connect(org.libvirt.Connect) RebootAnswer(com.cloud.agent.api.RebootAnswer)

Example 8 with RebootAnswer

use of com.cloud.agent.api.RebootAnswer in project cloudstack by apache.

the class Ovm3HypervisorResource method execute.

@Override
public RebootAnswer execute(RebootCommand cmd) {
    String vmName = cmd.getVmName();
    hypervisorsupport.setVmStateStarting(vmName);
    try {
        Xen xen = new Xen(c);
        Xen.Vm vm = xen.getRunningVmConfig(vmName);
        if (vm == null) {
            return new RebootAnswer(cmd, vmName + " not present", false);
        }
        xen.rebootVm(ovmObject.deDash(vm.getVmRootDiskPoolId()), vm.getVmUuid());
        vm = xen.getRunningVmConfig(vmName);
        Integer vncPort = vm.getVncPort();
        return new RebootAnswer(cmd, null, vncPort);
    } catch (Exception e) {
        LOGGER.debug("Reboot " + vmName + " failed", e);
        return new RebootAnswer(cmd, e.getMessage(), false);
    } finally {
        hypervisorsupport.setVmState(vmName, State.Running);
    }
}
Also used : Xen(com.cloud.hypervisor.ovm3.objects.Xen) RebootAnswer(com.cloud.agent.api.RebootAnswer) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)

Example 9 with RebootAnswer

use of com.cloud.agent.api.RebootAnswer 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)

Example 10 with RebootAnswer

use of com.cloud.agent.api.RebootAnswer in project cloudstack by apache.

the class VmwareResource method execute.

protected Answer execute(RebootRouterCommand cmd) {
    if (s_logger.isInfoEnabled()) {
        s_logger.info("Executing resource RebootRouterCommand: " + _gson.toJson(cmd));
    }
    RebootAnswer answer = (RebootAnswer) execute((RebootCommand) cmd);
    if (answer.getResult()) {
        String connectResult = connect(cmd.getVmName(), cmd.getPrivateIpAddress());
        networkUsage(cmd.getPrivateIpAddress(), "create", null);
        if (connectResult == null) {
            return answer;
        } else {
            return new Answer(cmd, false, connectResult);
        }
    }
    return answer;
}
Also used : ModifyTargetsAnswer(com.cloud.agent.api.ModifyTargetsAnswer) GetVncPortAnswer(com.cloud.agent.api.GetVncPortAnswer) ManageSnapshotAnswer(com.cloud.agent.api.ManageSnapshotAnswer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) SetupAnswer(com.cloud.agent.api.SetupAnswer) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) StopAnswer(com.cloud.agent.api.StopAnswer) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) UnPlugNicAnswer(com.cloud.agent.api.UnPlugNicAnswer) CheckOnHostAnswer(com.cloud.agent.api.CheckOnHostAnswer) CheckHealthAnswer(com.cloud.agent.api.CheckHealthAnswer) RevertToVMSnapshotAnswer(com.cloud.agent.api.RevertToVMSnapshotAnswer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) CreateVMSnapshotAnswer(com.cloud.agent.api.CreateVMSnapshotAnswer) DeleteVMSnapshotAnswer(com.cloud.agent.api.DeleteVMSnapshotAnswer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) RebootAnswer(com.cloud.agent.api.RebootAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) StartAnswer(com.cloud.agent.api.StartAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) MigrateAnswer(com.cloud.agent.api.MigrateAnswer) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer) CheckNetworkAnswer(com.cloud.agent.api.CheckNetworkAnswer) PlugNicAnswer(com.cloud.agent.api.PlugNicAnswer) ScaleVmAnswer(com.cloud.agent.api.ScaleVmAnswer) MigrateWithStorageAnswer(com.cloud.agent.api.MigrateWithStorageAnswer) ResizeVolumeAnswer(com.cloud.agent.api.storage.ResizeVolumeAnswer) BackupSnapshotAnswer(com.cloud.agent.api.BackupSnapshotAnswer) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) ValidateSnapshotAnswer(com.cloud.agent.api.ValidateSnapshotAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer) GetVmDiskStatsAnswer(com.cloud.agent.api.GetVmDiskStatsAnswer) RebootCommand(com.cloud.agent.api.RebootCommand) RebootAnswer(com.cloud.agent.api.RebootAnswer)

Aggregations

RebootAnswer (com.cloud.agent.api.RebootAnswer)10 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)5 ConfigurationException (javax.naming.ConfigurationException)4 Answer (com.cloud.agent.api.Answer)3 CheckVirtualMachineAnswer (com.cloud.agent.api.CheckVirtualMachineAnswer)3 RebootCommand (com.cloud.agent.api.RebootCommand)3 StartAnswer (com.cloud.agent.api.StartAnswer)3 StopAnswer (com.cloud.agent.api.StopAnswer)3 BackupSnapshotAnswer (com.cloud.agent.api.BackupSnapshotAnswer)2 CheckHealthAnswer (com.cloud.agent.api.CheckHealthAnswer)2 CheckNetworkAnswer (com.cloud.agent.api.CheckNetworkAnswer)2 CreateVolumeFromSnapshotAnswer (com.cloud.agent.api.CreateVolumeFromSnapshotAnswer)2 GetHostStatsAnswer (com.cloud.agent.api.GetHostStatsAnswer)2 GetStorageStatsAnswer (com.cloud.agent.api.GetStorageStatsAnswer)2 GetVmStatsAnswer (com.cloud.agent.api.GetVmStatsAnswer)2 GetVncPortAnswer (com.cloud.agent.api.GetVncPortAnswer)2 MaintainAnswer (com.cloud.agent.api.MaintainAnswer)2 ManageSnapshotAnswer (com.cloud.agent.api.ManageSnapshotAnswer)2 MigrateAnswer (com.cloud.agent.api.MigrateAnswer)2 ModifyStoragePoolAnswer (com.cloud.agent.api.ModifyStoragePoolAnswer)2