Search in sources :

Example 21 with VmDeviceId

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

the class OvfReader method readVmDevice.

/**
 * Reads vm device attributes from OVF and stores it in the collection
 */
private VmDevice readVmDevice(XmlNode node, Guid deviceId) {
    VmDevice vmDevice = new VmDevice();
    vmDevice.setId(new VmDeviceId(deviceId, vmBase.getId()));
    if (selectSingleNode(node, VMD_ADDRESS, _xmlNS) != null && !StringUtils.isEmpty(selectSingleNode(node, VMD_ADDRESS, _xmlNS).innerText)) {
        vmDevice.setAddress(String.valueOf(selectSingleNode(node, VMD_ADDRESS, _xmlNS).innerText));
    } else {
        vmDevice.setAddress("");
    }
    if (selectSingleNode(node, VMD_ALIAS, _xmlNS) != null && !StringUtils.isEmpty(selectSingleNode(node, VMD_ALIAS, _xmlNS).innerText)) {
        vmDevice.setAlias(String.valueOf(selectSingleNode(node, VMD_ALIAS, _xmlNS).innerText));
    } else {
        vmDevice.setAlias("");
    }
    XmlNode specParamsNode = selectSingleNode(node, VMD_SPEC_PARAMS, _xmlNS);
    if (specParamsNode != null && !StringUtils.isEmpty(specParamsNode.innerText)) {
        vmDevice.setSpecParams(getMapNode(specParamsNode));
    } else {
        // Empty map
        vmDevice.setSpecParams(Collections.emptyMap());
    }
    if (selectSingleNode(node, VMD_TYPE, _xmlNS) != null && !StringUtils.isEmpty(selectSingleNode(node, VMD_TYPE, _xmlNS).innerText)) {
        vmDevice.setType(VmDeviceGeneralType.forValue(String.valueOf(selectSingleNode(node, VMD_TYPE, _xmlNS).innerText)));
    } else {
        int resourceType = getResourceType(node, VMD_RESOURCE_TYPE);
        vmDevice.setType(VmDeviceGeneralType.forValue(VmDeviceType.getoVirtDevice(resourceType)));
    }
    if (selectSingleNode(node, VMD_DEVICE, _xmlNS) != null && !StringUtils.isEmpty(selectSingleNode(node, VMD_DEVICE, _xmlNS).innerText)) {
        vmDevice.setDevice(String.valueOf(selectSingleNode(node, VMD_DEVICE, _xmlNS).innerText));
    } else {
        setDeviceByResource(node, vmDevice);
    }
    if (selectSingleNode(node, VMD_IS_PLUGGED, _xmlNS) != null && !StringUtils.isEmpty(selectSingleNode(node, VMD_IS_PLUGGED, _xmlNS).innerText)) {
        vmDevice.setPlugged(Boolean.valueOf(selectSingleNode(node, VMD_IS_PLUGGED, _xmlNS).innerText));
    } else {
        vmDevice.setPlugged(Boolean.TRUE);
    }
    if (selectSingleNode(node, VMD_IS_READONLY, _xmlNS) != null && !StringUtils.isEmpty(selectSingleNode(node, VMD_IS_READONLY, _xmlNS).innerText)) {
        vmDevice.setReadOnly(Boolean.valueOf(selectSingleNode(node, VMD_IS_READONLY, _xmlNS).innerText));
    } else {
        vmDevice.setReadOnly(Boolean.FALSE);
    }
    if (selectSingleNode(node, VMD_CUSTOM_PROP, _xmlNS) != null && StringUtils.isNotEmpty(selectSingleNode(node, VMD_CUSTOM_PROP, _xmlNS).innerText)) {
        vmDevice.setCustomProperties(DevicePropertiesUtils.getInstance().convertProperties(String.valueOf(selectSingleNode(node, VMD_CUSTOM_PROP, _xmlNS).innerText)));
    } else {
        vmDevice.setCustomProperties(null);
    }
    if (selectSingleNode(node, VMD_SNAPSHOT_PROP, _xmlNS) != null && StringUtils.isNotEmpty(selectSingleNode(node, VMD_SNAPSHOT_PROP, _xmlNS).innerText)) {
        vmDevice.setSnapshotId(new Guid(String.valueOf(selectSingleNode(node, VMD_CUSTOM_PROP, _xmlNS).innerText)));
    }
    return vmDevice;
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) Guid(org.ovirt.engine.core.compat.Guid) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Example 22 with VmDeviceId

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

the class ImagesHandler method removeDiskFromVm.

public void removeDiskFromVm(Guid vmGuid, Guid diskId) {
    vmDeviceDao.remove(new VmDeviceId(diskId, vmGuid));
    baseDiskDao.remove(diskId);
}
Also used : VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Example 23 with VmDeviceId

use of org.ovirt.engine.core.common.businessentities.VmDeviceId 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;
}
Also used : Version(org.ovirt.engine.core.compat.Version) VM(org.ovirt.engine.core.common.businessentities.VM) FullEntityOvfData(org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId) OvfReaderException(org.ovirt.engine.core.utils.ovf.OvfReaderException)

Example 24 with VmDeviceId

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

the class ImagesHandler method removeLunDisk.

public void removeLunDisk(LunDisk lunDisk) {
    vmDeviceDao.remove(new VmDeviceId(lunDisk.getId(), null));
    LUNs lun = lunDisk.getLun();
    diskLunMapDao.remove(new DiskLunMapId(lunDisk.getId(), lun.getLUNId()));
    baseDiskDao.remove(lunDisk.getId());
    lun.setLunConnections(new ArrayList<>(storageServerConnectionDao.getAllForLun(lun.getLUNId())));
    if (!lun.getLunConnections().isEmpty()) {
        storageHelperDirector.getItem(lun.getLunConnections().get(0).getStorageType()).removeLun(lun);
    } else {
        // if there are no connections then the lun is fcp.
        storageHelperDirector.getItem(StorageType.FCP).removeLun(lun);
    }
}
Also used : DiskLunMapId(org.ovirt.engine.core.common.businessentities.storage.DiskLunMapId) LUNs(org.ovirt.engine.core.common.businessentities.storage.LUNs) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Example 25 with VmDeviceId

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

the class VmDeviceCommonUtils method addVideoDevice.

public static void addVideoDevice(VmBase vmBase) {
    if (vmBase.getDefaultDisplayType().getDefaultVmDeviceType() == null) {
        return;
    }
    VmDevice vmDevice = new VmDevice();
    vmDevice.setId(new VmDeviceId(Guid.newGuid(), vmBase.getId()));
    vmDevice.setType(VmDeviceGeneralType.VIDEO);
    vmDevice.setDevice(vmBase.getDefaultDisplayType().getDefaultVmDeviceType().getName());
    vmDevice.setManaged(true);
    vmDevice.setPlugged(true);
    vmDevice.setReadOnly(false);
    vmDevice.setAddress("");
    vmBase.getManagedDeviceMap().put(vmDevice.getDeviceId(), vmDevice);
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Aggregations

VmDeviceId (org.ovirt.engine.core.common.businessentities.VmDeviceId)75 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)40 DiskVmElement (org.ovirt.engine.core.common.businessentities.storage.DiskVmElement)21 Guid (org.ovirt.engine.core.compat.Guid)19 HashMap (java.util.HashMap)13 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)12 Test (org.junit.Test)10 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)9 ArrayList (java.util.ArrayList)7 Map (java.util.Map)5 GraphicsType (org.ovirt.engine.core.common.businessentities.GraphicsType)5 VM (org.ovirt.engine.core.common.businessentities.VM)5 VmPayload (org.ovirt.engine.core.common.businessentities.VmPayload)4 VmNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)4 VmNic (org.ovirt.engine.core.common.businessentities.network.VmNic)4 Collection (java.util.Collection)3 HashSet (java.util.HashSet)3 DisplayType (org.ovirt.engine.core.common.businessentities.DisplayType)3 CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)3 LunDisk (org.ovirt.engine.core.common.businessentities.storage.LunDisk)3