Search in sources :

Example 6 with FullEntityOvfData

use of org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData in project ovirt-engine by oVirt.

the class GetUnregisteredVmsQueryTest method setUpQueryEntities.

private void setUpQueryEntities() throws OvfReaderException {
    // Set up the expected result
    VM vmReturnForOvf = new VM();
    vmReturnForOvf.setId(newVmGuid);
    vmReturnForOvf.setName("Name");
    String ovfData = new String("OVF data for the first VM");
    OvfEntityData ovfEntityData = new OvfEntityData(vmReturnForOvf.getId(), vmReturnForOvf.getName(), VmEntityType.VM, null, null, storageDomainId, ovfData, null);
    ovfEntityData.setStatus(vmStatus);
    List<OvfEntityData> expectedResultQuery1 = new ArrayList<>();
    expectedResultQuery1.add(ovfEntityData);
    List<OvfEntityData> expectedResult = new ArrayList<>();
    expectedResult.add(ovfEntityData);
    VM vmReturnForOvf2 = new VM();
    vmReturnForOvf2.setId(newVmGuid2);
    vmReturnForOvf2.setName("Name2");
    String ovfData2 = new String("OVF data for the second VM");
    OvfEntityData ovfEntityData2 = new OvfEntityData(vmReturnForOvf2.getId(), vmReturnForOvf2.getName(), VmEntityType.VM, null, null, storageDomainId, ovfData2, null);
    ovfEntityData2.setStatus(vmStatus2);
    expectedResult.add(ovfEntityData2);
    List<OvfEntityData> expectedResultQuery2 = new ArrayList<>();
    expectedResultQuery2.add(ovfEntityData);
    // Mock the Daos
    when(unregisteredOVFDataDaoMock.getAllForStorageDomainByEntityType(storageDomainId, entityType)).thenReturn(expectedResult);
    when(unregisteredOVFDataDaoMock.getByEntityIdAndStorageDomain(newVmGuid2, storageDomainId)).thenReturn(expectedResultQuery2);
    when(unregisteredOVFDataDaoMock.getByEntityIdAndStorageDomain(newVmGuid, storageDomainId)).thenReturn(expectedResultQuery1);
    // Mock OVF
    when(ovfHelperMock.readVmFromOvf(ovfData)).thenReturn(new FullEntityOvfData(vmReturnForOvf));
    when(ovfHelperMock.readVmFromOvf(ovfData2)).thenReturn(new FullEntityOvfData(vmReturnForOvf2));
}
Also used : VM(org.ovirt.engine.core.common.businessentities.VM) ArrayList(java.util.ArrayList) OvfEntityData(org.ovirt.engine.core.common.businessentities.OvfEntityData) FullEntityOvfData(org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData)

Example 7 with FullEntityOvfData

use of org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData in project ovirt-engine by oVirt.

the class OvfManagerTest method testVmOvfCreationDefaultGraphicsDeviceFallbackToSupported.

@Test
public void testVmOvfCreationDefaultGraphicsDeviceFallbackToSupported() throws Exception {
    VM vm = createVM();
    vm.setDefaultDisplayType(DisplayType.cirrus);
    vm.setVmOs(EXISTING_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.SPICE.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 8 with FullEntityOvfData

use of org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData in project ovirt-engine by oVirt.

the class HostedEngineOvfWriterTest method setup.

@Before
public void setup() {
    initVm();
    fullEntityOvfData = new FullEntityOvfData();
    emulatedMachine = "pc";
    cpuId = "SandyBridge";
    engineXml = "<Envelope></Envelope>";
    underTest = new HostedEngineOvfWriter(vm, fullEntityOvfData, version, emulatedMachine, cpuId, osRepository, engineXml);
}
Also used : FullEntityOvfData(org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData) Before(org.junit.Before)

Example 9 with FullEntityOvfData

use of org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData in project ovirt-engine by oVirt.

the class ImagesHandler method prepareSnapshotConfigWithAlternateImage.

/**
 * Prepare a single {@link org.ovirt.engine.core.common.businessentities.Snapshot} object representing a snapshot of a given VM without the given disk,
 * substituting a new disk in its place if a new disk is provided to the method.
 */
public Snapshot prepareSnapshotConfigWithAlternateImage(Snapshot snapshot, Guid oldImageId, DiskImage newImage, OvfManager ovfManager) {
    if (snapshot == null) {
        return null;
    }
    try {
        String snapConfig = snapshot.getVmConfiguration();
        if (snapshot.isVmConfigurationAvailable() && snapConfig != null) {
            VM vmSnapshot = new VM();
            FullEntityOvfData fullEntityOvfData = new FullEntityOvfData(vmSnapshot);
            ovfManager.importVm(snapConfig, vmSnapshot, fullEntityOvfData);
            // Remove the image from the disk list
            Iterator<DiskImage> diskIter = fullEntityOvfData.getDiskImages().iterator();
            while (diskIter.hasNext()) {
                DiskImage imageInList = diskIter.next();
                if (imageInList.getImageId().equals(oldImageId)) {
                    log.debug("Recreating vmSnapshot '{}' without the image '{}'", snapshot.getId(), oldImageId);
                    diskIter.remove();
                    break;
                }
            }
            if (newImage != null) {
                log.debug("Adding image '{}' to vmSnapshot '{}'", newImage.getImageId(), snapshot.getId());
                newImage.setDiskVmElements(Collections.singletonList(diskVmElementDao.get(new VmDeviceId(newImage.getId(), vmSnapshot.getId()))));
                fullEntityOvfData.getDiskImages().add(newImage);
            }
            final Version compatibilityVersion = Optional.ofNullable(vmSnapshot.getStaticData().getClusterCompatibilityVersionOrigin()).orElse(Version.getLowest());
            FullEntityOvfData fullEntityOvfDataForExport = new FullEntityOvfData(vmSnapshot);
            fullEntityOvfDataForExport.setDiskImages(fullEntityOvfData.getDiskImages());
            String newOvf = ovfManager.exportVm(vmSnapshot, fullEntityOvfDataForExport, compatibilityVersion);
            snapshot.setVmConfiguration(newOvf);
        }
    } catch (OvfReaderException e) {
        log.error("Can't remove image '{}' from snapshot '{}'", oldImageId, snapshot.getId());
    }
    return snapshot;
}
Also used : Version(org.ovirt.engine.core.compat.Version) VM(org.ovirt.engine.core.common.businessentities.VM) FullEntityOvfData(org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId) OvfReaderException(org.ovirt.engine.core.utils.ovf.OvfReaderException)

Example 10 with FullEntityOvfData

use of org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData in project ovirt-engine by oVirt.

the class ExportVmCommand method updateCopyVmInSpm.

private void updateCopyVmInSpm(Guid storagePoolId, VM vm, Guid storageDomainId) {
    HashMap<Guid, KeyValuePairCompat<String, List<Guid>>> vmsAndMetaDictionary = new HashMap<>();
    List<DiskImage> vmImages = new ArrayList<>();
    List<LunDisk> lunDisks = new ArrayList<>();
    List<VmNetworkInterface> interfaces = vm.getInterfaces();
    if (interfaces != null) {
        // TODO remove this when the API changes
        interfaces.clear();
        interfaces.addAll(vmNetworkInterfaceDao.getAllForVm(vm.getId()));
    }
    List<Guid> imageGroupIds = new ArrayList<>();
    for (Disk disk : getDisksBasedOnImage()) {
        DiskImage diskImage = (DiskImage) disk;
        diskImage.setParentId(VmTemplateHandler.BLANK_VM_TEMPLATE_ID);
        diskImage.setImageTemplateId(VmTemplateHandler.BLANK_VM_TEMPLATE_ID);
        diskImage.setStorageIds(new ArrayList<>(Collections.singletonList(storageDomainId)));
        DiskImage diskForVolumeInfo = getDiskForVolumeInfo(diskImage);
        diskImage.setVolumeFormat(diskForVolumeInfo.getVolumeFormat());
        diskImage.setVolumeType(diskForVolumeInfo.getVolumeType());
        VDSReturnValue vdsReturnValue = runVdsCommand(VDSCommandType.GetImageInfo, new GetImageInfoVDSCommandParameters(storagePoolId, storageDomainId, diskImage.getId(), diskImage.getImageId()));
        if (vdsReturnValue != null && vdsReturnValue.getSucceeded()) {
            DiskImage fromVdsm = (DiskImage) vdsReturnValue.getReturnValue();
            diskImage.setActualSizeInBytes(fromVdsm.getActualSizeInBytes());
        }
        vmImages.add(diskImage);
        imageGroupIds.add(disk.getId());
    }
    if (StringUtils.isEmpty(vm.getVmtName())) {
        VmTemplate t = vmTemplateDao.get(vm.getVmtGuid());
        vm.setVmtName(t.getName());
    }
    lunDisks.addAll(DisksFilter.filterLunDisks(getVm().getDiskMap().values(), ONLY_NOT_SHAREABLE));
    lunDisks.forEach(lun -> lun.getLun().setLunConnections(new ArrayList<>(storageServerConnectionDao.getAllForLun(lun.getLun().getId()))));
    getVm().setVmtGuid(VmTemplateHandler.BLANK_VM_TEMPLATE_ID);
    FullEntityOvfData fullEntityOvfData = new FullEntityOvfData(vm);
    fullEntityOvfData.setClusterName(vm.getClusterName());
    fullEntityOvfData.setDiskImages(vmImages);
    fullEntityOvfData.setLunDisks(lunDisks);
    String vmMeta = ovfManager.exportVm(vm, fullEntityOvfData, clusterUtils.getCompatibilityVersion(vm));
    vmsAndMetaDictionary.put(vm.getId(), new KeyValuePairCompat<>(vmMeta, imageGroupIds));
    UpdateVMVDSCommandParameters tempVar = new UpdateVMVDSCommandParameters(storagePoolId, vmsAndMetaDictionary);
    tempVar.setStorageDomainId(storageDomainId);
    runVdsCommand(VDSCommandType.UpdateVM, tempVar);
}
Also used : GetImageInfoVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.GetImageInfoVDSCommandParameters) KeyValuePairCompat(org.ovirt.engine.core.compat.KeyValuePairCompat) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) UpdateVMVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.UpdateVMVDSCommandParameters) Guid(org.ovirt.engine.core.compat.Guid) FullEntityOvfData(org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData) LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk)

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