Search in sources :

Example 6 with VmPlacementPolicy

use of org.ovirt.engine.api.model.VmPlacementPolicy in project ovirt-engine by oVirt.

the class VmMapperTest method createPlacementPolicy.

private VmPlacementPolicy createPlacementPolicy(Guid... guids) {
    VmPlacementPolicy placementPolicy = new VmPlacementPolicy();
    Hosts hostsList = new Hosts();
    for (Guid guid : guids) {
        Host newHost = new Host();
        newHost.setId(guid.toString());
        hostsList.getHosts().add(newHost);
    }
    placementPolicy.setHosts(hostsList);
    return placementPolicy;
}
Also used : Hosts(org.ovirt.engine.api.model.Hosts) Host(org.ovirt.engine.api.model.Host) Guid(org.ovirt.engine.core.compat.Guid) VmPlacementPolicy(org.ovirt.engine.api.model.VmPlacementPolicy)

Example 7 with VmPlacementPolicy

use of org.ovirt.engine.api.model.VmPlacementPolicy in project ovirt-engine by oVirt.

the class BackendVmsResourceTest method testAddWithPlacementPolicyHostsNames.

@Test
public void testAddWithPlacementPolicyHostsNames() throws Exception {
    setUpAddVm();
    for (int i = 0; i < NAMES.length; i++) {
        setUpGetHostByNameExpectations(i);
    }
    setUpCreationExpectations(ActionType.AddVm, AddVmParameters.class, new String[] { "StorageDomainId" }, new Object[] { GUIDS[0] }, true, true, GUIDS[2], QueryType.GetVmByVmId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[2] }, getEntity(2));
    Vm model = createModel(null);
    model.setPlacementPolicy(new VmPlacementPolicy());
    Hosts hosts = new Hosts();
    for (int i = 0; i < NAMES.length; i++) {
        Host newHost = new Host();
        newHost.setName(NAMES[i]);
        hosts.getHosts().add(newHost);
    }
    model.getPlacementPolicy().setHosts(hosts);
    Response response = collection.add(model);
    assertEquals(201, response.getStatus());
    assertTrue(response.getEntity() instanceof Vm);
    verifyModel((Vm) response.getEntity(), 2);
}
Also used : Response(javax.ws.rs.core.Response) Hosts(org.ovirt.engine.api.model.Hosts) Vm(org.ovirt.engine.api.model.Vm) Host(org.ovirt.engine.api.model.Host) VmPlacementPolicy(org.ovirt.engine.api.model.VmPlacementPolicy) Test(org.junit.Test)

Example 8 with VmPlacementPolicy

use of org.ovirt.engine.api.model.VmPlacementPolicy in project ovirt-engine by oVirt.

the class BackendVmsResourceTest method testAddWithPlacementPolicyHostsIds.

@Test
public void testAddWithPlacementPolicyHostsIds() throws Exception {
    setUpAddVm();
    setUpCreationExpectations(ActionType.AddVm, AddVmParameters.class, new String[] { "StorageDomainId" }, new Object[] { GUIDS[0] }, true, true, GUIDS[2], QueryType.GetVmByVmId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[2] }, getEntity(2));
    Vm model = createModel(null);
    model.setPlacementPolicy(new VmPlacementPolicy());
    Hosts hosts = new Hosts();
    for (int i = 0; i < GUIDS.length; i++) {
        Host newHost = new Host();
        newHost.setId(GUIDS[i].toString());
        hosts.getHosts().add(newHost);
    }
    model.getPlacementPolicy().setHosts(hosts);
    Response response = collection.add(model);
    assertEquals(201, response.getStatus());
    assertTrue(response.getEntity() instanceof Vm);
    verifyModel((Vm) response.getEntity(), 2);
}
Also used : Response(javax.ws.rs.core.Response) Hosts(org.ovirt.engine.api.model.Hosts) Vm(org.ovirt.engine.api.model.Vm) Host(org.ovirt.engine.api.model.Host) VmPlacementPolicy(org.ovirt.engine.api.model.VmPlacementPolicy) Test(org.junit.Test)

Example 9 with VmPlacementPolicy

use of org.ovirt.engine.api.model.VmPlacementPolicy in project ovirt-engine by oVirt.

the class BackendVmsResourceTest method testAddWithPlacementPolicySingleHostId.

@Test
public void testAddWithPlacementPolicySingleHostId() throws Exception {
    setUpAddVm();
    setUpGetConsoleExpectations(1);
    setUpCreationExpectations(ActionType.AddVm, AddVmParameters.class, new String[] { "StorageDomainId" }, new Object[] { GUIDS[0] }, true, true, GUIDS[2], QueryType.GetVmByVmId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[2] }, getEntity(2));
    Vm model = createModel(null);
    model.setPlacementPolicy(new VmPlacementPolicy());
    model.getPlacementPolicy().setHosts(new Hosts());
    model.getPlacementPolicy().getHosts().getHosts().add(new Host());
    model.getPlacementPolicy().getHosts().getHosts().get(0).setId(GUIDS[1].toString());
    Response response = collection.add(model);
    assertEquals(201, response.getStatus());
    assertTrue(response.getEntity() instanceof Vm);
    verifyModel((Vm) response.getEntity(), 2);
}
Also used : Response(javax.ws.rs.core.Response) Hosts(org.ovirt.engine.api.model.Hosts) Vm(org.ovirt.engine.api.model.Vm) Host(org.ovirt.engine.api.model.Host) VmPlacementPolicy(org.ovirt.engine.api.model.VmPlacementPolicy) Test(org.junit.Test)

Example 10 with VmPlacementPolicy

use of org.ovirt.engine.api.model.VmPlacementPolicy in project ovirt-engine by oVirt.

the class VmBaseMapper method mapCommonEntityToModel.

/**
 * Common for VM, template and instance type
 */
protected static void mapCommonEntityToModel(VmBase model, org.ovirt.engine.core.common.businessentities.VmBase entity) {
    model.setId(entity.getId().toString());
    model.setName(entity.getName());
    model.setDescription(entity.getDescription());
    model.setMemory((long) entity.getMemSizeMb() * BYTES_PER_MB);
    Io io = model.getIo();
    if (io == null) {
        io = new Io();
        model.setIo(io);
    }
    io.setThreads(entity.getNumOfIoThreads());
    if (entity.getCreationDate() != null) {
        model.setCreationTime(DateMapper.map(entity.getCreationDate(), null));
    }
    if (entity.getUsbPolicy() != null) {
        Usb usb = new Usb();
        usb.setEnabled(UsbMapperUtils.getIsUsbEnabled(entity.getUsbPolicy()));
        UsbType usbType = UsbMapperUtils.getUsbType(entity.getUsbPolicy());
        if (usbType != null) {
            usb.setType(usbType);
        }
        model.setUsb(usb);
    }
    CpuTopology topology = new CpuTopology();
    topology.setSockets(entity.getNumOfSockets());
    topology.setCores(entity.getCpuPerSocket());
    topology.setThreads(entity.getThreadsPerCpu());
    model.setCpu(new Cpu());
    model.getCpu().setTopology(topology);
    model.setHighAvailability(new HighAvailability());
    model.getHighAvailability().setEnabled(entity.isAutoStartup());
    model.getHighAvailability().setPriority(entity.getPriority());
    model.setMigrationDowntime(mapNullToMinusOne(entity.getMigrationDowntime()));
    model.setMigration(MigrationOptionsMapper.map(entity, null));
    if (entity.getCustomEmulatedMachine() != null) {
        model.setCustomEmulatedMachine(entity.getCustomEmulatedMachine());
    }
    if (entity.getCustomCpuName() != null) {
        model.setCustomCpuModel(entity.getCustomCpuName());
    }
    MemoryPolicy policy = new MemoryPolicy();
    policy.setGuaranteed((long) entity.getMinAllocatedMem() * (long) BYTES_PER_MB);
    policy.setMax((long) entity.getMaxMemorySizeMb() * (long) BYTES_PER_MB);
    model.setMemoryPolicy(policy);
    if (entity.getCustomCompatibilityVersion() != null) {
        model.setCustomCompatibilityVersion(VersionMapper.map(entity.getCustomCompatibilityVersion()));
    }
    model.setLease(StorageDomainLeaseMapper.map(entity.getLeaseStorageDomainId()));
    if (model.getPlacementPolicy() == null) {
        model.setPlacementPolicy(new VmPlacementPolicy());
    }
    VmAffinity vmAffinity = map(entity.getMigrationSupport(), null);
    if (vmAffinity != null) {
        model.getPlacementPolicy().setAffinity(vmAffinity);
    }
    if (!entity.getDedicatedVmForVdsList().isEmpty()) {
        Hosts hostsList = new Hosts();
        for (Guid hostGuid : entity.getDedicatedVmForVdsList()) {
            Host newHost = new Host();
            newHost.setId(hostGuid.toString());
            hostsList.getHosts().add(newHost);
        }
        model.getPlacementPolicy().setHosts(hostsList);
    }
}
Also used : CpuTopology(org.ovirt.engine.api.model.CpuTopology) Hosts(org.ovirt.engine.api.model.Hosts) Usb(org.ovirt.engine.api.model.Usb) UsbType(org.ovirt.engine.api.model.UsbType) Io(org.ovirt.engine.api.model.Io) MemoryPolicy(org.ovirt.engine.api.model.MemoryPolicy) Cpu(org.ovirt.engine.api.model.Cpu) HighAvailability(org.ovirt.engine.api.model.HighAvailability) Host(org.ovirt.engine.api.model.Host) Guid(org.ovirt.engine.core.compat.Guid) VmPlacementPolicy(org.ovirt.engine.api.model.VmPlacementPolicy) VmAffinity(org.ovirt.engine.api.model.VmAffinity)

Aggregations

Hosts (org.ovirt.engine.api.model.Hosts)12 VmPlacementPolicy (org.ovirt.engine.api.model.VmPlacementPolicy)12 Host (org.ovirt.engine.api.model.Host)11 Vm (org.ovirt.engine.api.model.Vm)9 Test (org.junit.Test)8 Response (javax.ws.rs.core.Response)4 VmManagementParametersBase (org.ovirt.engine.core.common.action.VmManagementParametersBase)4 Guid (org.ovirt.engine.core.compat.Guid)2 Action (org.ovirt.engine.api.model.Action)1 Cpu (org.ovirt.engine.api.model.Cpu)1 CpuTopology (org.ovirt.engine.api.model.CpuTopology)1 HighAvailability (org.ovirt.engine.api.model.HighAvailability)1 Io (org.ovirt.engine.api.model.Io)1 MemoryPolicy (org.ovirt.engine.api.model.MemoryPolicy)1 Usb (org.ovirt.engine.api.model.Usb)1 UsbType (org.ovirt.engine.api.model.UsbType)1 VmAffinity (org.ovirt.engine.api.model.VmAffinity)1 V3VmPlacementPolicy (org.ovirt.engine.api.v3.types.V3VmPlacementPolicy)1 RunVmOnceParams (org.ovirt.engine.core.common.action.RunVmOnceParams)1