use of org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData in project ovirt-engine by oVirt.
the class OvfManagerTest method testVmOvfCreationDefaultGraphicsDevice.
@Test
public void testVmOvfCreationDefaultGraphicsDevice() throws Exception {
VM vm = createVM();
vm.setDefaultDisplayType(DisplayType.cirrus);
vm.setVmOs(DEFAULT_OS_ID);
String xml = manager.exportVm(vm, new FullEntityOvfData(vm), Version.getLast());
assertNotNull(xml);
final VM newVm = new VM();
FullEntityOvfData fullEntityOvfData = new FullEntityOvfData(newVm);
manager.importVm(xml, newVm, fullEntityOvfData);
int graphicsDeviceCount = 0;
for (VmDevice device : newVm.getManagedVmDeviceMap().values()) {
if (device.getType() == VmDeviceGeneralType.GRAPHICS) {
graphicsDeviceCount++;
assertEquals(device.getDevice(), VmDeviceType.VNC.getName());
}
}
assertEquals(1, graphicsDeviceCount);
}
use of org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData in project ovirt-engine by oVirt.
the class OvfHelper method readVmFromOva.
/**
* parses a given ovf to a vm, intialized with images and interfaces.
* unlike {@link #readVmFromOvf(String)}, the given ovf is taken from ova
* and thus closer to the OVF specification.
* @return
* Pair of VM that represents the given ovf data and a Map that
* Maps disk UUID to a pair of (filename, actual size) as they are within the OVA
*/
public VM readVmFromOva(String ovf) throws OvfReaderException {
ovf = ovf.replaceAll("[\r\n]+", // remove new lines
"").replaceAll("xmlns=[^-\\s]*", // remove global namespace
"");
VM vm = new VM();
FullEntityOvfData fullEntityOvfData = new FullEntityOvfData(vm);
ovfManager.importVmFromOva(ovf, vm, fullEntityOvfData);
// add images
vm.setImages((ArrayList) fullEntityOvfData.getDiskImages());
// add interfaces
vm.setInterfaces(fullEntityOvfData.getInterfaces());
// add disk map
fullEntityOvfData.getDiskImages().forEach(image -> vm.getDiskMap().put(image.getId(), image));
return vm;
}
use of org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData in project ovirt-engine by oVirt.
the class OvfHelper method buildMetadataDictionaryForVm.
/**
* Adds the given vm metadata to the given map
*/
private String buildMetadataDictionaryForVm(VM vm) {
List<DiskImage> allVmImages = new ArrayList<>();
List<DiskImage> filteredDisks = DisksFilter.filterImageDisks(vm.getDiskList(), ONLY_SNAPABLE, ONLY_ACTIVE);
List<LunDisk> lunDisks = DisksFilter.filterLunDisks(vm.getDiskMap().values());
List<AffinityGroup> affinityGroups = affinityGroupDao.getAllAffinityGroupsByVmId(vm.getId());
Set<DbUser> dbUsers = new HashSet<>(dbUserDao.getAllForVm(vm.getId()));
List<Label> affinityLabels = labelDao.getAllByEntityIds(Collections.singletonList(vm.getId()));
for (DiskImage diskImage : filteredDisks) {
List<DiskImage> images = diskImageDao.getAllSnapshotsForLeaf(diskImage.getImageId());
images.forEach(d -> d.setDiskVmElements(Collections.singletonList(diskImage.getDiskVmElementForVm(vm.getId()))));
allVmImages.addAll(images);
}
FullEntityOvfData fullEntityOvfData = new FullEntityOvfData(vm);
fullEntityOvfData.setDiskImages(allVmImages);
fullEntityOvfData.setLunDisks(lunDisks);
fullEntityOvfData.setAffinityGroups(affinityGroups);
fullEntityOvfData.setAffinityLabels(affinityLabels);
fullEntityOvfData.setDbUsers(dbUsers);
populateUserToRoles(fullEntityOvfData, vm.getId());
return ovfManager.exportVm(vm, fullEntityOvfData, clusterUtils.getCompatibilityVersion(vm));
}
use of org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData in project ovirt-engine by oVirt.
the class OvfHelper method readVmTemplateFromOvf.
/**
* parses a given ovf to a VmTemplate, initialized with images and interfaces.
* @return
* VmTemplate that represents the given ovf data
*/
public FullEntityOvfData readVmTemplateFromOvf(String ovf) throws OvfReaderException {
VmTemplate template = new VmTemplate();
FullEntityOvfData fullEntityOvfData = new FullEntityOvfData(template);
ovfManager.importTemplate(ovf, fullEntityOvfData);
template.setInterfaces(fullEntityOvfData.getInterfaces());
// add disk map
for (DiskImage disk : fullEntityOvfData.getDiskImages()) {
template.getDiskTemplateMap().put(disk.getId(), disk);
}
return fullEntityOvfData;
}
use of org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData in project ovirt-engine by oVirt.
the class OvfUpdateProcessHelper method buildMetadataDictionaryForTemplate.
/**
* Adds the given template metadata to the given map
*/
public String buildMetadataDictionaryForTemplate(VmTemplate template, Map<Guid, KeyValuePairCompat<String, List<Guid>>> metaDictionary) {
List<DiskImage> allTemplateImages = template.getDiskList();
Set<DbUser> dbUsers = new HashSet<>(dbUserDao.getAllForTemplate(template.getId()));
FullEntityOvfData fullEntityOvfData = new FullEntityOvfData(template);
fullEntityOvfData.setDbUsers(dbUsers);
fullEntityOvfData.setDiskImages(allTemplateImages);
ovfHelper.populateUserToRoles(fullEntityOvfData, template.getId());
String templateMeta = generateVmTemplateMetadata(fullEntityOvfData);
metaDictionary.put(template.getId(), new KeyValuePairCompat<>(templateMeta, allTemplateImages.stream().map(BaseDisk::getId).collect(Collectors.toList())));
return templateMeta;
}
Aggregations