Search in sources :

Example 1 with VmNetworkInterface

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

the class VmDevicesConverter method parseInterfaces.

private List<Map<String, Object>> parseInterfaces(XmlDocument document, List<VmDevice> devices, Guid vmId, MemoizingSupplier<Map<Map<String, String>, HostDevice>> addressToHostDeviceSupplier) {
    List<VmDevice> dbDevices = filterDevices(devices, VmDeviceGeneralType.INTERFACE);
    Map<Guid, VmDevice> devIdToDbDev = dbDevices.stream().collect(Collectors.toMap(device -> device.getDeviceId(), device -> device));
    List<VmNetworkInterface> dbInterfaces = vmNetworkInterfaceDao.getAllForVm(vmId);
    List<Map<String, Object>> result = new ArrayList<>();
    for (XmlNode node : selectNodes(document, VmDeviceGeneralType.INTERFACE)) {
        String type = parseAttribute(node, TYPE);
        Map<String, Object> dev = new HashMap<>();
        if (VmDeviceType.HOST_DEVICE.getName().equals(type)) {
            dev.put(VdsProperties.HostDev, getHostDeviceName(node, addressToHostDeviceSupplier));
        }
        dev.put(VdsProperties.Type, VmDeviceGeneralType.INTERFACE.getValue());
        dev.put(VdsProperties.Device, type);
        dev.put(VdsProperties.Address, parseAddress(node));
        dev.put(VdsProperties.Alias, parseAlias(node));
        String macAddress = parseMacAddress(node);
        // MAC address is a unique identifier of network interface devices
        VmDevice dbDev = correlate(dev, dbDevices, device -> {
            VmNetworkInterface dbInterface = dbInterfaces.stream().filter(iface -> iface.getMacAddress().equalsIgnoreCase(macAddress)).findFirst().orElse(null);
            return dbInterface != null ? devIdToDbDev.get(dbInterface.getId()) : null;
        });
        if (dbDev == null) {
            log.warn("unmanaged network interface with mac address '{}' is ignored", macAddress);
            continue;
        }
        dev.put(VdsProperties.DeviceId, dbDev.getDeviceId().toString());
        dev.put(VdsProperties.SpecParams, dbDev.getSpecParams());
        result.add(dev);
    }
    return result;
}
Also used : VmDeviceType(org.ovirt.engine.core.common.utils.VmDeviceType) Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) DiskLunMapDao(org.ovirt.engine.core.dao.DiskLunMapDao) Guid(org.ovirt.engine.core.compat.Guid) XmlNamespaceManager(org.ovirt.engine.core.utils.ovf.xml.XmlNamespaceManager) UsbControllerModel(org.ovirt.engine.core.common.businessentities.UsbControllerModel) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) XmlAttribute(org.ovirt.engine.core.utils.ovf.xml.XmlAttribute) LibvirtVmXmlBuilder(org.ovirt.engine.core.vdsbroker.builder.vminfo.LibvirtVmXmlBuilder) Singleton(javax.inject.Singleton) Function(java.util.function.Function) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) DiskLunMap(org.ovirt.engine.core.common.businessentities.storage.DiskLunMap) ArrayList(java.util.ArrayList) VmDeviceGeneralType(org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType) Inject(javax.inject.Inject) DiskImageDao(org.ovirt.engine.core.dao.DiskImageDao) Map(java.util.Map) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VdsProperties(org.ovirt.engine.core.vdsbroker.vdsbroker.VdsProperties) VmDeviceDao(org.ovirt.engine.core.dao.VmDeviceDao) VmNetworkInterfaceDao(org.ovirt.engine.core.dao.network.VmNetworkInterfaceDao) MemoizingSupplier(org.ovirt.engine.core.utils.MemoizingSupplier) Logger(org.slf4j.Logger) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) XmlDocument(org.ovirt.engine.core.utils.ovf.xml.XmlDocument) HostDeviceDao(org.ovirt.engine.core.dao.HostDeviceDao) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice) List(java.util.List) SPEC_PARAM_NODE(org.ovirt.engine.core.common.utils.VmDeviceCommonUtils.SPEC_PARAM_NODE) SPEC_PARAM_SIZE(org.ovirt.engine.core.common.utils.VmDeviceCommonUtils.SPEC_PARAM_SIZE) Optional(java.util.Optional) Comparator(java.util.Comparator) Collections(java.util.Collections) XmlNodeList(org.ovirt.engine.core.utils.ovf.xml.XmlNodeList) XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) HashMap(java.util.HashMap) DiskLunMap(org.ovirt.engine.core.common.businessentities.storage.DiskLunMap) Map(java.util.Map)

Example 2 with VmNetworkInterface

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

the class NetworkTemplateListModel method remove.

private void remove() {
    if (getWindow() != null) {
        return;
    }
    List<VmNetworkInterface> vnics = new ArrayList<>();
    for (PairQueryable<VmNetworkInterface, VmTemplate> pair : getSelectedItems()) {
        vnics.add(pair.getFirst());
    }
    RemoveVmTemplateInterfaceModel model = new RemoveVmTemplateInterfaceModel(this, vnics, true);
    setWindow(model);
}
Also used : VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) ArrayList(java.util.ArrayList) RemoveVmTemplateInterfaceModel(org.ovirt.engine.ui.uicommonweb.models.vms.RemoveVmTemplateInterfaceModel)

Example 3 with VmNetworkInterface

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

the class NetworkVmListModel method remove.

private void remove() {
    if (getWindow() != null) {
        return;
    }
    List<VmNetworkInterface> vnics = new ArrayList<>();
    for (Object item : getSelectedItems()) {
        PairQueryable<VmNetworkInterface, VM> pair = (PairQueryable<VmNetworkInterface, VM>) item;
        vnics.add(pair.getFirst());
    }
    RemoveVmInterfaceModel model = new RemoveVmInterfaceModel(this, vnics, true);
    setWindow(model);
}
Also used : PairQueryable(org.ovirt.engine.core.common.utils.PairQueryable) RemoveVmInterfaceModel(org.ovirt.engine.ui.uicommonweb.models.vms.RemoveVmInterfaceModel) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) VM(org.ovirt.engine.core.common.businessentities.VM) ArrayList(java.util.ArrayList)

Example 4 with VmNetworkInterface

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

the class NetworkVmListModel method syncSearch.

@Override
protected void syncSearch() {
    if (getEntity() == null) {
        return;
    }
    GetVmsAndNetworkInterfacesByNetworkIdParameters params = new GetVmsAndNetworkInterfacesByNetworkIdParameters(getEntity().getId(), NetworkVmFilter.running.equals(getViewFilterType()));
    params.setRefresh(getIsQueryFirstTime());
    final NetworkVmFilter filter = getViewFilterType();
    Frontend.getInstance().runQuery(QueryType.GetVmsAndNetworkInterfacesByNetworkId, params, new AsyncQuery<QueryReturnValue>(returnValue -> {
        if (filter.equals(getViewFilterType())) {
            setItems((Collection<PairQueryable<VmNetworkInterface, VM>>) returnValue.getReturnValue());
        }
    }));
}
Also used : QueryType(org.ovirt.engine.core.common.queries.QueryType) ActionUtils(org.ovirt.engine.core.common.ActionUtils) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) Collection(java.util.Collection) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand) HelpTag(org.ovirt.engine.ui.uicommonweb.help.HelpTag) ApplicationMode(org.ovirt.engine.core.common.mode.ApplicationMode) SearchableListModel(org.ovirt.engine.ui.uicommonweb.models.SearchableListModel) ArrayList(java.util.ArrayList) ActionType(org.ovirt.engine.core.common.action.ActionType) Frontend(org.ovirt.engine.ui.frontend.Frontend) List(java.util.List) VM(org.ovirt.engine.core.common.businessentities.VM) ConstantsManager(org.ovirt.engine.ui.uicompat.ConstantsManager) GetVmsAndNetworkInterfacesByNetworkIdParameters(org.ovirt.engine.core.common.queries.GetVmsAndNetworkInterfacesByNetworkIdParameters) PairQueryable(org.ovirt.engine.core.common.utils.PairQueryable) Comparator(java.util.Comparator) VMStatus(org.ovirt.engine.core.common.businessentities.VMStatus) PropertyChangedEventArgs(org.ovirt.engine.ui.uicompat.PropertyChangedEventArgs) NetworkView(org.ovirt.engine.core.common.businessentities.network.NetworkView) RemoveVmInterfaceModel(org.ovirt.engine.ui.uicommonweb.models.vms.RemoveVmInterfaceModel) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) VM(org.ovirt.engine.core.common.businessentities.VM) Collection(java.util.Collection) GetVmsAndNetworkInterfacesByNetworkIdParameters(org.ovirt.engine.core.common.queries.GetVmsAndNetworkInterfacesByNetworkIdParameters)

Example 5 with VmNetworkInterface

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

the class NetworkVmListModel method updateActionAvailability.

private void updateActionAvailability() {
    ArrayList<VM> vms = new ArrayList<>();
    Iterable<PairQueryable<VmNetworkInterface, VM>> selectedItems = getSelectedItems() != null ? getSelectedItems() : new ArrayList();
    for (PairQueryable<VmNetworkInterface, VM> item : selectedItems) {
        vms.add(item.getSecond());
    }
    getRemoveCommand().setIsExecutionAllowed(ActionUtils.canExecute(vms, VM.class, ActionType.RemoveVmInterface) && getSelectedItems() != null && !getSelectedItems().isEmpty() && canRemoveVnics());
}
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)

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