Skip to content

Commit

Permalink
core: Move VmDeviceCommonUtils.isSpecialDevice to ovf package
Browse files Browse the repository at this point in the history
It’s not used elsewhere.
  • Loading branch information
mz-pdm committed Aug 15, 2022
1 parent b7dcfbd commit f260d33
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 38 deletions.
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 abstract class OvfReaderWriterUtils {

/**
* is special device - device which is managed, but contains the general properties
*/
protected 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

0 comments on commit f260d33

Please sign in to comment.