Search in sources :

Example 21 with FullEntityOvfData

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);
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VM(org.ovirt.engine.core.common.businessentities.VM) FullEntityOvfData(org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData) Test(org.junit.Test)

Example 22 with FullEntityOvfData

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;
}
Also used : VM(org.ovirt.engine.core.common.businessentities.VM) FullEntityOvfData(org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData)

Example 23 with FullEntityOvfData

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));
}
Also used : ArrayList(java.util.ArrayList) Label(org.ovirt.engine.core.common.businessentities.Label) FullEntityOvfData(org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData) LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk) AffinityGroup(org.ovirt.engine.core.common.scheduling.AffinityGroup) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser) HashSet(java.util.HashSet)

Example 24 with FullEntityOvfData

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;
}
Also used : VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) FullEntityOvfData(org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 25 with 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;
}
Also used : FullEntityOvfData(org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser) HashSet(java.util.HashSet)

Aggregations

FullEntityOvfData (org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData)27 VM (org.ovirt.engine.core.common.businessentities.VM)17 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)13 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)8 Guid (org.ovirt.engine.core.compat.Guid)7 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)6 HashMap (java.util.HashMap)5 OvfReaderException (org.ovirt.engine.core.utils.ovf.OvfReaderException)5 OvfEntityData (org.ovirt.engine.core.common.businessentities.OvfEntityData)4 DbUser (org.ovirt.engine.core.common.businessentities.aaa.DbUser)4 KeyValuePairCompat (org.ovirt.engine.core.compat.KeyValuePairCompat)4 HashSet (java.util.HashSet)3 List (java.util.List)2 Map (java.util.Map)2 Before (org.junit.Before)2 BaseCommandTest (org.ovirt.engine.core.bll.BaseCommandTest)2 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)2 Label (org.ovirt.engine.core.common.businessentities.Label)2 Snapshot (org.ovirt.engine.core.common.businessentities.Snapshot)2