Search in sources :

Example 1 with VMStaticOvfLogHandler

use of org.ovirt.engine.core.utils.ovf.VMStaticOvfLogHandler in project ovirt-engine by oVirt.

the class SnapshotsManager method updateVmFromConfiguration.

/**
 * Update the given VM with the (static) data that is contained in the configuration. The {@link VM#getImages()}
 * will contain the images that were read from the configuration.
 *
 * @param vm
 *            The VM to update.
 * @param configuration
 *            The configuration to update from.
 * @return In case of a problem reading the configuration, <code>false</code>. Otherwise, <code>true</code>.
 */
public boolean updateVmFromConfiguration(VM vm, String configuration) {
    try {
        VmStatic oldVmStatic = vm.getStaticData();
        VM tempVM = new VM();
        if (vm.getDynamicData() != null) {
            tempVM.setDynamicData(vm.getDynamicData());
        }
        FullEntityOvfData fullEntityOvfData = new FullEntityOvfData(tempVM);
        ovfManager.importVm(configuration, tempVM, fullEntityOvfData);
        for (DiskImage diskImage : fullEntityOvfData.getDiskImages()) {
            DiskImage dbImage = diskImageDao.getSnapshotById(diskImage.getImageId());
            if (dbImage != null) {
                diskImage.setStorageIds(dbImage.getStorageIds());
            }
        }
        new VMStaticOvfLogHandler(tempVM.getStaticData()).resetDefaults(oldVmStatic);
        vm.setStaticData(tempVM.getStaticData());
        IconUtils.preserveIcons(vm.getStaticData(), oldVmStatic);
        vm.setImages((ArrayList<DiskImage>) fullEntityOvfData.getDiskImages());
        vm.setInterfaces(fullEntityOvfData.getInterfaces());
        // These fields are not saved in the OVF, so get them from the current VM.
        vm.setIsoPath(oldVmStatic.getIsoPath());
        vm.setCpuProfileId(oldVmStatic.getCpuProfileId());
        vm.setClusterId(oldVmStatic.getClusterId());
        // The VM configuration does not hold the vds group Id.
        // It is necessary to fetch the vm static from the Db, in order to get this information
        VmStatic vmStaticFromDb = vmStaticDao.get(vm.getId());
        if (vmStaticFromDb != null) {
            Cluster cluster = clusterDao.get(vmStaticFromDb.getClusterId());
            if (cluster != null) {
                vm.setStoragePoolId(cluster.getStoragePoolId());
                vm.setClusterCompatibilityVersion(cluster.getCompatibilityVersion());
                vm.setClusterName(cluster.getName());
                vm.setClusterCpuName(cluster.getCpuName());
            }
        }
        // if the required dedicated host is invalid -> use current VM dedicated host
        if (!vmHandler.validateDedicatedVdsExistOnSameCluster(vm.getStaticData()).isValid()) {
            vm.setDedicatedVmForVdsList(oldVmStatic.getDedicatedVmForVdsList());
        }
        vmHandler.updateMaxMemorySize(vm.getStaticData(), vm.getCompatibilityVersion());
        vmHandler.autoSelectResumeBehavior(vm.getStaticData(), vm.getCompatibilityVersion());
        validateQuota(vm);
        return true;
    } catch (OvfReaderException e) {
        log.error("Failed to update VM from the configuration '{}': {}", configuration, e.getMessage());
        log.debug("Exception", e);
        return false;
    }
}
Also used : VM(org.ovirt.engine.core.common.businessentities.VM) VMStaticOvfLogHandler(org.ovirt.engine.core.utils.ovf.VMStaticOvfLogHandler) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) FullEntityOvfData(org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) OvfReaderException(org.ovirt.engine.core.utils.ovf.OvfReaderException)

Example 2 with VMStaticOvfLogHandler

use of org.ovirt.engine.core.utils.ovf.VMStaticOvfLogHandler in project ovirt-engine by oVirt.

the class ImportVmCommandBase method logImportEvents.

private void logImportEvents() {
    // Some values at the OVF file are used for creating events at the GUI
    // for the sake of providing information on the content of the VM that
    // was exported,
    // but not setting it in the imported VM
    VmStatic vmStaticFromOvf = getVm().getStaticData();
    OvfLogEventHandler<VmStatic> handler = new VMStaticOvfLogHandler(vmStaticFromOvf);
    Map<String, String> aliasesValuesMap = handler.getAliasesValuesMap();
    if (aliasesValuesMap != null) {
        for (Map.Entry<String, String> entry : aliasesValuesMap.entrySet()) {
            String fieldName = entry.getKey();
            String fieldValue = entry.getValue();
            logField(vmStaticFromOvf, fieldName, fieldValue);
        }
    }
    handler.resetDefaults(vmStaticForDefaultValues);
}
Also used : VMStaticOvfLogHandler(org.ovirt.engine.core.utils.ovf.VMStaticOvfLogHandler) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

VmStatic (org.ovirt.engine.core.common.businessentities.VmStatic)2 VMStaticOvfLogHandler (org.ovirt.engine.core.utils.ovf.VMStaticOvfLogHandler)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)1 VM (org.ovirt.engine.core.common.businessentities.VM)1 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)1 FullEntityOvfData (org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData)1 OvfReaderException (org.ovirt.engine.core.utils.ovf.OvfReaderException)1