use of org.ovirt.engine.api.resource.ClusterResource 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.resource.ClusterResource in project ovirt-engine by oVirt.
the class BackendGlusterBricksResourceTest method setUpParentMocks.
/**
* The method {@link BackendGlusterBricksResource#list()} internally invokes
* {@link BackendGlusterVolumeResource#get()} to fetch the volume object, and then invokes the query to fetch the
* bricks of that volume. This method mocks the volume resource to return pre-defined volume id
*/
private void setUpParentMocks() {
GlusterVolume volume = new GlusterVolume();
volume.setId(volumeId.toString());
Cluster cluster = new Cluster();
cluster.setId(clusterId.toString());
volume.setCluster(cluster);
ClusterResource clusterResourceMock = mock(ClusterResource.class);
when(clusterResourceMock.get()).thenReturn(cluster);
BackendGlusterVolumesResource volumesResourceMock = mock(BackendGlusterVolumesResource.class);
when(volumesResourceMock.getParent()).thenReturn(clusterResourceMock);
parentMock = mock(BackendGlusterVolumeResource.class);
when(parentMock.getParent()).thenReturn(volumesResourceMock);
when(parentMock.get()).thenReturn(volume);
collection.setParent(parentMock);
doAnswer(invocation -> {
GlusterVolume model = (GlusterVolume) invocation.getArguments()[0];
Cluster clusterModel = new Cluster();
clusterModel.setId(clusterId.toString());
model.setCluster(clusterModel);
model.setId(volumeId.toString());
return model;
}).when(parentMock).addParents(isA(GlusterVolume.class));
}
use of org.ovirt.engine.api.resource.ClusterResource in project ovirt-engine by oVirt.
the class BackendGlusterVolumesResourceTest method setupListExpectations.
/**
* The method {@link BackendGlusterVolumesResource#list()} internally
* invokes {@link ClusterResource#get()} to fetch the cluster object,
* and then invokes the query including the default constraint on cluster name.
* This method mocks the cluster resource in such a way that the cluster
* name will be returned as "Default"
*/
private void setupListExpectations() {
Cluster cluster = new Cluster();
cluster.setName(defaultClusterName);
cluster.setId(clusterId.toString());
parentMock = mock(ClusterResource.class);
when(parentMock.get()).thenReturn(cluster);
}
Aggregations