use of org.ovirt.engine.ui.uicommonweb.models.vms.register.VnicProfileMappingEntity in project ovirt-engine by oVirt.
the class RegisterEntityModel method updateExternalVnicProfilesPerTargetCluster.
/**
* on first call: create new mappings with no target profile for each interface of the entities being registered.
* on subsequent calls: repopulate with existing mappings and user selections
*/
private Map<Cluster, Set<VnicProfileMappingEntity>> updateExternalVnicProfilesPerTargetCluster() {
Map<Cluster, Set<VnicProfileMappingEntity>> updated = new HashMap<>();
// the update may be for several VMs or VmTemplates over various clusters
for (E importEntityData : getEntities().getItems()) {
Cluster cluster = importEntityData.getCluster().getSelectedItem();
// get the set of profiles being updated for the cluster or create new
Set<VnicProfileMappingEntity> clusterVnicProfileMappings;
if (updated.containsKey(cluster)) {
clusterVnicProfileMappings = updated.get(cluster);
} else {
clusterVnicProfileMappings = new HashSet<>();
updated.put(cluster, clusterVnicProfileMappings);
}
// get the previous set of profiles for the cluster or create new
Set<VnicProfileMappingEntity> previousClusterVnicProfileMappings;
if (externalVnicProfilesPerTargetCluster.containsKey(cluster)) {
previousClusterVnicProfileMappings = externalVnicProfilesPerTargetCluster.get(cluster);
} else {
previousClusterVnicProfileMappings = new HashSet<>();
}
// create or set mappings according to currently existing interfaces and previous user selections
Set<VnicProfileMappingEntity> vmVnicProfiles = getNewVnicProfileMappings(getInterfaces(importEntityData), previousClusterVnicProfileMappings);
clusterVnicProfileMappings.addAll(vmVnicProfiles);
}
return updated;
}
use of org.ovirt.engine.ui.uicommonweb.models.vms.register.VnicProfileMappingEntity in project ovirt-engine by oVirt.
the class RegisterEntityModel method getNewVnicProfileMappings.
/**
* create a {@link VnicProfileMappingEntity} with no target profile for each pre-loaded interface of the registered entity
* if a previous mapping for the same source profile is not found.
*
* @param interfaces the interfaces of the registered entity initially loaded by the frontend when the register action started
* @param previousClusterVnicProfileMappings the mappings passed to {@link VnicProfileMappingModel}, with user selections of target profiles
* @return a set of mappings for all interfaces of registered entity
*/
private Set<VnicProfileMappingEntity> getNewVnicProfileMappings(List<VmNetworkInterface> interfaces, Set<VnicProfileMappingEntity> previousClusterVnicProfileMappings) {
Set<VnicProfileMappingEntity> result = new HashSet<>();
for (VmNetworkInterface vnic : interfaces) {
VnicProfileMappingEntity newMapping = new VnicProfileMappingEntity(vnic.getNetworkName(), vnic.getVnicProfileName(), null);
VnicProfileMappingEntity mapping = previousClusterVnicProfileMappings.stream().filter(x -> x.isSameSourceProfile(newMapping)).findFirst().orElse(newMapping);
// warning: the Set.add() uses the equals of {@link VnicProfileMappingEntity} which only compares the source profile
result.add(mapping);
}
return result;
}
Aggregations