use of org.ovirt.engine.core.common.businessentities.network.VnicProfile in project ovirt-engine by oVirt.
the class AddNetworkCommand method runAddVnicProfile.
private void runAddVnicProfile() {
if (getNetwork().isVmNetwork() && getParameters().isVnicProfileRequired()) {
VnicProfile vnicProfile = networkHelper.createVnicProfile(getNetwork());
AddVnicProfileParameters vnicProfileParameters = new AddVnicProfileParameters(vnicProfile);
vnicProfileParameters.setPublicUse(getParameters().isVnicProfilePublicUse());
runInternalAction(ActionType.AddVnicProfile, vnicProfileParameters, getContext().clone().withoutLock());
}
}
use of org.ovirt.engine.core.common.businessentities.network.VnicProfile in project ovirt-engine by oVirt.
the class LibvirtVmXmlBuilder method writeInterface.
private void writeInterface(VmDevice device, VmNic nic) {
// <interface type="bridge">
// <mac address="aa:bb:dd:dd:aa:bb"/>
// <model type="virtio"/>
// <source bridge="engine"/>
// [<driver name="vhost/qemu" queues="int"/>]
// [<filterref filter='filter name'>
// [<parameter name='parameter name' value='parameter value'>]
// </filterref>]
// [<tune><sndbuf>0</sndbuf></tune>]
// [<link state='up|down'/>]
// [<bandwidth>
// [<inbound average="int" [burst="int"] [peak="int"]/>]
// [<outbound average="int" [burst="int"] [peak="int"]/>]
// </bandwidth>]
// </interface>
//
// -- or -- a slightly different SR-IOV network interface
// <interface type='hostdev' managed='no'>
// <driver name='vfio'/>
// <source>
// <address type='pci' domain='0x0000' bus='0x00' slot='0x07'
// function='0x0'/>
// </source>
// <mac address='52:54:00:6d:90:02'/>
// <vlan>
// <tag id=100/>
// </vlan>
// <address type='pci' domain='0x0000' bus='0x00' slot='0x07'
// function='0x0'/>
// <boot order='1'/>
// </interface>
writer.writeStartElement("interface");
VnicProfile vnicProfile = vmInfoBuildUtils.getVnicProfile(nic.getVnicProfileId());
Network network = vnicProfile != null ? vmInfoBuildUtils.getNetwork(vnicProfile.getNetworkId()) : null;
boolean networkless = network == null;
switch(device.getDevice()) {
case "bridge":
writer.writeAttributeString("type", "bridge");
writer.writeStartElement("model");
VmInterfaceType ifaceType = nic.getType() != null ? VmInterfaceType.forValue(nic.getType()) : VmInterfaceType.rtl8139;
String evaluatedIfaceType = vmInfoBuildUtils.evaluateInterfaceType(ifaceType, vm.getHasAgent());
if ("pv".equals(evaluatedIfaceType)) {
evaluatedIfaceType = "virtio";
}
writer.writeAttributeString("type", evaluatedIfaceType);
writer.writeEndElement();
writer.writeStartElement("link");
writer.writeAttributeString("state", !networkless && nic.isLinked() ? "up" : "down");
writer.writeEndElement();
// The source element is different when using legacy or OVS bridge. We
// expect VDSM to replace the source element if it is a non legacy bridge
writer.writeStartElement("source");
writer.writeAttributeString("bridge", !networkless ? network.getVdsmName() : ";vdsmdummy;");
writer.writeEndElement();
String queues = vnicProfile != null ? vnicProfile.getCustomProperties().remove("queues") : null;
String driverName = getDriverNameForNetwork(!networkless ? network.getName() : "");
if (queues != null || driverName != null) {
writer.writeStartElement("driver");
if (queues != null) {
writer.writeAttributeString("queues", queues);
if (driverName == null) {
driverName = "vhost";
}
}
writer.writeAttributeString("name", driverName);
writer.writeEndElement();
}
break;
case "hostdev":
writer.writeAttributeString("type", "hostdev");
writer.writeAttributeString("managed", "no");
writer.writeStartElement("driver");
writer.writeAttributeString("name", "vfio");
writer.writeEndElement();
if (!networkless && NetworkUtils.isVlan(network)) {
writer.writeStartElement("vlan");
writer.writeStartElement("tag");
writer.writeAttributeString("id", network.getVlanId().toString());
writer.writeEndElement();
writer.writeEndElement();
}
writer.writeStartElement("source");
writer.writeStartElement("address");
String vfDeviceName = passthroughVnicToVfMap.get(nic.getId());
Map<String, String> sourceAddress = hostDevicesSupplier.get().get(vfDeviceName).getAddress();
sourceAddress.put("type", "pci");
sourceAddress.forEach(writer::writeAttributeString);
writer.writeEndElement();
writer.writeEndElement();
break;
}
writeAlias(device);
writeAddress(device);
writeBootOrder(device.getBootOrder());
writer.writeStartElement("mac");
writer.writeAttributeString("address", nic.getMacAddress());
writer.writeEndElement();
NetworkFilter networkFilter = vmInfoBuildUtils.fetchVnicProfileNetworkFilter(nic);
if (networkFilter != null) {
writer.writeStartElement("filterref");
writer.writeAttributeString("filter", networkFilter.getName());
vmInfoBuildUtils.getAllNetworkFiltersForVmNic(nic.getId()).forEach(parameter -> {
writer.writeStartElement("parameter");
writer.writeAttributeString("name", parameter.getName());
writer.writeAttributeString("value", parameter.getValue());
writer.writeEndElement();
});
writer.writeEndElement();
}
String sndbuf = vmCustomProperties.get("sndbuf");
if (sndbuf != null) {
writer.writeStartElement("tune");
writer.writeElement("sndbuf", sndbuf);
writer.writeEndElement();
}
Map<String, Object> profileData = new HashMap<>();
vmInfoBuildUtils.addProfileDataToNic(profileData, vm, device, nic);
List<String> portMirroring = (List<String>) profileData.get(VdsProperties.PORT_MIRRORING);
if (portMirroring != null && !portMirroring.isEmpty()) {
// store port mirroring in the metadata
vnicMetadata.computeIfAbsent(nic.getMacAddress(), mac -> new HashMap<>());
vnicMetadata.get(nic.getMacAddress()).put("portMirroring", portMirroring);
}
Map<String, String> runtimeCustomProperties = vm.getRuntimeDeviceCustomProperties().get(device.getId());
if (runtimeCustomProperties != null && !runtimeCustomProperties.isEmpty()) {
// store runtime custom properties in the metadata
vnicMetadata.computeIfAbsent(nic.getMacAddress(), mac -> new HashMap<>());
vnicMetadata.get(nic.getMacAddress()).put("runtimeCustomProperties", runtimeCustomProperties);
}
if (vnicProfile != null && vnicProfile.getCustomProperties() != null) {
vnicMetadata.computeIfAbsent(nic.getMacAddress(), mac -> new HashMap<>());
vnicMetadata.get(nic.getMacAddress()).putAll(vnicProfile.getCustomProperties());
}
writer.writeStartElement("bandwidth");
@SuppressWarnings("unchecked") Map<String, Object> specParams = (Map<String, Object>) profileData.get("specParams");
if (specParams != null && (specParams.containsKey("inbound") || specParams.containsKey("outbound"))) {
@SuppressWarnings("unchecked") Map<String, String> inboundMap = (Map<String, String>) specParams.get("inbound");
if (inboundMap != null && !inboundMap.isEmpty()) {
writer.writeStartElement("inbound");
writer.writeAttributeString("average", String.valueOf(inboundMap.get("average")));
writer.writeAttributeString("burst", String.valueOf(inboundMap.get("burst")));
writer.writeAttributeString("peak", String.valueOf(inboundMap.get("peak")));
writer.writeEndElement();
}
@SuppressWarnings("unchecked") Map<String, String> outboundMap = (Map<String, String>) specParams.get("outbound");
if (outboundMap != null && !outboundMap.isEmpty()) {
writer.writeStartElement("outbound");
writer.writeAttributeString("average", String.valueOf(outboundMap.get("average")));
writer.writeAttributeString("burst", String.valueOf(outboundMap.get("burst")));
writer.writeAttributeString("peak", String.valueOf(outboundMap.get("peak")));
writer.writeEndElement();
}
}
writer.writeEndElement();
writer.writeEndElement();
}
use of org.ovirt.engine.core.common.businessentities.network.VnicProfile in project ovirt-engine by oVirt.
the class VmInfoBuildUtils method addNetworkVirtualFunctionProperties.
public void addNetworkVirtualFunctionProperties(Map<String, Object> struct, VmNic vmInterface, VmDevice vmDevice, String vfName, VM vm) {
struct.put(VdsProperties.Type, vmDevice.getType().getValue());
struct.put(VdsProperties.Device, vmDevice.getDevice());
struct.put(VdsProperties.HostDev, vfName);
addAddress(vmDevice, struct);
struct.put(VdsProperties.MAC_ADDR, vmInterface.getMacAddress());
struct.put(VdsProperties.DeviceId, String.valueOf(vmDevice.getId().getDeviceId()));
Map<String, Object> specParams = new HashMap<>();
VnicProfile vnicProfile = getVnicProfile(vmInterface.getVnicProfileId());
Network network = getNetwork(vnicProfile.getNetworkId());
if (NetworkUtils.isVlan(network)) {
specParams.put(VdsProperties.VLAN_ID, network.getVlanId());
}
struct.put(VdsProperties.SpecParams, specParams);
addCustomPropertiesForDevice(struct, vm, vmDevice, getVnicCustomProperties(vnicProfile));
}
use of org.ovirt.engine.core.common.businessentities.network.VnicProfile in project ovirt-engine by oVirt.
the class EntityDaoImplTest method testGetEntityNameByIdAndTypeForVNICProfile.
@Test
public void testGetEntityNameByIdAndTypeForVNICProfile() {
VnicProfile vnicProfile = vnicProfileDao.get(FixturesTool.VM_NETWORK_INTERFACE_PROFILE);
assertNotNull(vnicProfile);
String name = vnicProfile.getName();
assertEquals(name, underTest.getEntityNameByIdAndType(FixturesTool.VM_NETWORK_INTERFACE_PROFILE, VdcObjectType.VnicProfile));
}
use of org.ovirt.engine.core.common.businessentities.network.VnicProfile in project ovirt-engine by oVirt.
the class VmInfoBuildUtils method addProfileDataToNic.
public void addProfileDataToNic(Map<String, Object> struct, VM vm, VmDevice vmDevice, VmNic nic) {
VnicProfile vnicProfile = null;
Network network = null;
String networkName = "";
String vdsmName = "";
List<VnicProfileProperties> unsupportedFeatures = new ArrayList<>();
if (nic.getVnicProfileId() != null) {
vnicProfile = getVnicProfile(nic.getVnicProfileId());
if (vnicProfile != null) {
network = getNetwork(vnicProfile.getNetworkId());
networkName = network.getName();
vdsmName = network.getVdsmName();
log.debug("VNIC '{}' is using profile '{}' on network '{}' with vdsmName '{}'", nic.getName(), vnicProfile, networkName, vdsmName);
addQosForDevice(struct, vnicProfile);
}
}
struct.put(VdsProperties.NETWORK, vdsmName);
addPortMirroringToVmInterface(struct, vnicProfile, network);
addCustomPropertiesForDevice(struct, vm, vmDevice, getVnicCustomProperties(vnicProfile));
reportUnsupportedVnicProfileFeatures(vm, nic, vnicProfile, unsupportedFeatures);
}
Aggregations