use of org.ovirt.engine.core.common.businessentities.network.VmInterfaceType in project ovirt-engine by oVirt.
the class VdsBrokerObjectsBuilder method buildVmNetworkInterfacesFromDevices.
/**
* Convert the devices map and make a list of {@linkplain VmNetworkInterface}
* Mainly used to import the Hosted Engine Vm disks.
*
* @return A List of VM network interfaces {@linkplain VmNetworkInterface}
*/
public static ArrayList<VmNetworkInterface> buildVmNetworkInterfacesFromDevices(Map<String, Object> vmStruct) {
ArrayList<VmNetworkInterface> nics = new ArrayList<>();
Object[] devices = (Object[]) vmStruct.get(VdsProperties.Devices);
if (devices != null) {
for (Object device : devices) {
Map<String, Object> deviceMap = (Map<String, Object>) device;
if (VdsProperties.VM_INTERFACE_DEVICE_TYPE.equals(deviceMap.get(VdsProperties.Type))) {
VmNetworkInterface nic = new VmNetworkInterface();
nic.setId(Guid.createGuidFromString((String) deviceMap.get(VdsProperties.DeviceId)));
nic.setMacAddress((String) deviceMap.get(VdsProperties.MAC_ADDR));
nic.setName((String) deviceMap.get(VdsProperties.Name));
// FIXME we can't deduce the network profile by the network name. its many to many.
nic.setNetworkName((String) deviceMap.get(VdsProperties.NETWORK));
String nicModel = (String) deviceMap.get(VdsProperties.NIC_TYPE);
if ("virtio".equals(nicModel)) {
nicModel = "pv";
}
nic.setType(VmInterfaceType.valueOf(nicModel).getValue());
if (deviceMap.containsKey(VdsProperties.Model)) {
String model = (String) deviceMap.get(VdsProperties.Model);
for (VmInterfaceType type : VmInterfaceType.values()) {
if (model.equals(type.getInternalName())) {
nic.setType(type.getValue());
break;
}
}
}
nics.add(nic);
}
}
}
return nics;
}
use of org.ovirt.engine.core.common.businessentities.network.VmInterfaceType in project ovirt-engine by oVirt.
the class VdsBrokerObjectsBuilder method buildNetworkInterfaceFromExternalProvider.
private static VmNetworkInterface buildNetworkInterfaceFromExternalProvider(Map<String, Object> map) {
VmNetworkInterface nic = new VmNetworkInterface();
nic.setMacAddress((String) map.get(VdsProperties.MAC_ADDR));
nic.setRemoteNetworkName((String) map.get(VdsProperties.BRIDGE));
nic.setType(VmInterfaceType.pv.getValue());
if (map.containsKey(VdsProperties.Model)) {
String model = (String) map.get(VdsProperties.Model);
for (VmInterfaceType type : VmInterfaceType.values()) {
if (model.equals(type.getInternalName())) {
nic.setType(type.getValue());
break;
}
}
}
return nic;
}
use of org.ovirt.engine.core.common.businessentities.network.VmInterfaceType in project ovirt-engine by oVirt.
the class AsyncDataProvider method getNicTypeList.
public void getNicTypeList(final int osId, Version version, AsyncQuery<List<VmInterfaceType>> asyncQuery) {
asyncQuery.converterCallback = returnValue -> {
ArrayList<String> nics = (ArrayList<String>) returnValue;
List<VmInterfaceType> interfaceTypes = new ArrayList<>();
for (String nic : nics) {
try {
interfaceTypes.add(VmInterfaceType.valueOf(nic));
} catch (IllegalArgumentException e) {
// ignore if we can't find the enum value.
}
}
return interfaceTypes;
};
Frontend.getInstance().runQuery(QueryType.OsRepository, new OsQueryParameters(OsRepositoryVerb.GetNetworkDevices, osId, version), asyncQuery);
}
use of org.ovirt.engine.core.common.businessentities.network.VmInterfaceType in project ovirt-engine by oVirt.
the class BaseInterfaceCreatingManager method updateVnicType.
private void updateVnicType(VnicProfileView profile, VmNetworkInterface existingVnic, VmNetworkInterface editedVnic) {
boolean shouldBePciPassthroughType = profile != null && profile.isPassthrough() && supportedInterfaceTypes != null && supportedInterfaceTypes.contains(VmInterfaceType.pciPassthrough);
if (existingVnic == null) {
if (shouldBePciPassthroughType) {
editedVnic.setType(VmInterfaceType.pciPassthrough.getValue());
} else {
editedVnic.setType(defaultType == null ? null : defaultType.getValue());
}
} else {
VmInterfaceType existingInterfaceType = VmInterfaceType.forValue(existingVnic.getType());
boolean shouldRestoreToDefault = profile != null && !profile.isPassthrough() && VmInterfaceType.pciPassthrough.equals(existingInterfaceType);
if (shouldBePciPassthroughType) {
existingVnic.setType(VmInterfaceType.pciPassthrough.getValue());
} else if (shouldRestoreToDefault || supportedInterfaceTypes == null || !supportedInterfaceTypes.contains(existingInterfaceType)) {
existingVnic.setType(defaultType == null ? null : defaultType.getValue());
}
}
}
use of org.ovirt.engine.core.common.businessentities.network.VmInterfaceType 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();
}
Aggregations