Search in sources :

Example 1 with Nic

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

the class BackendInstanceTypeNicsResourceTest method getModel.

static Nic getModel(int index) {
    Nic model = new Nic();
    model.setName(NAMES[index]);
    model.setInterface(NicInterface.RTL8139_VIRTIO);
    return model;
}
Also used : Nic(org.ovirt.engine.api.model.Nic)

Example 2 with Nic

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

the class BackendInstanceTypeNicsResourceTest method doTestBadAddNic.

private void doTestBadAddNic(boolean valid, boolean success, String detail) throws Exception {
    setUriInfo(setUpActionExpectations(ActionType.AddVmTemplateInterface, AddVmTemplateInterfaceParameters.class, new String[] { "VmTemplateId" }, new Object[] { INSTANCE_TYPE_ID }, valid, success));
    Nic model = getModel(0);
    try {
        collection.add(model);
        fail("expected WebApplicationException");
    } catch (WebApplicationException wae) {
        verifyFault(wae, detail);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) Nic(org.ovirt.engine.api.model.Nic) AddVmTemplateInterfaceParameters(org.ovirt.engine.core.common.action.AddVmTemplateInterfaceParameters)

Example 3 with Nic

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

the class BackendInstanceTypeNicsResourceTest method testAddIncompleteParameters.

@Test
public void testAddIncompleteParameters() throws Exception {
    Nic model = new Nic();
    model.setName(null);
    setUriInfo(setUpBasicUriExpectations());
    try {
        collection.add(model);
        fail("expected WebApplicationException on incomplete parameters");
    } catch (WebApplicationException wae) {
        verifyIncompleteException(wae, "Nic", "add", "name");
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) Nic(org.ovirt.engine.api.model.Nic) Test(org.junit.Test)

Example 4 with Nic

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

the class BackendInstanceTypeNicsResourceTest method testAddNic.

@Test
public void testAddNic() throws Exception {
    setUriInfo(setUpBasicUriExpectations());
    setUpCreationExpectations(ActionType.AddVmTemplateInterface, AddVmTemplateInterfaceParameters.class, new String[] {}, new Object[] {}, true, true, null, QueryType.GetTemplateInterfacesByTemplateId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { INSTANCE_TYPE_ID }, asList(getEntity(0)));
    Nic model = getModel(0);
    Response response = collection.add(model);
    assertEquals(201, response.getStatus());
    assertTrue(response.getEntity() instanceof Nic);
    verifyModel((Nic) response.getEntity(), 0);
}
Also used : Response(javax.ws.rs.core.Response) Nic(org.ovirt.engine.api.model.Nic) Test(org.junit.Test)

Example 5 with Nic

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

the class V3NICHelper method setVnicProfile.

/**
 * Finds the VNIC profile that correspond to the given V3 NIC and assigns it to the given V4 NIC.
 *
 * @param vmId the identifier of the virtual machine that the NIC is going to be added to
 * @param v3Nic the V3 NIC where the information will be extracted from
 * @param v4Nic the V4 NIC that will be populated
 */
public static void setVnicProfile(String vmId, V3NIC v3Nic, Nic v4Nic) {
    // Do nothing if the profile is already set:
    if (v4Nic.isSetVnicProfile()) {
        return;
    }
    // In version 4 of the API the "network" and "port_mirroring" properties of the NIC have been completely
    // removed, and instead of using them it is required to specify a VNIC profile. This means that if the user
    // isn't explicitly indicating the VNIC profile we need to find one that is compatible with the given network
    // and port mirroring configuration. The only VNIC profiles to consider are the ones corresponding to the
    // networks of the cluster where the VM resides, so we need to retrieve the VM, then the cluster, and then the
    // identifiers of the networks:
    SystemResource systemService = BackendApiResource.getInstance();
    VmsResource vmsService = systemService.getVmsResource();
    VmResource vmService = vmsService.getVmResource(vmId);
    Vm vm = vmService.get();
    ClustersResource clustersService = systemService.getClustersResource();
    ClusterResource clusterService = clustersService.getClusterResource(vm.getCluster().getId());
    ClusterNetworksResource networksService = clusterService.getNetworksResource();
    Set<String> validNetworkIds = networksService.list().getNetworks().stream().map(Network::getId).collect(toSet());
    // Find a VNIC profile that is in the set of valid networks and that is compatible with the NIC:
    VnicProfilesResource profilesService = systemService.getVnicProfilesResource();
    profilesService.list().getVnicProfiles().stream().filter(profile -> validNetworkIds.contains(profile.getNetwork().getId())).filter(profile -> isProfileCompatible(profile, v3Nic)).sorted(comparing(VnicProfile::getName)).map(VnicProfile::getId).findFirst().ifPresent(id -> {
        VnicProfile v4Profile = new VnicProfile();
        v4Profile.setId(id);
        v4Nic.setVnicProfile(v4Profile);
    });
}
Also used : VmResource(org.ovirt.engine.api.resource.VmResource) VnicProfilesResource(org.ovirt.engine.api.resource.VnicProfilesResource) VnicProfileResource(org.ovirt.engine.api.resource.VnicProfileResource) BackendApiResource(org.ovirt.engine.api.restapi.resource.BackendApiResource) SystemResource(org.ovirt.engine.api.resource.SystemResource) V3NIC(org.ovirt.engine.api.v3.types.V3NIC) V3PortMirroring(org.ovirt.engine.api.v3.types.V3PortMirroring) Vm(org.ovirt.engine.api.model.Vm) Set(java.util.Set) ClusterResource(org.ovirt.engine.api.resource.ClusterResource) NetworkResource(org.ovirt.engine.api.resource.NetworkResource) V3Network(org.ovirt.engine.api.v3.types.V3Network) VnicProfile(org.ovirt.engine.api.model.VnicProfile) Objects(java.util.Objects) V3Networks(org.ovirt.engine.api.v3.types.V3Networks) Nic(org.ovirt.engine.api.model.Nic) ClusterNetworksResource(org.ovirt.engine.api.resource.ClusterNetworksResource) Network(org.ovirt.engine.api.model.Network) VnicProfilesResource(org.ovirt.engine.api.resource.VnicProfilesResource) Comparator.comparing(java.util.Comparator.comparing) NetworksResource(org.ovirt.engine.api.resource.NetworksResource) VmResource(org.ovirt.engine.api.resource.VmResource) Collectors.toSet(java.util.stream.Collectors.toSet) VmsResource(org.ovirt.engine.api.resource.VmsResource) ClustersResource(org.ovirt.engine.api.resource.ClustersResource) VmsResource(org.ovirt.engine.api.resource.VmsResource) Vm(org.ovirt.engine.api.model.Vm) VnicProfile(org.ovirt.engine.api.model.VnicProfile) SystemResource(org.ovirt.engine.api.resource.SystemResource) ClusterNetworksResource(org.ovirt.engine.api.resource.ClusterNetworksResource) ClustersResource(org.ovirt.engine.api.resource.ClustersResource) ClusterResource(org.ovirt.engine.api.resource.ClusterResource)

Aggregations

Nic (org.ovirt.engine.api.model.Nic)33 Test (org.junit.Test)11 WebApplicationException (javax.ws.rs.WebApplicationException)8 Vm (org.ovirt.engine.api.model.Vm)6 Nics (org.ovirt.engine.api.model.Nics)5 VmNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)4 Response (javax.ws.rs.core.Response)3 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)3 ArrayList (java.util.ArrayList)2 Mac (org.ovirt.engine.api.model.Mac)2 Network (org.ovirt.engine.api.model.Network)2 ReportedDevices (org.ovirt.engine.api.model.ReportedDevices)2 VnicProfile (org.ovirt.engine.api.model.VnicProfile)2 SystemResource (org.ovirt.engine.api.resource.SystemResource)2 VmResource (org.ovirt.engine.api.resource.VmResource)2 VmsResource (org.ovirt.engine.api.resource.VmsResource)2 AddVmInterfaceParameters (org.ovirt.engine.core.common.action.AddVmInterfaceParameters)2 AddVmTemplateInterfaceParameters (org.ovirt.engine.core.common.action.AddVmTemplateInterfaceParameters)2 Comparator.comparing (java.util.Comparator.comparing)1 Objects (java.util.Objects)1