use of org.ovirt.engine.api.model.VnicProfile in project ovirt-engine by oVirt.
the class AbstractBackendVnicProfilesResource method mapCollection.
protected VnicProfiles mapCollection(List<org.ovirt.engine.core.common.businessentities.network.VnicProfile> entities) {
VnicProfiles collection = new VnicProfiles();
Map<Guid, Qos> qosMap = new HashMap<>();
for (org.ovirt.engine.core.common.businessentities.network.VnicProfile entity : entities) {
VnicProfile profile = populate(map(entity), entity);
collection.getVnicProfiles().add(profile);
if (entity.getNetworkQosId() != null) {
qosMap.put(entity.getNetworkQosId(), profile.getQos());
}
}
handleQosDataCenterLinks(qosMap);
for (VnicProfile vnicProfile : collection.getVnicProfiles()) {
addLinks(vnicProfile);
}
return collection;
}
use of org.ovirt.engine.api.model.VnicProfile in project ovirt-engine by oVirt.
the class V3NICHelper method setNetworkAndPortMirroring.
/**
* Populates the {@code network} and {@code port_mirroring} attributes used in V3.
*
* @param v4Nic the V4 NIC where the details of the NIC profile will be extracted from
* @param v3Nic the V3 NIC object that will be populated
*/
public static void setNetworkAndPortMirroring(Nic v4Nic, V3NIC v3Nic) {
// Do nothing if the V4 NIC doesn't specify a profile:
VnicProfile v4Profile = v4Nic.getVnicProfile();
if (v4Profile == null) {
return;
}
// Retrieve the complete representation of the profile, as we need it to compute the "network" and
// "port_mirroring" attributes used in V3:
BackendApiResource systemService = BackendApiResource.getInstance();
VnicProfilesResource profilesService = systemService.getVnicProfilesResource();
VnicProfileResource profileService = profilesService.getProfileResource(v4Profile.getId());
v4Profile = profileService.get();
// Populate the "network" and "port_mirroring" attributes of the V3 object:
Network v4Network = v4Profile.getNetwork();
V3Network v3Network = new V3Network();
v3Network.setId(v4Network.getId());
v4Network.setHref(v4Network.getHref());
v3Nic.setNetwork(v3Network);
if (v4Profile.isSetPortMirroring() && v4Profile.isPortMirroring()) {
V3PortMirroring v3PortMirroring = new V3PortMirroring();
V3Networks v3PortMirroringNetworks = new V3Networks();
V3Network v3PortMirroringNetwork = new V3Network();
v3PortMirroringNetwork.setId(v4Network.getId());
v3PortMirroringNetwork.setHref(v4Network.getHref());
v3PortMirroringNetworks.getNetworks().add(v3PortMirroringNetwork);
v3PortMirroring.setNetworks(v3PortMirroringNetworks);
v3Nic.setPortMirroring(v3PortMirroring);
}
}
use of org.ovirt.engine.api.model.VnicProfile 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);
});
}
use of org.ovirt.engine.api.model.VnicProfile in project ovirt-engine by oVirt.
the class V3VnicProfileInAdapter method adapt.
@Override
public VnicProfile adapt(V3VnicProfile from) {
VnicProfile to = new VnicProfile();
if (from.isSetLinks()) {
to.getLinks().addAll(adaptIn(from.getLinks()));
}
if (from.isSetActions()) {
to.setActions(adaptIn(from.getActions()));
}
if (from.isSetComment()) {
to.setComment(from.getComment());
}
if (from.isSetCustomProperties()) {
to.setCustomProperties(new CustomProperties());
to.getCustomProperties().getCustomProperties().addAll(adaptIn(from.getCustomProperties().getCustomProperty()));
}
if (from.isSetDescription()) {
to.setDescription(from.getDescription());
}
if (from.isSetId()) {
to.setId(from.getId());
}
if (from.isSetHref()) {
to.setHref(from.getHref());
}
if (from.isSetName()) {
to.setName(from.getName());
}
if (from.isSetNetwork()) {
to.setNetwork(adaptIn(from.getNetwork()));
}
if (from.isSetPassThrough()) {
to.setPassThrough(adaptIn(from.getPassThrough()));
}
if (from.isSetPortMirroring()) {
to.setPortMirroring(from.isPortMirroring());
}
if (from.isSetQos()) {
to.setQos(adaptIn(from.getQos()));
}
return to;
}
use of org.ovirt.engine.api.model.VnicProfile in project ovirt-engine by oVirt.
the class BackendVnicProfileResourceTest method testConflictedUpdate.
@Test
public void testConflictedUpdate() throws Exception {
setUriInfo(setUpBasicUriExpectations());
setUpEntityQueryExpectations(1, 0, false);
VnicProfile model = getModel(1);
model.setId(GUIDS[1].toString());
try {
BackendVnicProfileResource resource = (BackendVnicProfileResource) this.resource;
resource.update(model);
fail("expected WebApplicationException");
} catch (WebApplicationException wae) {
verifyImmutabilityConstraint(wae);
}
}
Aggregations