use of org.ovirt.engine.core.utils.ovf.xml.XmlNode in project ovirt-engine by oVirt.
the class OvfReader method readVmInit.
private void readVmInit(XmlNode content) {
XmlNode node = selectSingleNode(content, "VmInit");
VmInit vmInit = vmBase.getVmInit();
vmInit.setId(vmBase.getId());
if (node != null) {
if (node.attributes.get("ovf:hostname") != null) {
vmInit.setHostname(node.attributes.get("ovf:hostname").getValue());
}
if (node.attributes.get("ovf:domain") != null) {
vmInit.setDomain(node.attributes.get("ovf:domain").getValue());
}
if (node.attributes.get("ovf:timeZone") != null) {
vmInit.setTimeZone(node.attributes.get("ovf:timeZone").getValue());
}
if (node.attributes.get("ovf:authorizedKeys") != null) {
vmInit.setAuthorizedKeys(node.attributes.get("ovf:authorizedKeys").getValue());
}
if (node.attributes.get("ovf:regenerateKeys") != null) {
vmInit.setRegenerateKeys(Boolean.parseBoolean(node.attributes.get("ovf:regenerateKeys").getValue()));
}
if (node.attributes.get("ovf:dnsServers") != null) {
vmInit.setDnsServers(node.attributes.get("ovf:dnsServers").getValue());
}
if (node.attributes.get("ovf:dnsSearch") != null) {
vmInit.setDnsSearch(node.attributes.get("ovf:dnsSearch").getValue());
}
if (node.attributes.get("ovf:networks") != null) {
vmInit.setNetworks(VmInitUtils.jsonNetworksToList(node.attributes.get("ovf:networks").getValue()));
}
if (node.attributes.get("ovf:winKey") != null) {
vmInit.setWinKey(node.attributes.get("ovf:winKey").getValue());
}
if (node.attributes.get("ovf:rootPassword") != null) {
vmInit.setRootPassword(node.attributes.get("ovf:rootPassword").getValue());
}
if (node.attributes.get("ovf:customScript") != null) {
vmInit.setCustomScript(node.attributes.get("ovf:customScript").getValue());
}
}
}
use of org.ovirt.engine.core.utils.ovf.xml.XmlNode in project ovirt-engine by oVirt.
the class OvfReader method getMapNode.
private static Map<String, Object> getMapNode(XmlNode node) {
Map<String, Object> returnValue = new HashMap<>();
NodeList list = node.getChildNodes();
for (int index = 0; index < list.getLength(); ++index) {
Node currNode = list.item(index);
short nodeType = currNode.getNodeType();
if (nodeType == Node.ELEMENT_NODE) {
NodeList childNodes = currNode.getChildNodes();
// If the element node has only one child, then it contains the value
if (childNodes.getLength() == 1) {
Node valueNode = childNodes.item(0);
if (valueNode.getNodeType() == Node.TEXT_NODE) {
returnValue.put(currNode.getNodeName(), valueNode.getNodeValue());
}
} else if (childNodes.getLength() > 1) {
// In this case, we have a nested map, so we parse it
returnValue.put(currNode.getNodeName(), getMapNode(new XmlNode(currNode)));
}
}
}
return returnValue;
}
use of org.ovirt.engine.core.utils.ovf.xml.XmlNode in project ovirt-engine by oVirt.
the class OvfReader method setDeviceByResource.
private void setDeviceByResource(XmlNode node, VmDevice vmDevice) {
String resourceType = selectSingleNode(node, VMD_RESOURCE_TYPE, _xmlNS).innerText;
XmlNode resourceSubTypeNode = selectSingleNode(node, VMD_SUB_RESOURCE_TYPE, _xmlNS);
if (resourceSubTypeNode == null) {
// we need special handling for Monitor to define it as vnc or spice
if (OvfHardware.Monitor.equals(adjustHardwareResourceType(resourceType))) {
// get number of monitors from VirtualQuantity in OVF
if (selectSingleNode(node, VMD_VIRTUAL_QUANTITY, _xmlNS) != null && !StringUtils.isEmpty(selectSingleNode(node, VMD_VIRTUAL_QUANTITY, _xmlNS).innerText)) {
int virtualQuantity = Integer.parseInt(selectSingleNode(node, VMD_VIRTUAL_QUANTITY, _xmlNS).innerText);
if (virtualQuantity > 1) {
vmDevice.setDevice(VmDeviceType.QXL.getName());
} else {
// get first supported display device
List<Pair<GraphicsType, DisplayType>> supportedGraphicsAndDisplays = osRepository.getGraphicsAndDisplays(vmBase.getOsId(), new Version(getVersion()));
if (!supportedGraphicsAndDisplays.isEmpty()) {
DisplayType firstDisplayType = supportedGraphicsAndDisplays.get(0).getSecond();
vmDevice.setDevice(firstDisplayType.getDefaultVmDeviceType().getName());
} else {
vmDevice.setDevice(VmDeviceType.QXL.getName());
}
}
} else {
// default to spice if quantity not found
vmDevice.setDevice(VmDeviceType.QXL.getName());
}
} else {
vmDevice.setDevice(VmDeviceType.getoVirtDevice(Integer.parseInt(resourceType)).getName());
}
} else if (OvfHardware.Network.equals(resourceType)) {
// handle interfaces with different sub types : we have 0-5 as the VmInterfaceType enum
Integer nicTypeValue = getVmInterfaceType(resourceSubTypeNode);
VmInterfaceType nicType = nicTypeValue != null ? VmInterfaceType.forValue(nicTypeValue) : null;
if (nicType != null) {
if (nicType == VmInterfaceType.pciPassthrough) {
vmDevice.setDevice(VmDeviceType.HOST_DEVICE.getName());
} else {
vmDevice.setDevice(VmDeviceType.BRIDGE.getName());
}
} else {
vmDevice.setDevice(VmDeviceType.getoVirtDevice(Integer.parseInt(resourceType)).getName());
}
}
}
use of org.ovirt.engine.core.utils.ovf.xml.XmlNode in project ovirt-engine by oVirt.
the class OvfReader method readDiskImageItem.
protected void readDiskImageItem(XmlNode node, DiskImage image) {
XmlNode templateNode = selectSingleNode(node, "rasd:Template", _xmlNS);
if (templateNode != null && StringUtils.isNotEmpty(templateNode.innerText)) {
image.setImageTemplateId(new Guid(templateNode.innerText));
}
XmlNode applicationsNode = selectSingleNode(node, "rasd:ApplicationList", _xmlNS);
if (applicationsNode != null) {
image.setAppList(applicationsNode.innerText);
}
XmlNode storageNode = selectSingleNode(node, "rasd:StorageId", _xmlNS);
if (storageNode != null && StringUtils.isNotEmpty(storageNode.innerText)) {
image.setStorageIds(new ArrayList<>(Arrays.asList(new Guid(storageNode.innerText))));
}
XmlNode storagePoolNode = selectSingleNode(node, "rasd:StoragePoolId", _xmlNS);
if (storagePoolNode != null && StringUtils.isNotEmpty(storagePoolNode.innerText)) {
image.setStoragePoolId(new Guid(storagePoolNode.innerText));
}
XmlNode creationDateNode = selectSingleNode(node, "rasd:CreationDate", _xmlNS);
Date creationDate = creationDateNode != null ? OvfParser.utcDateStringToLocalDate(creationDateNode.innerText) : null;
if (creationDate != null) {
image.setCreationDate(creationDate);
}
XmlNode lastModifiedNode = selectSingleNode(node, "rasd:LastModified", _xmlNS);
Date lastModified = lastModifiedNode != null ? OvfParser.utcDateStringToLocalDate(lastModifiedNode.innerText) : null;
if (lastModified != null) {
image.setLastModified(lastModified);
}
XmlNode lastModifiedDateNode = selectSingleNode(node, "rasd:last_modified_date", _xmlNS);
Date last_modified_date = lastModifiedDateNode != null ? OvfParser.utcDateStringToLocalDate(lastModifiedDateNode.innerText) : null;
if (last_modified_date != null) {
image.setLastModifiedDate(last_modified_date);
}
VmDevice readDevice = readManagedVmDevice(node, image.getId());
image.setPlugged(readDevice.isPlugged());
}
use of org.ovirt.engine.core.utils.ovf.xml.XmlNode in project ovirt-engine by oVirt.
the class OvfVmReader method readEventLogValue.
private String readEventLogValue(XmlNode content, String name) {
StringBuilder fullNameSB = new StringBuilder(EXPORT_ONLY_PREFIX);
fullNameSB.append(name);
XmlNode node = selectSingleNode(content, fullNameSB.toString());
if (node != null) {
return node.innerText;
}
return null;
}
Aggregations