Search in sources :

Example 26 with VmNetworkInterface

use of org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface in project ovirt-engine by oVirt.

the class RunVmCommandBase method initParametersForExternalNetworks.

protected void initParametersForExternalNetworks(VDS vds, boolean isMigration) {
    for (VmNetworkInterface iface : getVm().getInterfaces()) {
        VnicProfile vnicProfile = vnicProfileDao.get(iface.getVnicProfileId());
        Network network = networkHelper.getNetworkByVnicProfile(vnicProfile);
        if (network != null && network.isExternal() && iface.isPlugged()) {
            Provider<?> provider = providerDao.get(network.getProvidedBy().getProviderId());
            NetworkProviderProxy providerProxy = providerProxyFactory.create(provider);
            Map<String, String> deviceProperties = providerProxy.allocate(network, vnicProfile, iface, vds, isMigration);
            getVm().getRuntimeDeviceCustomProperties().put(new VmDeviceId(iface.getId(), getVmId()), deviceProperties);
        }
    }
}
Also used : VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) Network(org.ovirt.engine.core.common.businessentities.network.Network) VnicProfile(org.ovirt.engine.core.common.businessentities.network.VnicProfile) NetworkProviderProxy(org.ovirt.engine.core.bll.provider.network.NetworkProviderProxy) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Example 27 with VmNetworkInterface

use of org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface in project ovirt-engine by oVirt.

the class ExternalVmMacsFinder method findExternalMacAddresses.

public Set<String> findExternalMacAddresses(VM vm) {
    final List<VmNetworkInterface> interfaces = vm.getInterfaces();
    if (interfaces == null) {
        return Collections.emptySet();
    }
    final ReadMacPool readMacPool = macPoolPerCluster.getMacPoolForCluster(vm.getClusterId());
    return interfaces.stream().map(VmNetworkInterface::getMacAddress).filter(Objects::nonNull).filter(((Predicate<String>) readMacPool::isMacInRange).negate()).collect(Collectors.toSet());
}
Also used : VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) ReadMacPool(org.ovirt.engine.core.bll.network.macpool.ReadMacPool) Objects(java.util.Objects) Predicate(java.util.function.Predicate)

Example 28 with VmNetworkInterface

use of org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface in project ovirt-engine by oVirt.

the class RemoveVmTemplateInterfaceCommand method executeCommand.

@Override
protected void executeCommand() {
    VmNetworkInterface iface = vmNetworkInterfaceDao.get(getParameters().getInterfaceId());
    if (iface != null) {
        addCustomValue("InterfaceName", iface.getName());
        addCustomValue("InterfaceType", VmInterfaceType.forValue(iface.getType()).getDescription());
    }
    vmDeviceDao.remove(new VmDeviceId(getParameters().getInterfaceId(), getParameters().getVmTemplateId()));
    vmNicDao.remove(getParameters().getInterfaceId());
    setSucceeded(true);
}
Also used : VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Example 29 with VmNetworkInterface

use of org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface in project ovirt-engine by oVirt.

the class GetVmsAndNetworkInterfacesByNetworkIdQuery method executeQueryCommand.

@Override
protected void executeQueryCommand() {
    List<VM> vmList = vmDao.getAllForNetwork(getParameters().getId());
    List<VmNetworkInterface> vmNetworkInterfaceList = vmNetworkInterfaceDao.getAllForNetwork(getParameters().getId());
    final Map<Guid, VM> vmsById = Entities.businessEntitiesById(vmList);
    List<PairQueryable<VmNetworkInterface, VM>> vmInterfaceVmPairs = new ArrayList<>();
    for (VmNetworkInterface vmNetworkInterface : vmNetworkInterfaceList) {
        VM vm = vmsById.get(vmNetworkInterface.getVmId());
        if (getParameters().getRunningVms() == null || getParameters().getRunningVms().equals(vm.isRunning())) {
            vmInterfaceVmPairs.add(new PairQueryable<>(vmNetworkInterface, vm));
        }
    }
    getQueryReturnValue().setReturnValue(vmInterfaceVmPairs);
}
Also used : PairQueryable(org.ovirt.engine.core.common.utils.PairQueryable) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) VM(org.ovirt.engine.core.common.businessentities.VM) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid)

Example 30 with VmNetworkInterface

use of org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface in project ovirt-engine by oVirt.

the class NetworkPolicyUnit method filter.

@Override
public List<VDS> filter(Cluster cluster, List<VDS> hosts, VM vm, Map<String, String> parameters, PerHostMessages messages) {
    if (hosts == null || hosts.isEmpty()) {
        return Collections.emptyList();
    }
    List<VDS> toRemoveHostList = new ArrayList<>();
    List<VmNetworkInterface> vmNICs = vmNetworkInterfaceDao.getAllForVm(vm.getId());
    Guid clusterId = hosts.get(0).getClusterId();
    List<Network> clusterNetworks = networkDao.getAllForCluster(clusterId);
    Map<String, Network> networksByName = Entities.entitiesByName(clusterNetworks);
    Map<Guid, List<String>> hostNics = interfaceDao.getHostNetworksByCluster(clusterId);
    Network displayNetwork = NetworkUtils.getDisplayNetwork(clusterNetworks);
    Map<Guid, VdsNetworkInterface> hostDisplayNics = getDisplayNics(displayNetwork);
    for (VDS host : hosts) {
        ValidationResult result = validateRequiredNetworksAvailable(host, vm, vmNICs, displayNetwork, networksByName, hostNics.get(host.getId()), hostDisplayNics.get(host.getId()));
        if (result.isValid()) {
            result = validatePassthroughVnics(vm.getId(), host, vmNICs);
        }
        if (!result.isValid()) {
            toRemoveHostList.add(host);
            messages.addMessages(host.getId(), result.getVariableReplacements());
            messages.addMessages(host.getId(), result.getMessagesAsStrings());
        }
    }
    hosts.removeAll(toRemoveHostList);
    return hosts;
}
Also used : VDS(org.ovirt.engine.core.common.businessentities.VDS) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) Network(org.ovirt.engine.core.common.businessentities.network.Network) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

VmNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)115 Test (org.junit.Test)27 ArrayList (java.util.ArrayList)25 Guid (org.ovirt.engine.core.compat.Guid)19 VM (org.ovirt.engine.core.common.businessentities.VM)16 HashMap (java.util.HashMap)11 List (java.util.List)9 Map (java.util.Map)9 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)6 PairQueryable (org.ovirt.engine.core.common.utils.PairQueryable)6 MapVnicsContext (org.ovirt.engine.core.bll.exportimport.vnics.MapVnicsContext)5 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)5 HostNicVfsConfig (org.ovirt.engine.core.common.businessentities.network.HostNicVfsConfig)5 VmNetworkStatistics (org.ovirt.engine.core.common.businessentities.network.VmNetworkStatistics)5 Nic (org.ovirt.engine.api.model.Nic)4 VnicProfileHelper (org.ovirt.engine.core.bll.network.vm.VnicProfileHelper)4 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)4 Network (org.ovirt.engine.core.common.businessentities.network.Network)4 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)4 Collection (java.util.Collection)3