use of com.cloud.agent.api.StopAnswer in project CloudStack-archive by CloudStack-extras.
the class LibvirtComputingResource method execute.
protected Answer execute(StopCommand cmd) {
final String vmName = cmd.getVmName();
Long bytesReceived = new Long(0);
Long bytesSent = new Long(0);
State state = null;
synchronized (_vms) {
state = _vms.get(vmName);
_vms.put(vmName, State.Stopping);
}
try {
Connect conn = LibvirtConnection.getConnection();
List<DiskDef> disks = getDisks(conn, vmName);
destroy_network_rules_for_vm(conn, vmName);
String result = stopVM(conn, vmName, defineOps.UNDEFINE_VM);
if (result == null) {
for (DiskDef disk : disks) {
if (disk.getDeviceType() == DiskDef.deviceType.CDROM && disk.getDiskPath() != null)
cleanupDisk(conn, disk);
}
}
final String result2 = cleanupVnet(conn, cmd.getVnet());
if (result != null && result2 != null) {
result = result2 + result;
}
state = State.Stopped;
return new StopAnswer(cmd, result, 0, bytesSent, bytesReceived);
} catch (LibvirtException e) {
return new StopAnswer(cmd, e.getMessage());
} finally {
synchronized (_vms) {
if (state != null) {
_vms.put(vmName, state);
} else {
_vms.remove(vmName);
}
}
}
}
use of com.cloud.agent.api.StopAnswer in project CloudStack-archive by CloudStack-extras.
the class CloudZonesComputingResource method execute.
protected Answer execute(StopCommand cmd) {
final String vmName = cmd.getVmName();
Long bytesReceived = new Long(0);
Long bytesSent = new Long(0);
State state = null;
synchronized (_vms) {
state = _vms.get(vmName);
_vms.put(vmName, State.Stopping);
}
try {
Connect conn = LibvirtConnection.getConnection();
try {
Domain dm = conn.domainLookupByUUID(UUID.nameUUIDFromBytes(vmName.getBytes()));
} catch (LibvirtException e) {
state = State.Stopped;
return new StopAnswer(cmd, null, 0, bytesSent, bytesReceived);
}
String macAddress = null;
if (vmName.startsWith("i-")) {
List<InterfaceDef> nics = getInterfaces(conn, vmName);
if (!nics.isEmpty()) {
macAddress = nics.get(0).getMacAddress();
}
}
destroy_network_rules_for_vm(conn, vmName);
String result = stopVM(conn, vmName, defineOps.UNDEFINE_VM);
try {
cleanupVnet(conn, cmd.getVnet());
_dhcpSnooper.cleanup(macAddress, vmName);
_vmDataServer.handleVmStopped(cmd.getVmName());
} catch (Exception e) {
}
state = State.Stopped;
return new StopAnswer(cmd, result, 0, bytesSent, bytesReceived);
} catch (LibvirtException e) {
return new StopAnswer(cmd, e.getMessage());
} finally {
synchronized (_vms) {
if (state != null) {
_vms.put(vmName, state);
} else {
_vms.remove(vmName);
}
}
}
}
use of com.cloud.agent.api.StopAnswer in project cloudstack by apache.
the class VirtualMachineManagerImplTest method testSendStopWithOkAnswer.
@Test
public void testSendStopWithOkAnswer() throws Exception {
VirtualMachineGuru guru = mock(VirtualMachineGuru.class);
VirtualMachine vm = mock(VirtualMachine.class);
VirtualMachineProfile profile = mock(VirtualMachineProfile.class);
StopAnswer answer = new StopAnswer(new StopCommand(vm, false, false), "ok", true);
when(profile.getVirtualMachine()).thenReturn(vm);
when(vm.getHostId()).thenReturn(1L);
when(_agentMgr.send(anyLong(), (Command) any())).thenReturn(answer);
boolean actual = _vmMgr.sendStop(guru, profile, false, false);
Assert.assertTrue(actual);
}
use of com.cloud.agent.api.StopAnswer in project cloudstack by apache.
the class OvmResourceBase method execute.
@Override
public StopAnswer execute(StopCommand cmd) {
String vmName = cmd.getVmName();
try {
OvmVm.Details vm = null;
try {
vm = OvmVm.getDetails(_conn, vmName);
} catch (XmlRpcException e) {
s_logger.debug("Unable to get details of vm: " + vmName + ", treating it as stopped", e);
return new StopAnswer(cmd, "success", true);
}
deleteAllNetworkRulesForVm(vmName);
OvmVm.stop(_conn, vmName);
cleanup(vm);
return new StopAnswer(cmd, "success", true);
} catch (Exception e) {
s_logger.debug("Stop " + vmName + "failed", e);
return new StopAnswer(cmd, e.getMessage(), false);
}
}
use of com.cloud.agent.api.StopAnswer in project cloudstack by apache.
the class HypervDirectConnectResourceTest method testStartStartCommand.
@Test
public final void testStartStartCommand() {
String sample = getSampleStartCommand();
StartAnswer sans = simpleVmStart(sample);
Assert.assertTrue(sans.getDetails(), sans.getResult());
simpleVmStart(sample);
StopAnswer ans = simpleVmStop();
Assert.assertTrue(ans.getDetails(), ans.getResult());
}
Aggregations