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();
}
}
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);
}
}
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);
}
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);
}
}
Aggregations