Search in sources :

Example 71 with Vm

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

the class LinkFollowerTest method createVm.

private Vm createVm() {
    Vm vm = new Vm();
    // add an irrelevant link
    Link disksLink = new Link();
    disksLink.setHref("/ovirt-engine/api/vms/63978315-2d17-4e67-b393-2ea60a8aeacb/diskattachments");
    disksLink.setRel("diskattachments");
    vm.getLinks().add(disksLink);
    Link nicsLink = new Link();
    nicsLink.setHref("/ovirt-engine/api/vms/63978315-2d17-4e67-b393-2ea60a8aeacb/nics");
    nicsLink.setRel("nics");
    vm.getLinks().add(nicsLink);
    return vm;
}
Also used : Vm(org.ovirt.engine.api.model.Vm) Link(org.ovirt.engine.api.model.Link)

Example 72 with Vm

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

the class LinkHelperTest method testNicLinks.

@Test
public void testNicLinks() throws Exception {
    Nic nic = new Nic();
    nic.setId(NIC_ID);
    nic.setVm(new Vm());
    nic.getVm().setId(VM_ID);
    LinkHelper.addLinks(nic);
    assertEquals(NIC_HREF, nic.getHref());
}
Also used : Vm(org.ovirt.engine.api.model.Vm) Nic(org.ovirt.engine.api.model.Nic) Test(org.junit.Test)

Example 73 with Vm

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

the class LinkHelperTest method doTestVmLinks.

private void doTestVmLinks(boolean suggestParent) throws Exception {
    Vm vm = new Vm();
    vm.setId(VM_ID);
    vm.setCluster(new Cluster());
    vm.getCluster().setId(CLUSTER_ID);
    vm.setTemplate(new Template());
    vm.getTemplate().setId(TEMPLATE_ID);
    vm.setVmPool(new VmPool());
    vm.getVmPool().setId(VM_POOL_ID);
    if (suggestParent) {
        LinkHelper.addLinks(vm, Vm.class);
    } else {
        LinkHelper.addLinks(vm);
    }
    assertEquals(VM_HREF, vm.getHref());
    assertEquals(CLUSTER_HREF, vm.getCluster().getHref());
    assertEquals(TEMPLATE_HREF, vm.getTemplate().getHref());
    assertEquals(VM_POOL_HREF, vm.getVmPool().getHref());
}
Also used : VmPool(org.ovirt.engine.api.model.VmPool) Vm(org.ovirt.engine.api.model.Vm) Cluster(org.ovirt.engine.api.model.Cluster) Template(org.ovirt.engine.api.model.Template)

Example 74 with Vm

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

the class AffinityGroupMapper method map.

@Mapping(from = org.ovirt.engine.core.common.scheduling.AffinityGroup.class, to = AffinityGroup.class)
public static AffinityGroup map(org.ovirt.engine.core.common.scheduling.AffinityGroup entity, AffinityGroup template) {
    AffinityGroup model = template != null ? template : new AffinityGroup();
    model.setId(entity.getId().toString());
    model.setName(entity.getName());
    model.setDescription(entity.getDescription());
    // These two fields are maintained to keep the backwards compatibility
    // with version 4 of the API and will be removed in future.
    model.setPositive(entity.isVmAffinityEnabled() ? entity.getVmPolarityBooleanObject() : null);
    model.setEnforcing(entity.isVmEnforcing());
    AffinityRule hostsRule = model.getHostsRule();
    if (hostsRule == null) {
        hostsRule = new AffinityRule();
        model.setHostsRule(hostsRule);
    }
    hostsRule.setEnabled(entity.isVdsAffinityEnabled());
    hostsRule.setEnforcing(entity.isVdsEnforcing());
    hostsRule.setPositive(entity.isVdsPositive());
    AffinityRule vmsRule = model.getVmsRule();
    if (vmsRule == null) {
        vmsRule = new AffinityRule();
        model.setVmsRule(vmsRule);
    }
    vmsRule.setEnabled(entity.isVmAffinityEnabled());
    vmsRule.setEnforcing(entity.isVmEnforcing());
    vmsRule.setPositive(entity.isVmPositive());
    Cluster cluster = new Cluster();
    cluster.setId(entity.getClusterId().toString());
    model.setCluster(cluster);
    Hosts hosts = model.getHosts();
    if (hosts == null) {
        hosts = new Hosts();
        model.setHosts(hosts);
    }
    entity.getVdsIds().stream().map(id -> {
        Host host = new Host();
        host.setId(id.toString());
        return host;
    }).forEach(model.getHosts().getHosts()::add);
    Vms vms = model.getVms();
    if (vms == null) {
        vms = new Vms();
        model.setVms(vms);
    }
    entity.getVmIds().stream().map(id -> {
        Vm vm = new Vm();
        vm.setId(id.toString());
        return vm;
    }).forEach(model.getVms().getVms()::add);
    return model;
}
Also used : AffinityGroup(org.ovirt.engine.api.model.AffinityGroup) Hosts(org.ovirt.engine.api.model.Hosts) List(java.util.List) Host(org.ovirt.engine.api.model.Host) Guid(org.ovirt.engine.core.compat.Guid) AffinityRule(org.ovirt.engine.api.model.AffinityRule) EntityAffinityRule(org.ovirt.engine.core.common.scheduling.EntityAffinityRule) Vm(org.ovirt.engine.api.model.Vm) Cluster(org.ovirt.engine.api.model.Cluster) GuidUtils(org.ovirt.engine.api.restapi.utils.GuidUtils) ArrayList(java.util.ArrayList) Vms(org.ovirt.engine.api.model.Vms) Hosts(org.ovirt.engine.api.model.Hosts) AffinityRule(org.ovirt.engine.api.model.AffinityRule) EntityAffinityRule(org.ovirt.engine.core.common.scheduling.EntityAffinityRule) Vm(org.ovirt.engine.api.model.Vm) Cluster(org.ovirt.engine.api.model.Cluster) Host(org.ovirt.engine.api.model.Host) Vms(org.ovirt.engine.api.model.Vms) AffinityGroup(org.ovirt.engine.api.model.AffinityGroup)

Example 75 with Vm

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

the class AffinityGroupMapperTest method testVmIdsReplacement.

@Test
public void testVmIdsReplacement() throws Exception {
    AffinityGroup model = new AffinityGroup();
    Vm vm = new Vm();
    final Guid vmGuid = Guid.newGuid();
    vm.setId(vmGuid.toString());
    model.setVms(new Vms());
    model.getVms().getVms().add(vm);
    org.ovirt.engine.core.common.scheduling.AffinityGroup entity = new org.ovirt.engine.core.common.scheduling.AffinityGroup();
    entity.getVdsIds().add(Guid.newGuid());
    AffinityGroupMapper.map(model, entity);
    assertEquals(vmGuid, entity.getVmIds().get(0));
    assertEquals(1, entity.getVmIds().size());
}
Also used : Vm(org.ovirt.engine.api.model.Vm) Guid(org.ovirt.engine.core.compat.Guid) Vms(org.ovirt.engine.api.model.Vms) AffinityGroup(org.ovirt.engine.api.model.AffinityGroup) Test(org.junit.Test)

Aggregations

Vm (org.ovirt.engine.api.model.Vm)145 Test (org.junit.Test)80 Response (javax.ws.rs.core.Response)26 Host (org.ovirt.engine.api.model.Host)21 WebApplicationException (javax.ws.rs.WebApplicationException)19 Guid (org.ovirt.engine.core.compat.Guid)15 Template (org.ovirt.engine.api.model.Template)11 Hosts (org.ovirt.engine.api.model.Hosts)10 Action (org.ovirt.engine.api.model.Action)9 VmPlacementPolicy (org.ovirt.engine.api.model.VmPlacementPolicy)9 Vms (org.ovirt.engine.api.model.Vms)8 RunVmOnceParams (org.ovirt.engine.core.common.action.RunVmOnceParams)8 VM (org.ovirt.engine.core.common.businessentities.VM)8 Disk (org.ovirt.engine.api.model.Disk)7 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)7 ArrayList (java.util.ArrayList)6 Nic (org.ovirt.engine.api.model.Nic)6 VmManagementParametersBase (org.ovirt.engine.core.common.action.VmManagementParametersBase)6 Configuration (org.ovirt.engine.api.model.Configuration)5 DiskAttachment (org.ovirt.engine.api.model.DiskAttachment)5