Search in sources :

Example 16 with CheckVirtualMachineAnswer

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

the class MockVmManagerImpl method checkVmState.

@Override
public CheckVirtualMachineAnswer checkVmState(final CheckVirtualMachineCommand cmd) {
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    try {
        txn.start();
        final MockVMVO vm = _mockVmDao.findByVmName(cmd.getVmName());
        if (vm == null) {
            return new CheckVirtualMachineAnswer(cmd, "can't find vm:" + cmd.getVmName());
        }
        txn.commit();
        return new CheckVirtualMachineAnswer(cmd, vm.getPowerState(), vm.getVncPort());
    } catch (final Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("unable to fetch vm state " + cmd.getVmName(), ex);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
}
Also used : MockVMVO(com.cloud.simulator.MockVMVO) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 17 with CheckVirtualMachineAnswer

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

the class OvmResourceBase method execute.

protected CheckVirtualMachineAnswer execute(final CheckVirtualMachineCommand cmd) {
    final String vmName = cmd.getVmName();
    try {
        Map<String, String> res = OvmVm.register(_conn, vmName);
        Integer vncPort = Integer.parseInt(res.get("vncPort"));
        HashMap<String, PowerState> states = getAllVms();
        PowerState vmPowerState = states.get(vmName);
        if (vmPowerState == null) {
            s_logger.warn("Check state of " + vmName + " return null in CheckVirtualMachineCommand");
            vmPowerState = PowerState.PowerOff;
        }
        return new CheckVirtualMachineAnswer(cmd, vmPowerState, vncPort);
    } catch (Exception e) {
        s_logger.debug("Check migration for " + vmName + " failed", e);
        return new CheckVirtualMachineAnswer(cmd, PowerState.PowerOff, null);
    }
}
Also used : CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) PowerState(com.cloud.vm.VirtualMachine.PowerState) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) ConfigurationException(javax.naming.ConfigurationException)

Example 18 with CheckVirtualMachineAnswer

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

the class CitrixCheckVirtualMachineCommandWrapper method execute.

@Override
public Answer execute(final CheckVirtualMachineCommand command, final CitrixResourceBase citrixResourceBase) {
    final Connection conn = citrixResourceBase.getConnection();
    final String vmName = command.getVmName();
    final PowerState powerState = citrixResourceBase.getVmState(conn, vmName);
    final Integer vncPort = null;
    if (powerState == PowerState.PowerOn) {
        s_logger.debug("3. The VM " + vmName + " is in Running state");
    }
    return new CheckVirtualMachineAnswer(command, powerState, vncPort);
}
Also used : CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) Connection(com.xensource.xenapi.Connection) PowerState(com.cloud.vm.VirtualMachine.PowerState)

Example 19 with CheckVirtualMachineAnswer

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

the class VmwareResource method execute.

protected Answer execute(CheckVirtualMachineCommand cmd) {
    final String vmName = cmd.getVmName();
    PowerState powerState = PowerState.PowerUnknown;
    Integer vncPort = null;
    VmwareContext context = getServiceContext();
    VmwareHypervisorHost hyperHost = getHyperHost(context);
    try {
        VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(vmName);
        if (vmMo != null) {
            powerState = getVmPowerState(vmMo);
            return new CheckVirtualMachineAnswer(cmd, powerState, vncPort);
        } else {
            s_logger.warn("Can not find vm " + vmName + " to execute CheckVirtualMachineCommand");
            return new CheckVirtualMachineAnswer(cmd, powerState, vncPort);
        }
    } catch (Throwable e) {
        createLogMessageException(e, cmd);
        return new CheckVirtualMachineAnswer(cmd, powerState, vncPort);
    }
}
Also used : CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) VirtualMachineMO(com.cloud.hypervisor.vmware.mo.VirtualMachineMO) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) PowerState(com.cloud.vm.VirtualMachine.PowerState) VirtualMachinePowerState(com.vmware.vim25.VirtualMachinePowerState)

Aggregations

CheckVirtualMachineAnswer (com.cloud.agent.api.CheckVirtualMachineAnswer)19 CheckVirtualMachineCommand (com.cloud.agent.api.CheckVirtualMachineCommand)7 PowerState (com.cloud.vm.VirtualMachine.PowerState)7 Answer (com.cloud.agent.api.Answer)3 PrepareForMigrationAnswer (com.cloud.agent.api.PrepareForMigrationAnswer)3 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)3 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)3 State (com.cloud.vm.VirtualMachine.State)3 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)2 ClusterVMMetaDataSyncAnswer (com.cloud.agent.api.ClusterVMMetaDataSyncAnswer)2 MigrateWithStorageAnswer (com.cloud.agent.api.MigrateWithStorageAnswer)2 MigrateWithStorageCommand (com.cloud.agent.api.MigrateWithStorageCommand)2 MigrateWithStorageCompleteAnswer (com.cloud.agent.api.MigrateWithStorageCompleteAnswer)2 MigrateWithStorageCompleteCommand (com.cloud.agent.api.MigrateWithStorageCompleteCommand)2 MigrateWithStorageReceiveAnswer (com.cloud.agent.api.MigrateWithStorageReceiveAnswer)2 MigrateWithStorageReceiveCommand (com.cloud.agent.api.MigrateWithStorageReceiveCommand)2 MigrateWithStorageSendAnswer (com.cloud.agent.api.MigrateWithStorageSendAnswer)2 MigrateWithStorageSendCommand (com.cloud.agent.api.MigrateWithStorageSendCommand)2 PlugNicAnswer (com.cloud.agent.api.PlugNicAnswer)2 PrepareForMigrationCommand (com.cloud.agent.api.PrepareForMigrationCommand)2