use of com.cloud.agent.api.to.VirtualMachineTO in project cloudstack by apache.
the class LibvirtComputingResourceTest method testCreateVMFromSpecWithTopology4.
/**
This test verifies that CPU topology is properly set for quad-core
*/
@Test
public void testCreateVMFromSpecWithTopology4() {
final int id = random.nextInt(65534);
final String name = "test-instance-1";
final int cpus = 8;
final int minSpeed = 1024;
final int maxSpeed = 2048;
final int minRam = 256 * 1024;
final int maxRam = 512 * 1024;
final String os = "Ubuntu";
final String vncAddr = "";
final String vncPassword = "mySuperSecretPassword";
final LibvirtComputingResource lcr = new LibvirtComputingResource();
final VirtualMachineTO to = new VirtualMachineTO(id, name, VirtualMachine.Type.User, cpus, minSpeed, maxSpeed, minRam, maxRam, BootloaderType.HVM, os, false, false, vncPassword);
to.setVncAddr(vncAddr);
to.setUuid("b0f0a72d-7efb-3cad-a8ff-70ebf30b3af9");
final LibvirtVMDef vm = lcr.createVMFromSpec(to);
vm.setHvsType(hyperVisorType);
verifyVm(to, vm);
}
use of com.cloud.agent.api.to.VirtualMachineTO in project cloudstack by apache.
the class LibvirtComputingResourceTest method testPrepareForMigrationCommandMigration.
@Test
public void testPrepareForMigrationCommandMigration() {
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 diskTO = Mockito.mock(DiskTO.class);
final VifDriver vifDriver = Mockito.mock(VifDriver.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(vm.getDisks()).thenReturn(new DiskTO[] { diskTO });
when(nicTO.getType()).thenReturn(TrafficType.Guest);
when(diskTO.getType()).thenReturn(Volume.Type.ISO);
when(libvirtComputingResource.getVifDriver(nicTO.getType())).thenReturn(vifDriver);
when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolManager);
when(storagePoolManager.connectPhysicalDisksViaVmSpec(vm)).thenReturn(true);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, libvirtComputingResource);
assertTrue(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();
verify(vm, times(1)).getDisks();
verify(diskTO, times(1)).getType();
}
use of com.cloud.agent.api.to.VirtualMachineTO in project cloudstack by apache.
the class SimulatorGuru method implement.
@Override
public VirtualMachineTO implement(VirtualMachineProfile vm) {
VirtualMachineTO to = toVirtualMachineTO(vm);
// Determine the VM's OS description
GuestOSVO guestOS = _guestOsDao.findById(vm.getVirtualMachine().getGuestOSId());
to.setOs(guestOS.getDisplayName());
return to;
}
use of com.cloud.agent.api.to.VirtualMachineTO in project cloudstack by apache.
the class AgentRoutingResource method execute.
protected synchronized Answer execute(StartCommand cmd) throws IllegalArgumentException {
VirtualMachineTO vmSpec = cmd.getVirtualMachine();
String vmName = vmSpec.getName();
if (this.totalCpu < (vmSpec.getCpus() * vmSpec.getMaxSpeed() + this.usedCpu) || this.totalMem < (vmSpec.getMaxRam() + this.usedMem)) {
return new StartAnswer(cmd, "Not enough resource to start the vm");
}
Answer result = _simMgr.simulate(cmd, hostGuid);
if (!result.getResult()) {
return new StartAnswer(cmd, result.getDetails());
}
this.usedCpu += vmSpec.getCpus() * vmSpec.getMaxSpeed();
this.usedMem += vmSpec.getMaxRam();
_runningVms.put(vmName, new Pair<Long, Long>(Long.valueOf(vmSpec.getCpus() * vmSpec.getMaxSpeed()), vmSpec.getMaxRam()));
return new StartAnswer(cmd);
}
use of com.cloud.agent.api.to.VirtualMachineTO in project cloudstack by apache.
the class XenServer610MigrateWithStorageReceiveCommandWrapper method execute.
@Override
public Answer execute(final MigrateWithStorageReceiveCommand command, final XenServer610Resource xenServer610Resource) {
final Connection connection = xenServer610Resource.getConnection();
final VirtualMachineTO vmSpec = command.getVirtualMachine();
final List<Pair<VolumeTO, String>> volumeToStorageUuid = command.getVolumeToStorageUuid();
try {
// In a cluster management server setup, the migrate with storage receive and send
// commands and answers may have to be forwarded to another management server. This
// happens when the host/resource on which the command has to be executed is owned
// by the second management server. The serialization/deserialization of the command
// and answers fails as the xapi SR and Network class type isn't understand by the
// agent attache. Seriliaze the SR and Network objects here to a string and pass in
// the answer object. It'll be deserialzed and object created in migrate with
// storage send command execution.
Gson gson = new Gson();
// Get a map of all the SRs to which the vdis will be migrated.
final List<Pair<VolumeTO, Object>> volumeToSr = new ArrayList<>();
for (final Pair<VolumeTO, String> entry : volumeToStorageUuid) {
final String storageUuid = entry.second();
final SR sr = xenServer610Resource.getStorageRepository(connection, storageUuid);
volumeToSr.add(new Pair<VolumeTO, Object>(entry.first(), sr));
}
// Get the list of networks to which the vifs will attach.
final List<Pair<NicTO, Object>> nicToNetwork = new ArrayList<Pair<NicTO, Object>>();
for (final NicTO nicTo : vmSpec.getNics()) {
final Network network = xenServer610Resource.getNetwork(connection, nicTo);
nicToNetwork.add(new Pair<NicTO, Object>(nicTo, network));
}
final XsLocalNetwork nativeNetworkForTraffic = xenServer610Resource.getNativeNetworkForTraffic(connection, TrafficType.Storage, null);
final Network network = nativeNetworkForTraffic.getNetwork();
final XsHost xsHost = xenServer610Resource.getHost();
final String uuid = xsHost.getUuid();
final Map<String, String> other = new HashMap<String, String>();
other.put("live", "true");
final Host host = Host.getByUuid(connection, uuid);
final Map<String, String> token = host.migrateReceive(connection, network, other);
return new MigrateWithStorageReceiveAnswer(command, volumeToSr, nicToNetwork, token);
} catch (final CloudRuntimeException e) {
s_logger.error("Migration of vm " + vmSpec.getName() + " with storage failed due to " + e.toString(), e);
return new MigrateWithStorageReceiveAnswer(command, e);
} catch (final Exception e) {
s_logger.error("Migration of vm " + vmSpec.getName() + " with storage failed due to " + e.toString(), e);
return new MigrateWithStorageReceiveAnswer(command, e);
}
}
Aggregations