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