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