Search in sources :

Example 1 with OvfEntityData

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

the class ImportVmFromConfigurationCommand method initUnregisteredVM.

private void initUnregisteredVM() {
    List<OvfEntityData> ovfEntityDataList = unregisteredOVFDataDao.getByEntityIdAndStorageDomain(getParameters().getContainerId(), getParameters().getStorageDomainId());
    if (!ovfEntityDataList.isEmpty()) {
        try {
            // We should get only one entity, since we fetched the entity with a specific Storage Domain
            ovfEntityData = ovfEntityDataList.get(0);
            FullEntityOvfData fullEntityOvfData = ovfHelper.readVmFromOvf(ovfEntityData.getOvfData());
            VM vmFromConfiguration = fullEntityOvfData.getVm();
            if (Guid.isNullOrEmpty(getParameters().getClusterId())) {
                Cluster cluster = drMappingHelper.getMappedCluster(fullEntityOvfData.getClusterName(), vmFromConfiguration.getId(), getParameters().getClusterMap());
                if (cluster != null) {
                    getParameters().setClusterId(cluster.getId());
                }
            }
            vmFromConfiguration.setClusterId(getParameters().getClusterId());
            getParameters().setVm(vmFromConfiguration);
            getParameters().setDestDomainId(ovfEntityData.getStorageDomainId());
            getParameters().setSourceDomainId(ovfEntityData.getStorageDomainId());
            getParameters().setUserToRoles(fullEntityOvfData.getUserToRoles());
            // For quota, update disks when required
            if (getParameters().getDiskMap() != null) {
                vmFromConfiguration.setDiskMap(getParameters().getDiskMap());
                vmFromConfiguration.setImages(getDiskImageListFromDiskMap(getParameters().getDiskMap()));
            }
            // Note: The VM's OVF does not preserve the username and password for the LUN's connection.
            // Therefore to achieve a simple VM registration the iSCSI storage server should not use
            // credentials, although if the user will use the mapping attribute, one can set the credentials through
            // there.
            drMappingHelper.mapExternalLunDisks(DisksFilter.filterLunDisks(vmFromConfiguration.getDiskMap().values()), getParameters().getExternalLunMap());
            mapEntities(fullEntityOvfData);
        } catch (OvfReaderException e) {
            log.error("Failed to parse a given ovf configuration: {}:\n{}", e.getMessage(), ovfEntityData.getOvfData());
            log.debug("Exception", e);
        }
    }
}
Also used : VM(org.ovirt.engine.core.common.businessentities.VM) OvfEntityData(org.ovirt.engine.core.common.businessentities.OvfEntityData) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) FullEntityOvfData(org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData) OvfReaderException(org.ovirt.engine.core.utils.ovf.OvfReaderException)

Example 2 with OvfEntityData

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

the class ImportVmTemplateFromConfigurationCommand method initVmTemplate.

private void initVmTemplate() {
    List<OvfEntityData> ovfEntityList = unregisteredOVFDataDao.getByEntityIdAndStorageDomain(getParameters().getContainerId(), getParameters().getStorageDomainId());
    if (!ovfEntityList.isEmpty()) {
        try {
            // We should get only one entity, since we fetched the entity with a specific Storage Domain
            ovfEntityData = ovfEntityList.get(0);
            FullEntityOvfData fullEntityOvfData = ovfHelper.readVmTemplateFromOvf(ovfEntityData.getOvfData());
            vmTemplateFromConfiguration = fullEntityOvfData.getVmTemplate();
            if (Guid.isNullOrEmpty(getParameters().getClusterId())) {
                mapCluster(fullEntityOvfData);
            }
            vmTemplateFromConfiguration.setClusterId(getParameters().getClusterId());
            setVmTemplate(vmTemplateFromConfiguration);
            setEffectiveCompatibilityVersion(CompatibilityVersionUtils.getEffective(getVmTemplate(), this::getCluster));
            vmHandler.updateMaxMemorySize(getVmTemplate(), getEffectiveCompatibilityVersion());
            getParameters().setVmTemplate(vmTemplateFromConfiguration);
            getParameters().setDestDomainId(ovfEntityData.getStorageDomainId());
            getParameters().setSourceDomainId(ovfEntityData.getStorageDomainId());
            getParameters().setUserToRoles(fullEntityOvfData.getUserToRoles());
            // For quota, update disks when required
            if (getParameters().getDiskTemplateMap() != null) {
                ArrayList imageList = new ArrayList<>(getParameters().getDiskTemplateMap().values());
                vmTemplateFromConfiguration.setDiskList(imageList);
                ensureDomainMap(imageList, getParameters().getDestDomainId());
            }
            if (getParameters().getDomainMap() != null) {
                getParameters().setDbUsers(drMappingHelper.mapDbUsers(fullEntityOvfData.getDbUsers(), getParameters().getDomainMap()));
            } else {
                getParameters().setDbUsers(fullEntityOvfData.getDbUsers());
            }
            if (getParameters().getRoleMap() != null) {
                getParameters().setUserToRoles(drMappingHelper.mapRoles(getParameters().getRoleMap(), getParameters().getUserToRoles()));
            } else {
                getParameters().setUserToRoles(fullEntityOvfData.getUserToRoles());
            }
        } catch (OvfReaderException e) {
            log.error("Failed to parse a given ovf configuration: {}:\n{}", e.getMessage(), ovfEntityData.getOvfData());
            log.debug("Exception", e);
        }
    }
    setClusterId(getParameters().getClusterId());
    if (getCluster() != null) {
        setStoragePoolId(getCluster().getStoragePoolId());
    }
}
Also used : ArrayList(java.util.ArrayList) OvfEntityData(org.ovirt.engine.core.common.businessentities.OvfEntityData) FullEntityOvfData(org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData) OvfReaderException(org.ovirt.engine.core.utils.ovf.OvfReaderException)

Example 3 with OvfEntityData

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

the class ImportVmTemplateFromConfigurationCommand method findAndSaveDiskCopies.

private void findAndSaveDiskCopies() {
    List<OvfEntityData> ovfEntityDataList = unregisteredOVFDataDao.getByEntityIdAndStorageDomain(ovfEntityData.getEntityId(), null);
    List<ImageStorageDomainMap> copiedTemplateDisks = new LinkedList<>();
    for (OvfEntityData ovfEntityDataFetched : ovfEntityDataList) {
        populateDisksCopies(copiedTemplateDisks, getImages(), ovfEntityDataFetched.getStorageDomainId());
    }
    saveImageStorageDomainMapList(copiedTemplateDisks);
}
Also used : ImageStorageDomainMap(org.ovirt.engine.core.common.businessentities.storage.ImageStorageDomainMap) OvfEntityData(org.ovirt.engine.core.common.businessentities.OvfEntityData) LinkedList(java.util.LinkedList)

Example 4 with OvfEntityData

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

the class AddStoragePoolWithStoragesCommand method registerOvfStoreDisks.

private void registerOvfStoreDisks() {
    for (final Guid storageDomainId : getParameters().getStorages()) {
        if (storageDomainStaticDao.get(storageDomainId).getStorageDomainType().isDataDomain()) {
            resetOvfStoreAndUnregisteredDisks();
            TransactionSupport.executeInNewTransaction(() -> {
                List<DiskImage> ovfStoreDiskImages = getAllOVFDisks(storageDomainId, getStoragePool().getId());
                registerAllOvfDisks(ovfStoreDiskImages, storageDomainId);
                List<OvfEntityData> entitiesFromStorageOvfDisk = getEntitiesFromStorageOvfDisk(storageDomainId, getStoragePool().getId());
                // Update unregistered entities
                for (Object ovf : entitiesFromStorageOvfDisk) {
                    OvfEntityData ovfEntityData = (OvfEntityData) ovf;
                    unregisteredOVFDataDao.removeEntity(ovfEntityData.getEntityId(), storageDomainId);
                    unregisteredOVFDataDao.saveOVFData(ovfEntityData);
                    log.info("Adding OVF data of entity id '{}' and entity name '{}'", ovfEntityData.getEntityId(), ovfEntityData.getEntityName());
                }
                initUnregisteredDisksToDB(storageDomainId);
                return null;
            });
        }
    }
}
Also used : OvfEntityData(org.ovirt.engine.core.common.businessentities.OvfEntityData) Guid(org.ovirt.engine.core.compat.Guid) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 5 with OvfEntityData

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

the class GetUnregisteredVmTemplatesQueryTest method setUpQueryEntities.

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

Aggregations

OvfEntityData (org.ovirt.engine.core.common.businessentities.OvfEntityData)21 ArrayList (java.util.ArrayList)10 VM (org.ovirt.engine.core.common.businessentities.VM)4 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)4 FullEntityOvfData (org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData)4 Guid (org.ovirt.engine.core.compat.Guid)4 OvfReaderException (org.ovirt.engine.core.utils.ovf.OvfReaderException)4 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)3 IOException (java.io.IOException)2 LinkedList (java.util.LinkedList)2 Test (org.junit.Test)2 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)2 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)2 Pair (org.ovirt.engine.core.common.utils.Pair)2 XmlDocument (org.ovirt.engine.core.utils.ovf.xml.XmlDocument)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1