use of org.ovirt.engine.core.utils.ovf.xml.XmlNode in project ovirt-engine by oVirt.
the class OvfReader method consumeReadProperty.
protected void consumeReadProperty(XmlNode content, String propertyKey, Consumer<String> then, Runnable orElse) {
XmlNode node = selectSingleNode(content, propertyKey);
acceptNode(then, orElse, node);
}
use of org.ovirt.engine.core.utils.ovf.xml.XmlNode in project ovirt-engine by oVirt.
the class OvfReader method readHardwareSection.
protected void readHardwareSection(XmlNode section) {
boolean readVirtioSerial = false;
int nicIdx = 0;
for (XmlNode item : selectNodes(section, "Item")) {
String resourceType = selectSingleNode(item, "rasd:ResourceType", _xmlNS).innerText;
resourceType = adjustHardwareResourceType(resourceType);
switch(resourceType) {
case OvfHardware.CPU:
readCpuItem(item);
break;
case OvfHardware.Memory:
readMemoryItem(item);
break;
case OvfHardware.DiskImage:
readDiskImageItem(item);
break;
case OvfHardware.Network:
/**
* If NIC items are found in the hardware section of the OVF, they are the real ones,
* so clear the NIC references found in the <NetworkSection> of the OVF which are used
* only to map networks, but should not be used to create NICs. Clear() is performed only
* upon finding the first NIC item.
*/
if (nicIdx == 0) {
interfaces.clear();
}
readNetworkItem(item, ++nicIdx);
break;
case OvfHardware.USB:
readUsbItem(item);
break;
case OvfHardware.Monitor:
readMonitorItem(item);
break;
case OvfHardware.Graphics:
// so far graphics doesn't contain anything special
readManagedVmDevice(item, Guid.newGuid());
break;
case OvfHardware.CD:
readCdItem(item);
break;
case OvfHardware.OTHER:
VmDevice vmDevice = readOtherHardwareItem(item);
readVirtioSerial = readVirtioSerial || VmDeviceType.VIRTIOSERIAL.getName().equals(vmDevice.getDevice());
break;
}
}
if (!readVirtioSerial) {
addManagedVmDevice(VmDeviceCommonUtils.createVirtioSerialDeviceForVm(vmBase.getId()));
}
}
use of org.ovirt.engine.core.utils.ovf.xml.XmlNode in project ovirt-engine by oVirt.
the class OvfReader method readDedicatedHostsList.
private void readDedicatedHostsList() {
// initialize to empty list
vmBase.setDedicatedVmForVdsList(new LinkedList<>());
// search all dedicated hosts with xPath
XmlNodeList hostsList = selectNodes(_document, "//*/Content/" + DEDICATED_VM_FOR_VDS);
for (XmlNode hostNode : hostsList) {
if (hostNode != null && StringUtils.isNotEmpty(hostNode.innerText)) {
vmBase.getDedicatedVmForVdsList().add(Guid.createGuidFromString(hostNode.innerText));
}
}
}
use of org.ovirt.engine.core.utils.ovf.xml.XmlNode in project ovirt-engine by oVirt.
the class OvfReader method updateSingleNic.
protected void updateSingleNic(XmlNode node, VmNetworkInterface iface, int nicIdx) {
String networkName = selectSingleNode(node, VMD_CONNECTION, _xmlNS).innerText;
iface.setRemoteNetworkName(networkName);
iface.setNetworkName(StringUtils.defaultIfEmpty(networkName, null));
XmlNode vnicProfileNameNode = selectSingleNode(node, VMD_VNIC_PROFILE_NAME, _xmlNS);
iface.setVnicProfileName(vnicProfileNameNode == null ? null : StringUtils.defaultIfEmpty(vnicProfileNameNode.innerText, null));
XmlNode linkedNode = selectSingleNode(node, VMD_LINKED, _xmlNS);
iface.setLinked(linkedNode == null ? true : Boolean.valueOf(linkedNode.innerText));
XmlNode nameNode = selectSingleNode(node, VMD_NAME, _xmlNS);
iface.setName(nameNode != null ? nameNode.innerText : String.format("nic%d", nicIdx));
XmlNode resourceSubTypeNode = selectSingleNode(node, "rasd:ResourceSubType", _xmlNS);
iface.setType(getVmInterfaceType(resourceSubTypeNode));
XmlNode speed = selectSingleNode(node, "rasd:speed", _xmlNS);
iface.setSpeed(speed != null ? Integer.parseInt(speed.innerText) : VmInterfaceType.forValue(iface.getType()).getSpeed());
}
use of org.ovirt.engine.core.utils.ovf.xml.XmlNode in project ovirt-engine by oVirt.
the class OvfReader method readVmDevice.
/**
* Reads vm device attributes from OVF and stores it in the collection
*/
private VmDevice readVmDevice(XmlNode node, Guid deviceId) {
VmDevice vmDevice = new VmDevice();
vmDevice.setId(new VmDeviceId(deviceId, vmBase.getId()));
if (selectSingleNode(node, VMD_ADDRESS, _xmlNS) != null && !StringUtils.isEmpty(selectSingleNode(node, VMD_ADDRESS, _xmlNS).innerText)) {
vmDevice.setAddress(String.valueOf(selectSingleNode(node, VMD_ADDRESS, _xmlNS).innerText));
} else {
vmDevice.setAddress("");
}
if (selectSingleNode(node, VMD_ALIAS, _xmlNS) != null && !StringUtils.isEmpty(selectSingleNode(node, VMD_ALIAS, _xmlNS).innerText)) {
vmDevice.setAlias(String.valueOf(selectSingleNode(node, VMD_ALIAS, _xmlNS).innerText));
} else {
vmDevice.setAlias("");
}
XmlNode specParamsNode = selectSingleNode(node, VMD_SPEC_PARAMS, _xmlNS);
if (specParamsNode != null && !StringUtils.isEmpty(specParamsNode.innerText)) {
vmDevice.setSpecParams(getMapNode(specParamsNode));
} else {
// Empty map
vmDevice.setSpecParams(Collections.emptyMap());
}
if (selectSingleNode(node, VMD_TYPE, _xmlNS) != null && !StringUtils.isEmpty(selectSingleNode(node, VMD_TYPE, _xmlNS).innerText)) {
vmDevice.setType(VmDeviceGeneralType.forValue(String.valueOf(selectSingleNode(node, VMD_TYPE, _xmlNS).innerText)));
} else {
int resourceType = getResourceType(node, VMD_RESOURCE_TYPE);
vmDevice.setType(VmDeviceGeneralType.forValue(VmDeviceType.getoVirtDevice(resourceType)));
}
if (selectSingleNode(node, VMD_DEVICE, _xmlNS) != null && !StringUtils.isEmpty(selectSingleNode(node, VMD_DEVICE, _xmlNS).innerText)) {
vmDevice.setDevice(String.valueOf(selectSingleNode(node, VMD_DEVICE, _xmlNS).innerText));
} else {
setDeviceByResource(node, vmDevice);
}
if (selectSingleNode(node, VMD_IS_PLUGGED, _xmlNS) != null && !StringUtils.isEmpty(selectSingleNode(node, VMD_IS_PLUGGED, _xmlNS).innerText)) {
vmDevice.setPlugged(Boolean.valueOf(selectSingleNode(node, VMD_IS_PLUGGED, _xmlNS).innerText));
} else {
vmDevice.setPlugged(Boolean.TRUE);
}
if (selectSingleNode(node, VMD_IS_READONLY, _xmlNS) != null && !StringUtils.isEmpty(selectSingleNode(node, VMD_IS_READONLY, _xmlNS).innerText)) {
vmDevice.setReadOnly(Boolean.valueOf(selectSingleNode(node, VMD_IS_READONLY, _xmlNS).innerText));
} else {
vmDevice.setReadOnly(Boolean.FALSE);
}
if (selectSingleNode(node, VMD_CUSTOM_PROP, _xmlNS) != null && StringUtils.isNotEmpty(selectSingleNode(node, VMD_CUSTOM_PROP, _xmlNS).innerText)) {
vmDevice.setCustomProperties(DevicePropertiesUtils.getInstance().convertProperties(String.valueOf(selectSingleNode(node, VMD_CUSTOM_PROP, _xmlNS).innerText)));
} else {
vmDevice.setCustomProperties(null);
}
if (selectSingleNode(node, VMD_SNAPSHOT_PROP, _xmlNS) != null && StringUtils.isNotEmpty(selectSingleNode(node, VMD_SNAPSHOT_PROP, _xmlNS).innerText)) {
vmDevice.setSnapshotId(new Guid(String.valueOf(selectSingleNode(node, VMD_CUSTOM_PROP, _xmlNS).innerText)));
}
return vmDevice;
}
Aggregations