use of org.ovirt.engine.core.utils.ovf.xml.XmlNode in project ovirt-engine by oVirt.
the class OvfOvirtReader method buildFileReference.
@Override
protected void buildFileReference() {
XmlNodeList list = selectNodes(_document, "//*/File", _xmlNS);
for (XmlNode node : list) {
// If the disk storage type is Cinder then override the disk image with Cinder object, otherwise use the
// disk image.
DiskImage disk = new DiskImage();
// image.
if (node.attributes.get("ovf:disk_storage_type") != null) {
String diskStorageType = node.attributes.get("ovf:disk_storage_type").getValue();
if (diskStorageType != null) {
if (diskStorageType.equals(DiskStorageType.LUN.name())) {
LunDisk lun = new LunDisk();
lun.setId(OvfParser.getImageGroupIdFromImageFile(node.attributes.get("ovf:href").getValue()));
luns.add(lun);
continue;
} else if (diskStorageType.equals(DiskStorageType.CINDER.name())) {
disk = new CinderDisk();
if (node.attributes.get("ovf:cinder_volume_type") != null) {
String cinderVolumeType = node.attributes.get("ovf:cinder_volume_type").getValue();
disk.setCinderVolumeType(cinderVolumeType);
}
}
}
}
disk.setImageId(new Guid(node.attributes.get("ovf:id").getValue()));
disk.setId(OvfParser.getImageGroupIdFromImageFile(node.attributes.get("ovf:href").getValue()));
disk.setDescription(node.attributes.get("ovf:description").getValue());
_images.add(disk);
}
}
use of org.ovirt.engine.core.utils.ovf.xml.XmlNode in project ovirt-engine by oVirt.
the class OvfOvirtReader method buildDisk.
@Override
public void buildDisk() {
XmlNodeList list = selectNodes(_document, "//*/Section/Disk");
for (XmlNode node : list) {
Guid guid = new Guid(node.attributes.get("ovf:diskId").getValue());
_images.stream().filter(d -> d.getImageId().equals(guid)).findFirst().ifPresent(img -> readDisk(node, img));
luns.stream().filter(d -> d.getId().equals(guid)).findFirst().ifPresent(lun -> readLunDisk(node, lun));
}
}
use of org.ovirt.engine.core.utils.ovf.xml.XmlNode in project ovirt-engine by oVirt.
the class OvfOvirtReader method readOsSection.
protected void readOsSection(XmlNode section) {
fullEntityOvfData.getVmBase().setId(new Guid(section.attributes.get("ovf:id").getValue()));
XmlNode node = selectSingleNode(section, "Description");
if (node != null) {
int osId = osRepository.getOsIdByUniqueName(node.innerText);
fullEntityOvfData.getVmBase().setOsId(osId);
setClusterArch(osRepository.getArchitectureFromOS(osId));
} else {
setClusterArch(ArchitectureType.undefined);
}
}
use of org.ovirt.engine.core.utils.ovf.xml.XmlNode in project ovirt-engine by oVirt.
the class OvfParser method isTemplate.
public boolean isTemplate() {
String id1 = "1";
String id2 = "2";
XmlNode node = _document.selectSingleNode("//*/Content/TemplateId");
if (!StringUtils.isBlank(node.innerText)) {
id1 = node.innerText;
}
XmlNodeList list = _document.selectNodes("//*/Content/Section");
for (XmlNode section : list) {
String value = section.attributes.get("xsi:type").getValue();
if (StringUtils.equals(value, "ovf:OperatingSystemSection_Type")) {
id2 = section.attributes.get("ovf:id").getValue();
}
}
return StringUtils.equals(id1, id2);
}
use of org.ovirt.engine.core.utils.ovf.xml.XmlNode in project ovirt-engine by oVirt.
the class OvfReader method readGeneralData.
protected void readGeneralData(XmlNode content) {
vmBase.setVmInit(new VmInit());
consumeReadProperty(content, DESCRIPTION, val -> vmBase.setDescription(val));
consumeReadProperty(content, COMMENT, val -> vmBase.setComment(val));
consumeReadProperty(content, DOMAIN, val -> vmBase.getVmInit().setDomain(val));
consumeReadProperty(content, CREATION_DATE, val -> vmBase.setCreationDate(OvfParser.utcDateStringToLocalDate(val)));
consumeReadProperty(content, EXPORT_DATE, val -> vmBase.setExportDate(OvfParser.utcDateStringToLocalDate(val)));
consumeReadProperty(content, DEFAULT_BOOT_SEQUENCE, val -> vmBase.setDefaultBootSequence(BootSequence.forValue(Integer.parseInt(val))));
consumeReadProperty(content, INITRD_URL, val -> vmBase.setInitrdUrl(val));
consumeReadProperty(content, KERNEL_URL, val -> vmBase.setKernelUrl(val));
consumeReadProperty(content, KERNEL_PARAMS, val -> vmBase.setKernelParams(val));
consumeReadProperty(content, GENERATION, val -> vmBase.setDbGeneration(Long.parseLong(val)), () -> vmBase.setDbGeneration(1L));
XmlNode node = selectSingleNode(content, CUSTOM_COMPATIBILITY_VERSION);
if (node != null) {
vmBase.setCustomCompatibilityVersion(new Version(node.innerText));
}
// the originating ENGINE version
Version originVersion = new Version(getVersion());
node = selectSingleNode(content, CLUSTER_COMPATIBILITY_VERSION);
if (node != null) {
originVersion = new Version(node.innerText);
}
vmBase.setClusterCompatibilityVersionOrigin(originVersion);
// Note: the fetching of 'default display type' should happen before reading
// the hardware section
consumeReadProperty(content, getDefaultDisplayTypeStringRepresentation(), val -> vmBase.setDefaultDisplayType(DisplayType.forValue(Integer.parseInt(val))));
// after reading the hardware section, if graphics device is still absent, add a default one
addDefaultGraphicsDevice();
fixDiskVmElements();
// due to dependency on vmBase.getOsId() must be read AFTER readOsSection
consumeReadProperty(content, TIMEZONE, val -> vmBase.setTimeZone(val), () -> {
if (osRepository.isWindows(vmBase.getOsId())) {
vmBase.setTimeZone(Config.getValue(ConfigValues.DefaultWindowsTimeZone));
} else {
vmBase.setTimeZone(Config.getValue(ConfigValues.DefaultGeneralTimeZone));
}
});
consumeReadProperty(content, ORIGIN, val -> vmBase.setOrigin(OriginType.forValue(Integer.parseInt(val))));
consumeReadProperty(content, VM_TYPE, val -> vmBase.setVmType(VmType.forValue(Integer.parseInt(val))));
consumeReadProperty(content, RESUME_BEHAVIOR, val -> vmBase.setResumeBehavior(VmResumeBehavior.valueOf(val)));
consumeReadProperty(content, IS_SMARTCARD_ENABLED, val -> vmBase.setSmartcardEnabled(Boolean.parseBoolean(val)));
consumeReadProperty(content, NUM_OF_IOTHREADS, val -> vmBase.setNumOfIoThreads(Integer.parseInt(val)));
consumeReadProperty(content, DELETE_PROTECTED, val -> vmBase.setDeleteProtected(Boolean.parseBoolean(val)));
consumeReadProperty(content, SSO_METHOD, val -> vmBase.setSsoMethod(SsoMethod.fromString(val)));
consumeReadProperty(content, TUNNEL_MIGRATION, val -> vmBase.setTunnelMigration(Boolean.parseBoolean(val)));
consumeReadProperty(content, VNC_KEYBOARD_LAYOUT, val -> vmBase.setVncKeyboardLayout(val));
consumeReadProperty(content, MIN_ALLOCATED_MEMORY, val -> vmBase.setMinAllocatedMem(Integer.parseInt(val)));
consumeReadProperty(content, IS_STATELESS, val -> vmBase.setStateless(Boolean.parseBoolean(val)));
consumeReadProperty(content, IS_RUN_AND_PAUSE, val -> vmBase.setRunAndPause(Boolean.parseBoolean(val)));
consumeReadProperty(content, CREATED_BY_USER_ID, val -> vmBase.setCreatedByUserId(Guid.createGuidFromString(val)));
consumeReadProperty(content, MIGRATION_DOWNTIME, val -> vmBase.setMigrationDowntime(Integer.parseInt(val)));
consumeReadProperty(content, MIGRATION_SUPPORT, val -> vmBase.setMigrationSupport(MigrationSupport.forValue(Integer.parseInt(val))));
// TODO dedicated to multiple hosts
readDedicatedHostsList();
consumeReadProperty(content, SERIAL_NUMBER_POLICY, val -> vmBase.setSerialNumberPolicy(SerialNumberPolicy.forValue(Integer.parseInt(val))));
consumeReadProperty(content, CUSTOM_SERIAL_NUMBER, val -> vmBase.setCustomSerialNumber(val));
consumeReadProperty(content, AUTO_STARTUP, val -> vmBase.setAutoStartup(Boolean.parseBoolean(val)));
consumeReadProperty(content, PRIORITY, val -> vmBase.setPriority(Integer.parseInt(val)));
consumeReadProperty(content, IS_BOOT_MENU_ENABLED, val -> vmBase.setBootMenuEnabled(Boolean.parseBoolean(val)));
consumeReadProperty(content, IS_SPICE_FILE_TRANSFER_ENABLED, val -> vmBase.setSpiceFileTransferEnabled(Boolean.parseBoolean(val)));
consumeReadProperty(content, IS_SPICE_COPY_PASTE_ENABLED, val -> vmBase.setSpiceCopyPasteEnabled(Boolean.parseBoolean(val)));
consumeReadProperty(content, ALLOW_CONSOLE_RECONNECT, val -> vmBase.setAllowConsoleReconnect(Boolean.parseBoolean(val)));
consumeReadProperty(content, CONSOLE_DISCONNECT_ACTION, val -> vmBase.setConsoleDisconnectAction(ConsoleDisconnectAction.fromString(val)));
consumeReadProperty(content, IS_AUTO_CONVERGE, val -> vmBase.setAutoConverge(Boolean.parseBoolean(val)));
consumeReadProperty(content, IS_MIGRATE_COMPRESSED, val -> vmBase.setMigrateCompressed(Boolean.parseBoolean(val)));
consumeReadProperty(content, MIGRATION_POLICY_ID, val -> vmBase.setMigrationPolicyId(Guid.createGuidFromString(val)));
consumeReadProperty(content, CUSTOM_EMULATED_MACHINE, val -> vmBase.setCustomEmulatedMachine(val));
consumeReadProperty(content, CUSTOM_CPU_NAME, val -> vmBase.setCustomCpuName(val));
consumeReadProperty(content, PREDEFINED_PROPERTIES, val -> vmBase.setPredefinedProperties(val));
consumeReadProperty(content, USER_DEFINED_PROPERTIES, val -> vmBase.setUserDefinedProperties(val));
consumeReadProperty(content, MAX_MEMORY_SIZE_MB, val -> vmBase.setMaxMemorySizeMb(Integer.parseInt(val)));
vmBase.setCustomProperties(VmPropertiesUtils.getInstance().customProperties(vmBase.getPredefinedProperties(), vmBase.getUserDefinedProperties()));
consumeReadProperty(content, VM_LEASE, val -> vmBase.setLeaseStorageDomainId(new Guid(val)));
readVmInit(content);
}
Aggregations