Search in sources :

Example 26 with VirtualMachineTO

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);
}
Also used : VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) Test(org.junit.Test)

Example 27 with VirtualMachineTO

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();
}
Also used : AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) KVMStoragePoolManager(com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) LibvirtException(org.libvirt.LibvirtException) PrepareForMigrationCommand(com.cloud.agent.api.PrepareForMigrationCommand) Connect(org.libvirt.Connect) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) LibvirtUtilitiesHelper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper) NicTO(com.cloud.agent.api.to.NicTO) DiskTO(com.cloud.agent.api.to.DiskTO) Test(org.junit.Test)

Example 28 with VirtualMachineTO

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;
}
Also used : GuestOSVO(com.cloud.storage.GuestOSVO) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO)

Example 29 with VirtualMachineTO

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);
}
Also used : ReadyAnswer(com.cloud.agent.api.ReadyAnswer) StartAnswer(com.cloud.agent.api.StartAnswer) StopAnswer(com.cloud.agent.api.StopAnswer) Answer(com.cloud.agent.api.Answer) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) StartAnswer(com.cloud.agent.api.StartAnswer) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO)

Example 30 with VirtualMachineTO

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);
    }
}
Also used : XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) VolumeTO(com.cloud.agent.api.to.VolumeTO) XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) Network(com.xensource.xenapi.Network) Pair(com.cloud.utils.Pair) SR(com.xensource.xenapi.SR) NicTO(com.cloud.agent.api.to.NicTO) Connection(com.xensource.xenapi.Connection) Host(com.xensource.xenapi.Host) XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) MigrateWithStorageReceiveAnswer(com.cloud.agent.api.MigrateWithStorageReceiveAnswer)

Aggregations

VirtualMachineTO (com.cloud.agent.api.to.VirtualMachineTO)84 NicTO (com.cloud.agent.api.to.NicTO)42 Test (org.junit.Test)33 Answer (com.cloud.agent.api.Answer)32 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)25 HashMap (java.util.HashMap)18 LibvirtException (org.libvirt.LibvirtException)18 StartAnswer (com.cloud.agent.api.StartAnswer)17 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)17 URISyntaxException (java.net.URISyntaxException)16 Connect (org.libvirt.Connect)16 InternalErrorException (com.cloud.exception.InternalErrorException)15 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)14 KVMStoragePoolManager (com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager)14 Connection (com.xensource.xenapi.Connection)14 ConfigurationException (javax.naming.ConfigurationException)14 LibvirtRequestWrapper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper)13 LibvirtUtilitiesHelper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper)13 StartCommand (com.cloud.agent.api.StartCommand)12 ArrayList (java.util.ArrayList)11