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);
}
}
}
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());
}
}
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);
}
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;
});
}
}
}
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));
}
Aggregations