use of com.cloud.agent.api.RebootAnswer in project CloudStack-archive by CloudStack-extras.
the class LibvirtComputingResource method execute.
protected Answer execute(RebootRouterCommand cmd) {
Long bytesSent = 0L;
Long bytesRcvd = 0L;
if (VirtualMachineName.isValidRouterName(cmd.getVmName())) {
long[] stats = getNetworkStats(cmd.getPrivateIpAddress());
bytesSent = stats[0];
bytesRcvd = stats[1];
}
RebootAnswer answer = (RebootAnswer) execute((RebootCommand) cmd);
answer.setBytesSent(bytesSent);
answer.setBytesReceived(bytesRcvd);
String result = _virtRouterResource.connect(cmd.getPrivateIpAddress());
if (result == null) {
networkUsage(cmd.getPrivateIpAddress(), "create", null);
return answer;
} else {
return new Answer(cmd, false, result);
}
}
use of com.cloud.agent.api.RebootAnswer in project CloudStack-archive by CloudStack-extras.
the class LibvirtComputingResource method execute.
private Answer execute(RebootCommand cmd) {
Long bytesReceived = null;
Long bytesSent = null;
synchronized (_vms) {
_vms.put(cmd.getVmName(), State.Starting);
}
try {
Connect conn = LibvirtConnection.getConnection();
final String result = rebootVM(conn, cmd.getVmName());
if (result == null) {
Integer vncPort = null;
try {
vncPort = getVncPort(conn, cmd.getVmName());
} catch (Exception e) {
}
get_rule_logs_for_vms();
return new RebootAnswer(cmd, null, bytesSent, bytesReceived, vncPort);
} else {
return new RebootAnswer(cmd, result);
}
} catch (LibvirtException e) {
return new RebootAnswer(cmd, e.getMessage());
} finally {
synchronized (_vms) {
_vms.put(cmd.getVmName(), State.Running);
}
}
}
use of com.cloud.agent.api.RebootAnswer in project cloudstack by apache.
the class OvmResourceBase method execute.
@Override
public RebootAnswer execute(RebootCommand cmd) {
String vmName = cmd.getVmName();
try {
Map<String, String> res = OvmVm.reboot(_conn, vmName);
Integer vncPort = Integer.parseInt(res.get("vncPort"));
return new RebootAnswer(cmd, null, vncPort);
} catch (Exception e) {
s_logger.debug("Reboot " + vmName + " failed", e);
return new RebootAnswer(cmd, e.getMessage(), false);
}
}
use of com.cloud.agent.api.RebootAnswer in project CloudStack-archive by CloudStack-extras.
the class FakeComputingResource method execute.
protected Answer execute(RebootCommand cmd) {
VmMgr vmMgr = getVmManager();
vmMgr.rebootVM(cmd.getVmName());
return new RebootAnswer(cmd, "success", 0L, 0L);
}
use of com.cloud.agent.api.RebootAnswer in project cloudstack by apache.
the class VirtualMachineManagerImpl method orchestrateReboot.
private void orchestrateReboot(final String vmUuid, final Map<VirtualMachineProfile.Param, Object> params) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
// if there are active vm snapshots task, state change is not allowed
if (_vmSnapshotMgr.hasActiveVMSnapshotTasks(vm.getId())) {
s_logger.error("Unable to reboot VM " + vm + " due to: " + vm.getInstanceName() + " has active VM snapshots tasks");
throw new CloudRuntimeException("Unable to reboot VM " + vm + " due to: " + vm.getInstanceName() + " has active VM snapshots tasks");
}
final DataCenter dc = _entityMgr.findById(DataCenter.class, vm.getDataCenterId());
final Host host = _hostDao.findById(vm.getHostId());
if (host == null) {
// Should findById throw an Exception is the host is not found?
throw new CloudRuntimeException("Unable to retrieve host with id " + vm.getHostId());
}
final Cluster cluster = _entityMgr.findById(Cluster.class, host.getClusterId());
final Pod pod = _entityMgr.findById(Pod.class, host.getPodId());
final DeployDestination dest = new DeployDestination(dc, pod, cluster, host);
try {
final Commands cmds = new Commands(Command.OnError.Stop);
cmds.addCommand(new RebootCommand(vm.getInstanceName(), getExecuteInSequence(vm.getHypervisorType())));
_agentMgr.send(host.getId(), cmds);
final Answer rebootAnswer = cmds.getAnswer(RebootAnswer.class);
if (rebootAnswer != null && rebootAnswer.getResult()) {
return;
}
s_logger.info("Unable to reboot VM " + vm + " on " + dest.getHost() + " due to " + (rebootAnswer == null ? " no reboot answer" : rebootAnswer.getDetails()));
} catch (final OperationTimedoutException e) {
s_logger.warn("Unable to send the reboot command to host " + dest.getHost() + " for the vm " + vm + " due to operation timeout", e);
throw new CloudRuntimeException("Failed to reboot the vm on host " + dest.getHost());
}
}
Aggregations