Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move VmDeviceCommonUtils.isSpecialDevice to ovf package #587

Merged
merged 1 commit into from
Aug 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -286,40 +286,6 @@ private static String getDeviceTypeSearchExpr(VmDeviceGeneralType type, String d
return sb.toString();
}

/**
* is special device - device which is managed, but contains the general properties
*/
public static boolean isSpecialDevice(String device, VmDeviceGeneralType type, boolean includeHostDev) {
if (VmDeviceType.USB.getName().equals(device)) {
return true;
}

switch(type) {
case MDEV:
case SOUND:
return true;
case CONSOLE:
return VmDeviceType.CONSOLE.getName().equals(device);
case SMARTCARD:
return VmDeviceType.SMARTCARD.getName().equals(device);
case REDIR:
return VmDeviceType.SPICEVMC.getName().equals(device);
case BALLOON:
return VmDeviceType.MEMBALLOON.getName().equals(device);
case WATCHDOG:
return VmDeviceType.WATCHDOG.getName().equals(device);
case RNG:
return VmDeviceType.VIRTIO.getName().equals(device);
case CONTROLLER:
return VmDeviceType.VIRTIOSERIAL.getName().equals(device)
|| VmDeviceType.VIRTIOSCSI.getName().equals(device);
case HOSTDEV:
return includeHostDev;
default:
return false;
}
}

/**
* Find a device in the map with the given type.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ private VmDevice readOtherHardwareItem(XmlNode node, VmDeviceGeneralType type) {
&& StringUtils.isNotEmpty(selectSingleNode(node, VMD_TYPE, _xmlNS).innerText)) {
String device = selectSingleNode(node, VMD_DEVICE, _xmlNS).innerText;
// special devices are treated as managed devices but still have the OTHER OVF ResourceType
managed = VmDeviceCommonUtils.isSpecialDevice(device, type, true);
managed = OvfReaderWriterUtils.isSpecialDevice(device, type, true);
}

return managed ? readManagedVmDevice(node, readDeviceId(node))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.ovirt.engine.core.utils.ovf;

import org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType;
import org.ovirt.engine.core.common.utils.VmDeviceType;

public class OvfReaderWriterUtils {

/**
* is special device - device which is managed, but contains the general properties
*/
static boolean isSpecialDevice(String device, VmDeviceGeneralType type, boolean includeHostDev) {
if (VmDeviceType.USB.getName().equals(device)) {
return true;
}

switch(type) {
case MDEV:
case SOUND:
return true;
case CONSOLE:
return VmDeviceType.CONSOLE.getName().equals(device);
case SMARTCARD:
return VmDeviceType.SMARTCARD.getName().equals(device);
case REDIR:
return VmDeviceType.SPICEVMC.getName().equals(device);
case BALLOON:
return VmDeviceType.MEMBALLOON.getName().equals(device);
case WATCHDOG:
return VmDeviceType.WATCHDOG.getName().equals(device);
case RNG:
return VmDeviceType.VIRTIO.getName().equals(device);
case CONTROLLER:
return VmDeviceType.VIRTIOSERIAL.getName().equals(device)
|| VmDeviceType.VIRTIOSCSI.getName().equals(device);
case HOSTDEV:
return includeHostDev;
default:
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.ovirt.engine.core.common.osinfo.OsRepository;
import org.ovirt.engine.core.common.scheduling.AffinityGroup;
import org.ovirt.engine.core.common.utils.VmCpuCountHelper;
import org.ovirt.engine.core.common.utils.VmDeviceCommonUtils;
import org.ovirt.engine.core.compat.Guid;
import org.ovirt.engine.core.compat.Version;

Expand Down Expand Up @@ -111,7 +110,7 @@ protected void writeHardware() {
}

protected boolean isSpecialDevice(VmDevice vmDevice) {
return VmDeviceCommonUtils.isSpecialDevice(vmDevice.getDevice(), vmDevice.getType(), true);
return OvfReaderWriterUtils.isSpecialDevice(vmDevice.getDevice(), vmDevice.getType(), true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ private void writeOtherDevices() {
}

protected boolean isSpecialDevice(VmDevice vmDevice) {
return VmDeviceCommonUtils.isSpecialDevice(vmDevice.getDevice(), vmDevice.getType(), false);
return OvfReaderWriterUtils.isSpecialDevice(vmDevice.getDevice(), vmDevice.getType(), false);
}

protected void writeVmDevice(VmDevice vmDevice) {
Expand Down