Search in sources :

Example 1 with VmNic

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

the class AddVmCommand method addVmNetwork.

protected void addVmNetwork() {
    List<? extends VmNic> nics = getVmInterfaces();
    VmInterfaceManager vmInterfaceManager = new VmInterfaceManager(getMacPool());
    vmInterfaceManager.sortVmNics(nics, getVmInterfaceDevices());
    List<String> macAddresses = getMacPool().allocateMacAddresses(nics.size());
    // Add interfaces from template
    for (int i = 0; i < nics.size(); ++i) {
        VmNic iface = nics.get(i);
        Guid id = Guid.newGuid();
        srcVmNicIdToTargetVmNicIdMapping.put(iface.getId(), id);
        iface.setId(id);
        iface.setMacAddress(macAddresses.get(i));
        iface.setSpeed(VmInterfaceType.forValue(iface.getType()).getSpeed());
        iface.setVmTemplateId(null);
        iface.setVmId(getParameters().getVmStaticData().getId());
        updateProfileOnNic(iface);
        vmNicDao.save(iface);
        getCompensationContext().snapshotNewEntity(iface);
        vmNetworkStatisticsDao.save(iface.getStatistics());
        getCompensationContext().snapshotNewEntity(iface.getStatistics());
    }
}
Also used : Guid(org.ovirt.engine.core.compat.Guid) VmInterfaceManager(org.ovirt.engine.core.bll.network.VmInterfaceManager) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic)

Example 2 with VmNic

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

the class RemoveStoragePoolCommand method removeNetworks.

private void removeNetworks() {
    final List<Network> networks = networkDao.getAllForDataCenter(getStoragePoolId());
    for (Network network : networks) {
        if (network.isExternal()) {
            for (VmNic nic : vmNicDao.getAllForNetwork(network.getId())) {
                externalNetworkManagerFactory.create(nic, network).deallocateIfExternal();
            }
        }
    }
    TransactionSupport.executeInNewTransaction(() -> {
        for (final Network net : networks) {
            List<VnicProfile> profiles = vnicProfileDao.getAllForNetwork(net.getId());
            for (VnicProfile vnicProfile : profiles) {
                getCompensationContext().snapshotEntity(vnicProfile);
                vnicProfileDao.remove(vnicProfile.getId());
            }
            getCompensationContext().snapshotEntity(net);
            networkDao.remove(net.getId());
        }
        getCompensationContext().stateChanged();
        return null;
    });
}
Also used : Network(org.ovirt.engine.core.common.businessentities.network.Network) VnicProfile(org.ovirt.engine.core.common.businessentities.network.VnicProfile) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic)

Example 3 with VmNic

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

the class HotPlugOrUnplugNicVDSCommand method generateDomainXml.

private String generateDomainXml() {
    VmNic nic = getParameters().getNic();
    VmDevice vmDevice = getParameters().getVmDevice();
    LibvirtVmXmlBuilder builder = new LibvirtVmXmlBuilder(getParameters().getVm(), getVds().getId(), nic, vmDevice, vmInfoBuildUtils, nic.isPassthrough() ? Collections.singletonMap(nic.getId(), vmDevice.getHostDevice()) : Collections.emptyMap());
    String libvirtXml = builder.buildHotplugNic();
    String prettyLibvirtXml = XmlUtils.prettify(libvirtXml);
    if (prettyLibvirtXml != null) {
        log.info("NIC hot-set: {}", prettyLibvirtXml);
    }
    return libvirtXml;
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic) LibvirtVmXmlBuilder(org.ovirt.engine.core.vdsbroker.builder.vminfo.LibvirtVmXmlBuilder)

Example 4 with VmNic

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

the class UpdateVmCommand method updateVmNetworks.

private void updateVmNetworks() {
    // check if the cluster has changed
    if (!Objects.equals(getVm().getClusterId(), getParameters().getVmStaticData().getClusterId())) {
        List<Network> networks = networkDao.getAllForCluster(getParameters().getVmStaticData().getClusterId());
        List<VmNic> interfaces = vmNicDao.getAllForVm(getParameters().getVmStaticData().getId());
        for (final VmNic iface : interfaces) {
            final Network network = networkHelper.getNetworkByVnicProfileId(iface.getVnicProfileId());
            boolean networkFound = networks.stream().anyMatch(n -> Objects.equals(n.getId(), network.getId()));
            // if network not exists in cluster we remove the network from the interface
            if (!networkFound) {
                iface.setVnicProfileId(null);
                vmNicDao.update(iface);
            }
        }
    }
}
Also used : Network(org.ovirt.engine.core.common.businessentities.network.Network) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic)

Example 5 with VmNic

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

the class ActivateDeactivateVmNicCommand method macAvailable.

protected ValidationResult macAvailable() {
    VmNic nic = getParameters().getNic();
    EngineMessage failMessage = EngineMessage.NETWORK_MAC_ADDRESS_IN_USE;
    return ValidationResult.failWith(failMessage, ReplacementUtils.getVariableAssignmentString(failMessage, nic.getMacAddress())).when(new VmInterfaceManager().tooManyPluggedInterfaceWithSameMac(nic, getMacPool()));
}
Also used : EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic) VmInterfaceManager(org.ovirt.engine.core.bll.network.VmInterfaceManager)

Aggregations

VmNic (org.ovirt.engine.core.common.businessentities.network.VmNic)47 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)8 VM (org.ovirt.engine.core.common.businessentities.VM)6 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)6 Network (org.ovirt.engine.core.common.businessentities.network.Network)5 Guid (org.ovirt.engine.core.compat.Guid)5 HashMap (java.util.HashMap)4 VmDeviceId (org.ovirt.engine.core.common.businessentities.VmDeviceId)4 VmNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)4 List (java.util.List)3 Map (java.util.Map)3 VmNicValidator (org.ovirt.engine.core.bll.validator.VmNicValidator)3 Version (org.ovirt.engine.core.compat.Version)3 Collectors (java.util.stream.Collectors)2 VmInterfaceManager (org.ovirt.engine.core.bll.network.VmInterfaceManager)2 MacPool (org.ovirt.engine.core.bll.network.macpool.MacPool)2 VnicProfileHelper (org.ovirt.engine.core.bll.network.vm.VnicProfileHelper)2 VnicProfile (org.ovirt.engine.core.common.businessentities.network.VnicProfile)2 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)2