Search in sources :

Example 1 with VmEntityType

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

the class DiskListModel method updateCopyAndMoveCommandAvailability.

private void updateCopyAndMoveCommandAvailability(List<Disk> disks) {
    boolean isCopyAllowed = true;
    boolean isMoveAllowed = true;
    if (disks == null || disks.isEmpty() || disks.get(0).getDiskStorageType() != DiskStorageType.IMAGE) {
        disableMoveAndCopyCommands();
        return;
    }
    Guid datacenterId = ((DiskImage) disks.get(0)).getStoragePoolId();
    boolean foundTemplateDisk = false;
    boolean foundVmDisk = false;
    boolean foundUnattachedDisk = false;
    for (Disk disk : disks) {
        if ((!isCopyAllowed && !isMoveAllowed) || disk.getDiskStorageType() != DiskStorageType.IMAGE) {
            disableMoveAndCopyCommands();
            return;
        }
        DiskImage diskImage = (DiskImage) disk;
        if (diskImage.getImageStatus() != ImageStatus.OK || !datacenterId.equals(diskImage.getStoragePoolId()) || diskImage.isOvfStore()) {
            disableMoveAndCopyCommands();
            return;
        }
        VmEntityType vmEntityType = disk.getVmEntityType();
        if (vmEntityType == null) {
            foundUnattachedDisk = true;
        } else if (vmEntityType.isTemplateType()) {
            foundTemplateDisk = true;
        } else if (vmEntityType.isVmType()) {
            foundVmDisk = true;
        }
        if (foundTemplateDisk && (foundUnattachedDisk || foundVmDisk)) {
            isCopyAllowed = false;
        }
        if (vmEntityType != null && vmEntityType.isTemplateType()) {
            isMoveAllowed = false;
        }
    }
    getCopyCommand().setIsExecutionAllowed(isCopyAllowed);
    getMoveCommand().setIsExecutionAllowed(isMoveAllowed);
}
Also used : Guid(org.ovirt.engine.core.compat.Guid) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) VmEntityType(org.ovirt.engine.core.common.businessentities.VmEntityType)

Example 2 with VmEntityType

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

the class AbstractDiskRowMapper method handleEntityType.

private static void handleEntityType(String entityType, Disk entity) {
    if (entityType != null && !entityType.isEmpty()) {
        VmEntityType vmEntityType = VmEntityType.valueOf(entityType);
        entity.setVmEntityType(vmEntityType);
    }
}
Also used : VmEntityType(org.ovirt.engine.core.common.businessentities.VmEntityType)

Example 3 with VmEntityType

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

the class OvfUtils method analyzeOvfFile.

private void analyzeOvfFile(List<UnregisteredDisk> unregisteredDisks, Guid storageDomainId, List<OvfEntityData> ovfEntityDataFromTar, Entry<String, ByteBuffer> fileEntry) {
    String ovfData = new String(fileEntry.getValue().array());
    VmEntityType vmType = getVmEntityType(ovfData);
    ArchitectureType archType = null;
    Guid entityId = getEntityId(fileEntry.getKey());
    String vmName = getEntityName(ovfData);
    try {
        XmlDocument xmlDocument = new XmlDocument(ovfData);
        archType = getOsSection(xmlDocument);
        if (isExternalVM(xmlDocument)) {
            log.warn("Retrieve an external OVF Entity from storage domain ID '{}' for entity ID '{}'," + " entity name '{}' and VM Type of '{}'." + " This OVF will be ignored since external VMs should not be restored.", storageDomainId, getEntityId(fileEntry.getKey()), getEntityName(ovfData), vmType.name());
            return;
        }
        updateUnregisteredDisksWithVMs(unregisteredDisks, entityId, vmName, xmlDocument);
    } catch (Exception e) {
        log.error("Could not parse VM's disks or architecture, file name: {}, content size: {}, error: {}", fileEntry.getKey(), ovfData.length(), e.getMessage());
        log.debug("Exception", e);
        return;
    }
    // Creates an OVF entity data.
    OvfEntityData ovfEntityData = createOvfEntityData(storageDomainId, ovfData, vmType, vmName, archType, entityId);
    log.info("Retrieve OVF Entity from storage domain ID '{}' for entity ID '{}', entity name '{}' and VM Type of '{}'", storageDomainId, getEntityId(fileEntry.getKey()), getEntityName(ovfData), vmType.name());
    ovfEntityDataFromTar.add(ovfEntityData);
}
Also used : ArchitectureType(org.ovirt.engine.core.common.businessentities.ArchitectureType) OvfEntityData(org.ovirt.engine.core.common.businessentities.OvfEntityData) XmlDocument(org.ovirt.engine.core.utils.ovf.xml.XmlDocument) Guid(org.ovirt.engine.core.compat.Guid) VmEntityType(org.ovirt.engine.core.common.businessentities.VmEntityType) IOException(java.io.IOException)

Example 4 with VmEntityType

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

the class OvfUtils method getVmEntityType.

private static VmEntityType getVmEntityType(String ovfData) {
    VmEntityType vmEntityType = VmEntityType.VM;
    int indexOfEntityType = ovfData.indexOf(TEMPLATE_ENTITY_TYPE);
    if (indexOfEntityType != -1) {
        vmEntityType = VmEntityType.TEMPLATE;
    }
    return vmEntityType;
}
Also used : VmEntityType(org.ovirt.engine.core.common.businessentities.VmEntityType)

Aggregations

VmEntityType (org.ovirt.engine.core.common.businessentities.VmEntityType)4 Guid (org.ovirt.engine.core.compat.Guid)2 IOException (java.io.IOException)1 ArchitectureType (org.ovirt.engine.core.common.businessentities.ArchitectureType)1 OvfEntityData (org.ovirt.engine.core.common.businessentities.OvfEntityData)1 CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)1 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)1 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)1 XmlDocument (org.ovirt.engine.core.utils.ovf.xml.XmlDocument)1