use of com.cloud.agent.api.to.NicTO in project cloudstack by apache.
the class OvmResourceBase method execute.
@Override
public synchronized StartAnswer execute(StartCommand cmd) {
VirtualMachineTO vmSpec = cmd.getVirtualMachine();
String vmName = vmSpec.getName();
OvmVm.Details vmDetails = null;
try {
vmDetails = new OvmVm.Details();
applySpecToVm(vmDetails, vmSpec);
createVbds(vmDetails, vmSpec);
createVifs(vmDetails, vmSpec);
startVm(vmDetails);
// Add security group rules
NicTO[] nics = vmSpec.getNics();
for (NicTO nic : nics) {
if (nic.isSecurityGroupEnabled()) {
if (vmSpec.getType().equals(VirtualMachine.Type.User)) {
defaultNetworkRulesForUserVm(vmName, vmSpec.getId(), nic);
}
}
}
return new StartAnswer(cmd);
} catch (Exception e) {
s_logger.debug("Start vm " + vmName + " failed", e);
cleanup(vmDetails);
return new StartAnswer(cmd, e.getMessage());
}
}
use of com.cloud.agent.api.to.NicTO in project cloudstack by apache.
the class OvmResourceBase method createVifs.
protected void createVifs(OvmVm.Details vm, VirtualMachineTO spec) throws CloudRuntimeException, XmlRpcException {
NicTO[] nics = spec.getNics();
List<OvmVif.Details> vifs = new ArrayList<OvmVif.Details>(nics.length);
for (NicTO nic : nics) {
OvmVif.Details vif = createVif(nic);
vifs.add(nic.getDeviceId(), vif);
}
vm.vifs.addAll(vifs);
}
use of com.cloud.agent.api.to.NicTO in project cloudstack by apache.
the class LibvirtComputingResource method prepareNetworkElementCommand.
private ExecutionResult prepareNetworkElementCommand(final SetupGuestNetworkCommand cmd) {
Connect conn;
final NicTO nic = cmd.getNic();
final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
try {
conn = LibvirtConnection.getConnectionByVmName(routerName);
final List<InterfaceDef> pluggedNics = getInterfaces(conn, routerName);
InterfaceDef routerNic = null;
for (final InterfaceDef pluggedNic : pluggedNics) {
if (pluggedNic.getMacAddress().equalsIgnoreCase(nic.getMac())) {
routerNic = pluggedNic;
break;
}
}
if (routerNic == null) {
return new ExecutionResult(false, "Can not find nic with mac " + nic.getMac() + " for VM " + routerName);
}
return new ExecutionResult(true, null);
} catch (final LibvirtException e) {
final String msg = "Creating guest network failed due to " + e.toString();
s_logger.warn(msg, e);
return new ExecutionResult(false, msg);
}
}
use of com.cloud.agent.api.to.NicTO in project cloudstack by apache.
the class LibvirtComputingResourceTest method testUnPlugNicCommandLibvirtException.
@SuppressWarnings("unchecked")
@Test
public void testUnPlugNicCommandLibvirtException() {
final NicTO nic = Mockito.mock(NicTO.class);
final String instanceName = "Test";
final UnPlugNicCommand command = new UnPlugNicCommand(nic, instanceName);
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName())).thenThrow(LibvirtException.class);
} catch (final LibvirtException e) {
fail(e.getMessage());
}
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, libvirtComputingResource);
assertFalse(answer.getResult());
verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(command.getVmName());
} catch (final LibvirtException e) {
fail(e.getMessage());
}
}
use of com.cloud.agent.api.to.NicTO in project cloudstack by apache.
the class LibvirtComputingResourceTest method testPrepareForMigrationCommandInternalErrorException.
@SuppressWarnings("unchecked")
@Test
public void testPrepareForMigrationCommandInternalErrorException() {
final Connect conn = Mockito.mock(Connect.class);
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
final VirtualMachineTO vm = Mockito.mock(VirtualMachineTO.class);
final KVMStoragePoolManager storagePoolManager = Mockito.mock(KVMStoragePoolManager.class);
final NicTO nicTO = Mockito.mock(NicTO.class);
final DiskTO volume = Mockito.mock(DiskTO.class);
final PrepareForMigrationCommand command = new PrepareForMigrationCommand(vm);
when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(vm.getName())).thenReturn(conn);
} catch (final LibvirtException e) {
fail(e.getMessage());
}
when(vm.getNics()).thenReturn(new NicTO[] { nicTO });
when(nicTO.getType()).thenReturn(TrafficType.Guest);
when(libvirtComputingResource.getVifDriver(nicTO.getType())).thenThrow(InternalErrorException.class);
when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolManager);
try {
when(libvirtComputingResource.getVolumePath(conn, volume)).thenReturn("/path");
} catch (final LibvirtException e) {
fail(e.getMessage());
} catch (final URISyntaxException e) {
fail(e.getMessage());
}
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, libvirtComputingResource);
assertFalse(answer.getResult());
verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vm.getName());
} catch (final LibvirtException e) {
fail(e.getMessage());
}
verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
verify(vm, times(1)).getNics();
}
Aggregations