use of com.cloud.legacymodel.communication.answer.RebootAnswer in project cosmic by MissionCriticalCloud.
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);
}
return new RebootAnswer(command, null, vncPort);
} else {
return new RebootAnswer(command, result, false);
}
} catch (final LibvirtException e) {
return new RebootAnswer(command, e.getMessage(), false);
}
}
use of com.cloud.legacymodel.communication.answer.RebootAnswer in project cosmic by MissionCriticalCloud.
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");
}
}
use of com.cloud.legacymodel.communication.answer.RebootAnswer in project cosmic by MissionCriticalCloud.
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 Zone zone = _zoneRepository.findById(vm.getDataCenterId()).orElse(null);
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(zone, 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