Search in sources :

Example 31 with VmNetworkInterface

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

the class OvfOvaReader method getNetworkInterface.

@Override
protected VmNetworkInterface getNetworkInterface(XmlNode node) {
    VmNetworkInterface iface = new VmNetworkInterface();
    iface.setId(Guid.newGuid());
    interfaces.add(iface);
    return iface;
}
Also used : VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)

Example 32 with VmNetworkInterface

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

the class OvfOvirtReader method buildNicReference.

protected void buildNicReference() {
    XmlNodeList list = selectNodes(_document, "//*/Nic", _xmlNS);
    for (XmlNode node : list) {
        VmNetworkInterface iface = new VmNetworkInterface();
        iface.setId(new Guid(node.attributes.get("ovf:id").getValue()));
        interfaces.add(iface);
    }
    if (!list.iterator().hasNext()) {
        String pattern = "//*/Item[" + VMD_RESOURCE_TYPE + "=" + OvfHardware.Network + "]";
        list = selectNodes(_document, pattern, _xmlNS);
        int nicIdx = 0;
        for (XmlNode node : list) {
            VmNetworkInterface iface = new VmNetworkInterface();
            iface.setId(Guid.newGuid());
            updateSingleNic(node, iface, ++nicIdx);
            interfaces.add(iface);
        }
    }
}
Also used : XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) Guid(org.ovirt.engine.core.compat.Guid) XmlNodeList(org.ovirt.engine.core.utils.ovf.xml.XmlNodeList)

Example 33 with VmNetworkInterface

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

the class OvfOvirtReader method getNetworkInterface.

@Override
protected VmNetworkInterface getNetworkInterface(XmlNode node) {
    // prior to 3.0 the instanceId is int , in 3.1 and on this is Guid
    String str = selectSingleNode(node, "rasd:InstanceId", _xmlNS).innerText;
    if (!StringUtils.isNumeric(str)) {
        // 3.1 and above OVF format
        final Guid guid = new Guid(str);
        VmNetworkInterface iface = interfaces.stream().filter(i -> i.getId().equals(guid)).findFirst().orElse(null);
        if (iface == null) {
            iface = new VmNetworkInterface();
            iface.setId(guid);
            interfaces.add(iface);
        }
        return iface;
    } else {
        // 3.0 and below OVF format
        VmNetworkInterface iface = new VmNetworkInterface();
        iface.setId(Guid.newGuid());
        interfaces.add(iface);
        return iface;
    }
}
Also used : VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) Guid(org.ovirt.engine.core.compat.Guid)

Example 34 with VmNetworkInterface

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

the class OvfWriter method writeNetwork.

private void writeNetwork() {
    for (VmNetworkInterface iface : vmBase.getInterfaces()) {
        _writer.writeStartElement("Item");
        _writer.writeStartElement(RASD_URI, "Caption");
        String networkName = iface.getNetworkName() != null ? iface.getNetworkName() : "[No Network]";
        _writer.writeRaw("Ethernet adapter on " + networkName);
        _writer.writeEndElement();
        _writer.writeStartElement(RASD_URI, "InstanceId");
        _writer.writeRaw(iface.getId().toString());
        _writer.writeEndElement();
        _writer.writeStartElement(RASD_URI, "ResourceType");
        _writer.writeRaw(OvfHardware.Network);
        _writer.writeEndElement();
        _writer.writeStartElement(RASD_URI, "OtherResourceType");
        if (StringUtils.isNotEmpty(iface.getVnicProfileName())) {
            _writer.writeRaw(iface.getVnicProfileName());
        }
        _writer.writeEndElement();
        _writer.writeStartElement(RASD_URI, "ResourceSubType");
        if (iface.getType() != null) {
            _writer.writeRaw(iface.getType().toString());
        }
        _writer.writeEndElement();
        _writer.writeStartElement(RASD_URI, "Connection");
        if (iface.getNetworkName() != null) {
            _writer.writeRaw(iface.getNetworkName());
        }
        _writer.writeEndElement();
        _writer.writeStartElement(RASD_URI, "Linked");
        _writer.writeRaw(String.valueOf(iface.isLinked()));
        _writer.writeEndElement();
        _writer.writeStartElement(RASD_URI, "Name");
        _writer.writeRaw(iface.getName());
        _writer.writeEndElement();
        _writer.writeStartElement(RASD_URI, "ElementName");
        _writer.writeRaw(iface.getName());
        _writer.writeEndElement();
        writeMacAddress(iface);
        _writer.writeStartElement(RASD_URI, "speed");
        // version prior to 2.3 may not have speed so we get it by type
        if (iface.getSpeed() != null) {
            _writer.writeRaw(iface.getSpeed().toString());
        } else {
            _writer.writeRaw(String.valueOf(VmInterfaceType.forValue(iface.getType()).getSpeed()));
        }
        _writer.writeEndElement();
        writeManagedDeviceInfo(vmBase, iface.getId());
        // item
        _writer.writeEndElement();
    }
}
Also used : VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)

Example 35 with VmNetworkInterface

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

the class AddVmAndCloneImageCommand method addVmNetwork.

@Override
protected void addVmNetwork() {
    VnicProfileHelper vnicProfileHelper = new VnicProfileHelper(getClusterId(), getStoragePoolId(), AuditLogType.ADD_VM_FROM_SNAPSHOT_INVALID_INTERFACES);
    for (VmNetworkInterface iface : getVmFromConfiguration().getInterfaces()) {
        vnicProfileHelper.updateNicWithVnicProfileForUser(iface, getCurrentUser());
    }
    vnicProfileHelper.auditInvalidInterfaces(getVmName());
    super.addVmNetwork();
}
Also used : VnicProfileHelper(org.ovirt.engine.core.bll.network.vm.VnicProfileHelper) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)

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