use of org.ovirt.engine.core.common.businessentities.VM in project ovirt-engine by oVirt.
the class RemoveVmFromImportExportCommand method getVm.
/*
* get vm from export domain
*/
@Override
public VM getVm() {
if (exportVm == null) {
GetAllFromExportDomainQueryParameters tempVar = new GetAllFromExportDomainQueryParameters(getParameters().getStoragePoolId(), getParameters().getStorageDomainId());
tempVar.setIds(new ArrayList<>(Collections.singletonList(getVmId())));
QueryReturnValue qretVal = runInternalQuery(QueryType.GetVmsFromExportDomain, tempVar);
if (qretVal != null && qretVal.getSucceeded()) {
ArrayList<VM> vms = qretVal.getReturnValue();
if (!vms.isEmpty()) {
exportVm = vms.get(0);
setVm(exportVm);
}
}
}
return exportVm;
}
use of org.ovirt.engine.core.common.businessentities.VM in project ovirt-engine by oVirt.
the class VdsKdumpDetectionCommand method restartVdsVms.
private void restartVdsVms() {
List<VM> vms = vmDao.getAllRunningForVds(getVdsId());
if (!vms.isEmpty()) {
RestartVdsVmsOperation restartVmsOper = new RestartVdsVmsOperation(getContext(), getVds());
restartVmsOper.restartVms(vms);
runVdsCommand(VDSCommandType.UpdateVdsVMsCleared, new UpdateVdsVMsClearedVDSCommandParameters(getVds().getId()));
}
}
use of org.ovirt.engine.core.common.businessentities.VM in project ovirt-engine by oVirt.
the class OvfHelper method readVmFromOvf.
/**
* parses a given ovf to a vm, initialize all the extra data related to it such as images, interfaces, cluster,
* LUNS, etc..
*
* @return FullEntityOvfData that represents the given ovf data
*/
public FullEntityOvfData readVmFromOvf(String ovf) throws OvfReaderException {
VM vm = new VM();
FullEntityOvfData fullEntityOvfData = new FullEntityOvfData(vm);
ovfManager.importVm(ovf, vm, fullEntityOvfData);
// add images
vm.setImages((ArrayList) fullEntityOvfData.getDiskImages());
// add interfaces
vm.setInterfaces(fullEntityOvfData.getInterfaces());
// add disk map
Map<Guid, List<DiskImage>> images = ImagesHandler.getImagesLeaf(fullEntityOvfData.getDiskImages());
for (Map.Entry<Guid, List<DiskImage>> entry : images.entrySet()) {
List<DiskImage> list = entry.getValue();
vm.getDiskMap().put(entry.getKey(), list.get(list.size() - 1));
}
fullEntityOvfData.getLunDisks().forEach(lunDisk -> vm.getDiskMap().put(lunDisk.getId(), lunDisk));
return fullEntityOvfData;
}
use of org.ovirt.engine.core.common.businessentities.VM in project ovirt-engine by oVirt.
the class ProcessOvfUpdateForStoragePoolCommand method populateVmsMetadataForOvfUpdate.
/**
* Create and returns map contains valid vms metadata
*/
protected Map<Guid, KeyValuePairCompat<String, List<Guid>>> populateVmsMetadataForOvfUpdate(List<Guid> idsToProcess) {
Map<Guid, KeyValuePairCompat<String, List<Guid>>> vmsAndTemplateMetadata = new HashMap<>();
List<VM> vms = vmDao.getVmsByIds(idsToProcess);
for (VM vm : vms) {
if (VMStatus.ImageLocked != vm.getStatus()) {
updateVmDisksFromDb(vm);
if (!verifyImagesStatus(vm.getDiskList())) {
continue;
}
ArrayList<DiskImage> vmImages = ovfUpdateProcessHelper.getVmImagesFromDb(vm);
if (!verifyImagesStatus(vmImages)) {
continue;
}
vm.setSnapshots(snapshotDao.getAllWithConfiguration(vm.getId()));
if (!verifySnapshotsStatus(vm.getSnapshots())) {
continue;
}
ovfUpdateProcessHelper.loadVmData(vm);
Long currentDbGeneration = vmStaticDao.getDbGeneration(vm.getId());
if (currentDbGeneration == null) {
log.warn("currentDbGeneration of VM (name: '{}', id: '{}') is null, probably because the VM was deleted during the run of OvfDataUpdater.", vm.getName(), vm.getId());
continue;
}
if (vm.getStaticData().getDbGeneration() == currentDbGeneration) {
List<LunDisk> lunDisks = DisksFilter.filterLunDisks(vm.getDiskMap().values());
for (LunDisk lun : lunDisks) {
lun.getLun().setLunConnections(new ArrayList<>(storageServerConnectionDao.getAllForLun(lun.getLun().getId())));
}
List<AffinityGroup> affinityGroups = affinityGroupDao.getAllAffinityGroupsByVmId(vm.getId());
List<Label> affinityLabels = labelDao.getAllByEntityIds(Collections.singletonList(vm.getId()));
Set<DbUser> dbUsers = new HashSet<>(dbUserDao.getAllForVm(vm.getId()));
FullEntityOvfData fullEntityOvfData = new FullEntityOvfData(vm);
fullEntityOvfData.setDiskImages(vmImages);
fullEntityOvfData.setLunDisks(lunDisks);
fullEntityOvfData.setAffinityGroups(affinityGroups);
fullEntityOvfData.setAffinityLabels(affinityLabels);
fullEntityOvfData.setDbUsers(dbUsers);
ovfHelper.populateUserToRoles(fullEntityOvfData, vm.getId());
proccessedOvfConfigurationsInfo.add(ovfUpdateProcessHelper.buildMetadataDictionaryForVm(vm, vmsAndTemplateMetadata, fullEntityOvfData));
proccessedIdsInfo.add(vm.getId());
proccessedOvfGenerationsInfo.add(vm.getStaticData().getDbGeneration());
proccessDisksDomains(vm.getDiskList());
}
}
}
return vmsAndTemplateMetadata;
}
use of org.ovirt.engine.core.common.businessentities.VM in project ovirt-engine by oVirt.
the class GlusterStorageSyncCommand method executeCommand.
@Override
protected void executeCommand() {
// Get list of running VMs that have disks on storage domain
List<VM> vms = runInternalQuery(QueryType.GetVmsByStorageDomain, new IdQueryParameters(getStorageDomain().getId())).getReturnValue();
// Snapshot the VMs
Map<Guid, Guid> vmIdSnapshotIdMap = new HashMap<>();
for (VM vm : vms) {
try {
Future<ActionReturnValue> future = commandCoordinatorUtil.executeAsyncCommand(ActionType.CreateSnapshotForVm, getCreateSnapshotParameters(vm), cloneContextAndDetachFromParent());
vmIdSnapshotIdMap.put(vm.getId(), future.get().getActionReturnValue());
} catch (InterruptedException | ExecutionException e) {
log.error("Error creating VM snapshot for VM with id '{}', name '{}' for DR sync", vm.getId(), vm.getName(), e.getMessage());
log.debug("Exception", e);
endWithFailure();
getParameters().setTaskGroupSuccess(false);
}
}
getParameters().setVmIdSnapshotIds(vmIdSnapshotIdMap);
getParameters().setNextStep(DRStep.GEO_REP);
persistCommandIfNeeded();
setSucceeded(true);
}
Aggregations