Search in sources :

Example 1 with VmPayload

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

the class ProcessDownVmCommand method createUpdateVmParameters.

private VmManagementParametersBase createUpdateVmParameters() {
    // clear non updateable fields got from config
    getVm().setExportDate(null);
    getVm().setOvfVersion(null);
    VmManagementParametersBase updateVmParams = new VmManagementParametersBase(getVm());
    updateVmParams.setUpdateWatchdog(true);
    updateVmParams.setSoundDeviceEnabled(false);
    updateVmParams.setBalloonEnabled(false);
    updateVmParams.setVirtioScsiEnabled(false);
    updateVmParams.setClearPayload(true);
    updateVmParams.setUpdateRngDevice(true);
    for (GraphicsType graphicsType : GraphicsType.values()) {
        updateVmParams.getGraphicsDevices().put(graphicsType, null);
    }
    for (VmDevice device : getVm().getManagedVmDeviceMap().values()) {
        switch(device.getType()) {
            case WATCHDOG:
                updateVmParams.setWatchdog(new VmWatchdog(device));
                break;
            case SOUND:
                updateVmParams.setSoundDeviceEnabled(true);
                break;
            case BALLOON:
                updateVmParams.setBalloonEnabled(true);
                break;
            case CONTROLLER:
                if (VmDeviceType.VIRTIOSCSI.getName().equals(device.getDevice())) {
                    updateVmParams.setVirtioScsiEnabled(true);
                }
                break;
            case DISK:
                if (VmPayload.isPayload(device.getSpecParams())) {
                    updateVmParams.setVmPayload(new VmPayload(device));
                }
                break;
            case CONSOLE:
                updateVmParams.setConsoleEnabled(true);
                break;
            case RNG:
                updateVmParams.setRngDevice(new VmRngDevice(device));
                break;
            case GRAPHICS:
                updateVmParams.getGraphicsDevices().put(GraphicsType.fromString(device.getDevice()), new GraphicsDevice(device));
                break;
            default:
        }
    }
    // clear these fields as these are non updatable
    getVm().getManagedVmDeviceMap().clear();
    getVm().getUnmanagedDeviceList().clear();
    return updateVmParams;
}
Also used : GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) GraphicsDevice(org.ovirt.engine.core.common.businessentities.GraphicsDevice) VmPayload(org.ovirt.engine.core.common.businessentities.VmPayload) VmManagementParametersBase(org.ovirt.engine.core.common.action.VmManagementParametersBase) VmWatchdog(org.ovirt.engine.core.common.businessentities.VmWatchdog) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice)

Example 2 with VmPayload

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

the class VmMapper method map.

@Mapping(from = VmPayload.class, to = Payload.class)
public static Payload map(VmPayload entity, Payload template) {
    if (entity.getDeviceType() != null || entity.getFiles().isEmpty()) {
        Payload model = template != null ? template : new Payload();
        if (entity.getDeviceType() != null) {
            org.ovirt.engine.api.model.VmDeviceType deviceType = map(entity.getDeviceType(), null);
            if (deviceType != null) {
                model.setType(deviceType);
            }
        }
        model.setVolumeId(entity.getVolumeId());
        if (entity.getFiles().size() > 0) {
            model.setFiles(new Files());
            for (Map.Entry<String, String> entry : entity.getFiles().entrySet()) {
                File file = new File();
                file.setName(entry.getKey());
                file.setContent(entry.getValue());
                model.getFiles().getFiles().add(file);
            }
        }
        return model;
    }
    return null;
}
Also used : VmPayload(org.ovirt.engine.core.common.businessentities.VmPayload) Payload(org.ovirt.engine.api.model.Payload) Files(org.ovirt.engine.api.model.Files) Map(java.util.Map) File(org.ovirt.engine.api.model.File)

Example 3 with VmPayload

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

the class BackendVmResourceTest method getPayloadModel.

private VmPayload getPayloadModel() {
    VmPayload payload = new VmPayload();
    payload.setDeviceType(VmDeviceType.CDROM);
    payload.getFiles().put("payloadFile", new String(Base64.decodeBase64(PAYLOAD_COMTENT)));
    return payload;
}
Also used : VmPayload(org.ovirt.engine.core.common.businessentities.VmPayload)

Example 4 with VmPayload

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

the class GetVmPayloadQuery method executeQueryCommand.

@Override
protected void executeQueryCommand() {
    if (multiLevelAdministrationHandler.isAdminUser(getUser())) {
        List<VmDevice> disks = dao.getVmDeviceByVmIdAndType(getParameters().getId(), VmDeviceGeneralType.DISK);
        for (VmDevice disk : disks) {
            if (disk.isManaged() && VmPayload.isPayload(disk.getSpecParams())) {
                VmPayload payload = new VmPayload(disk);
                for (Map.Entry<String, String> entry : payload.getFiles().entrySet()) {
                    entry.setValue(new String(Base64.decodeBase64(entry.getValue())));
                }
                getQueryReturnValue().setReturnValue(payload);
            }
        }
    }
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VmPayload(org.ovirt.engine.core.common.businessentities.VmPayload) Map(java.util.Map)

Example 5 with VmPayload

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

the class VmInfoBuildUtils method createSysprepPayloadDevice.

public VmDevice createSysprepPayloadDevice(String sysPrepContent, VM vm) {
    // We do not validate the size of the content being passed to the VM payload by VmPayload.isPayloadSizeLegal().
    // The sysprep file size isn't being verified for 3.0 clusters and below, so we maintain the same behavior here.
    VmPayload vmPayload = new VmPayload();
    vmPayload.setDeviceType(VmDeviceType.FLOPPY);
    vmPayload.getFiles().put(osRepository.getSysprepFileName(vm.getOs(), vm.getCompatibilityVersion()), new String(BASE_64.encode(sysPrepContent.getBytes()), StandardCharsets.UTF_8));
    return new VmDevice(new VmDeviceId(Guid.newGuid(), vm.getId()), VmDeviceGeneralType.DISK, VmDeviceType.FLOPPY.getName(), "", vmPayload.getSpecParams(), true, true, true, "", null, null, null);
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VmPayload(org.ovirt.engine.core.common.businessentities.VmPayload) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Aggregations

VmPayload (org.ovirt.engine.core.common.businessentities.VmPayload)12 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)6 Payload (org.ovirt.engine.api.model.Payload)4 VmDeviceId (org.ovirt.engine.core.common.businessentities.VmDeviceId)4 Map (java.util.Map)3 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 GraphicsType (org.ovirt.engine.core.common.businessentities.GraphicsType)2 Guid (org.ovirt.engine.core.compat.Guid)2 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Set (java.util.Set)1