Arik Hadas has uploaded a new change for review. Change subject: core: add managed virtio-serial device when reading ovf ......................................................................
core: add managed virtio-serial device when reading ovf virtio-serial devices were written to OVF files before, so when we import VM/Template and such device exist we'll just add it as managed device (virtio-serial was added to the list of 'special devices'). It could be that OVF file was created before the unmanaged virtio-serial device was added. In this case, we'll create a new managed virtio-serial device for the imported VM/Template. Change-Id: I08c8dc8514edf5b291017690c654f4a9e455a658 Bug-Url: https://bugzilla.redhat.com/1028387 Signed-off-by: Arik Hadas <[email protected]> --- M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VmDeviceCommonUtils.java M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfReader.java M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfTemplateReader.java M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfVmReader.java 4 files changed, 45 insertions(+), 6 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/95/31895/1 diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VmDeviceCommonUtils.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VmDeviceCommonUtils.java index 8c2c814..1f32b8d 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VmDeviceCommonUtils.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VmDeviceCommonUtils.java @@ -14,6 +14,7 @@ import org.ovirt.engine.core.common.businessentities.VM; import org.ovirt.engine.core.common.businessentities.VmDevice; import org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType; +import org.ovirt.engine.core.common.businessentities.VmDeviceId; import org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface; import org.ovirt.engine.core.common.config.Config; import org.ovirt.engine.core.common.config.ConfigValues; @@ -61,6 +62,21 @@ && device.getDevice().equals(VmDeviceType.BRIDGE.getName()); } + public static VmDevice createVirtioSerialDeviceForVm(Guid vmId) { + return new VmDevice(new VmDeviceId(Guid.newGuid(), vmId), + VmDeviceGeneralType.CONTROLLER, + VmDeviceType.VIRTIOSERIAL.getName(), + "", + 0, + new HashMap<String, Object>(), + true, + true, + false, + "", + null, + null); + } + /** * updates given devices boot order * diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfReader.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfReader.java index d3f53f3..7b961b6 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfReader.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfReader.java @@ -314,6 +314,12 @@ protected abstract void readHardwareSection(XmlNode section); + protected VmDevice addManagedVmDevice(VmDevice vmDevice) { + vmDevice.setIsManaged(true); + vmBase.getManagedDeviceMap().put(vmDevice.getDeviceId(), vmDevice); + return vmDevice; + } + protected VmDeviceType getDisplayDevice(DisplayType displayType) { return osRepository.getDisplayDevice(vmBase.getOsId(), new Version(getVersion()), displayType); } diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfTemplateReader.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfTemplateReader.java index a214d55..47fc786 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfTemplateReader.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfTemplateReader.java @@ -8,6 +8,7 @@ import org.ovirt.engine.core.common.businessentities.ArchitectureType; import org.ovirt.engine.core.common.businessentities.DiskImage; import org.ovirt.engine.core.common.businessentities.UsbPolicy; +import org.ovirt.engine.core.common.businessentities.VmDevice; import org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType; import org.ovirt.engine.core.common.businessentities.VmEntityType; import org.ovirt.engine.core.common.businessentities.VmTemplate; @@ -16,6 +17,7 @@ import org.ovirt.engine.core.common.osinfo.OsRepository; import org.ovirt.engine.core.common.utils.SimpleDependecyInjector; import org.ovirt.engine.core.common.utils.VmDeviceCommonUtils; +import org.ovirt.engine.core.common.utils.VmDeviceType; import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.compat.backendcompat.XmlDocument; import org.ovirt.engine.core.compat.backendcompat.XmlNode; @@ -51,6 +53,7 @@ @Override protected void readHardwareSection(XmlNode section) { + boolean readVirtioSerial = false; XmlNodeList list = section.SelectNodes("Item"); for (XmlNode node : list) { int resourceType = Integer.parseInt(node.SelectSingleNode("rasd:ResourceType", _xmlNS).innerText); @@ -160,11 +163,17 @@ // special devices are treated as managed devices but still have the OTHER OVF ResourceType addAsManaged = VmDeviceCommonUtils.isSpecialDevice(device, type); } - readVmDevice(node, _vmTemplate, Guid.newGuid(), addAsManaged); + VmDevice vmDevice = readVmDevice(node, _vmTemplate, Guid.newGuid(), addAsManaged); + readVirtioSerial = readVirtioSerial || + VmDeviceType.VIRTIOSERIAL.getName().equals(vmDevice.getDevice()); break; } } + + if (!readVirtioSerial) { + addManagedVmDevice(VmDeviceCommonUtils.createVirtioSerialDeviceForVm(_vmTemplate.getId())); + } } @Override diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfVmReader.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfVmReader.java index adc8db0..bb7d884 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfVmReader.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfVmReader.java @@ -19,6 +19,7 @@ import org.ovirt.engine.core.common.businessentities.VmStatic; import org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface; import org.ovirt.engine.core.common.utils.VmDeviceCommonUtils; +import org.ovirt.engine.core.common.utils.VmDeviceType; import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.compat.Version; import org.ovirt.engine.core.compat.backendcompat.XmlDocument; @@ -56,6 +57,7 @@ @Override protected void readHardwareSection(XmlNode section) { + boolean readVirtioSerial = false; for (XmlNode node : section.SelectNodes("Item")) { switch (node.SelectSingleNode("rasd:ResourceType", _xmlNS).innerText) { @@ -88,9 +90,15 @@ break; case OvfHardware.OTHER: - readOtherHardwareItem(node); + VmDevice vmDevice = readOtherHardwareItem(node); + readVirtioSerial = readVirtioSerial || + VmDeviceType.VIRTIOSERIAL.getName().equals(vmDevice.getDevice()); break; } + } + + if (!readVirtioSerial) { + addManagedVmDevice(VmDeviceCommonUtils.createVirtioSerialDeviceForVm(_vm.getId())); } } @@ -186,19 +194,19 @@ readVmDevice(node, _vm.getStaticData(), Guid.newGuid(), Boolean.TRUE); } - private void readOtherHardwareItem(XmlNode node) { + private VmDevice readOtherHardwareItem(XmlNode node) { if (node.SelectSingleNode(OvfProperties.VMD_TYPE, _xmlNS) != null && StringUtils.isNotEmpty(node.SelectSingleNode(OvfProperties.VMD_TYPE, _xmlNS).innerText)) { VmDeviceGeneralType type = VmDeviceGeneralType.forValue(String.valueOf(node.SelectSingleNode(OvfProperties.VMD_TYPE, _xmlNS).innerText)); String device = String.valueOf(node.SelectSingleNode(OvfProperties.VMD_DEVICE, _xmlNS).innerText); // special devices are treated as managed devices but still have the OTHER OVF ResourceType if (VmDeviceCommonUtils.isSpecialDevice(device, type)) { - readVmDevice(node, _vm.getStaticData(), Guid.newGuid(), Boolean.TRUE); + return readVmDevice(node, _vm.getStaticData(), Guid.newGuid(), Boolean.TRUE); } else { - readVmDevice(node, _vm.getStaticData(), Guid.newGuid(), Boolean.FALSE); + return readVmDevice(node, _vm.getStaticData(), Guid.newGuid(), Boolean.FALSE); } } else { - readVmDevice(node, _vm.getStaticData(), Guid.newGuid(), Boolean.FALSE); + return readVmDevice(node, _vm.getStaticData(), Guid.newGuid(), Boolean.FALSE); } } -- To view, visit http://gerrit.ovirt.org/31895 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I08c8dc8514edf5b291017690c654f4a9e455a658 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: ovirt-engine-3.5 Gerrit-Owner: Arik Hadas <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
