Search in sources :

Example 6 with VmPayload

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

the class BackendVmDeviceHelper method setPayload.

public static void setPayload(BackendResource resouce, Vm vm) {
    try {
        VmPayload payload = resouce.getEntity(VmPayload.class, QueryType.GetVmPayload, new IdQueryParameters(new Guid(vm.getId())), null, true);
        if (payload != null) {
            Payload p = resouce.getMappingLocator().getMapper(VmPayload.class, Payload.class).map(payload, null);
            Payloads payloads = new Payloads();
            payloads.getPayloads().add(p);
            vm.setPayloads(payloads);
        }
    } catch (WebApplicationException ex) {
        if (ex.getResponse().getStatus() == Response.Status.NOT_FOUND.getStatusCode()) {
        // It's legal to not receive a payload for this VM, so the exception is caught and ignored.
        // (TODO: 'getEntity()' should be refactored to make it the programmer's decision,
        // whether to throw an exception or not in case the entity is not found.) Then
        // this try-catch won't be necessary.
        } else {
            throw ex;
        }
    }
}
Also used : IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) WebApplicationException(javax.ws.rs.WebApplicationException) VmPayload(org.ovirt.engine.core.common.businessentities.VmPayload) VmPayload(org.ovirt.engine.core.common.businessentities.VmPayload) Payload(org.ovirt.engine.api.model.Payload) Guid(org.ovirt.engine.core.compat.Guid) Payloads(org.ovirt.engine.api.model.Payloads)

Example 7 with VmPayload

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

the class LibvirtVmXmlBuilder method writeCdRom.

private void writeCdRom(List<VmDevice> devices) {
    // <disk type='file' device='cdrom' snapshot='no'>
    // <driver name='qemu' type='raw' error_policy='report' />
    // <source file='<path>' startupPolicy='optional'/>
    // <target dev='hdc' bus='ide'/>
    // <readonly/>
    // <address type='drive' controller='0' bus='1' target='0' unit='0'/>
    // </disk>
    devices.stream().filter(d -> VmPayload.isPayload(d.getSpecParams())).forEach(device -> {
        writer.writeStartElement("disk");
        writer.writeAttributeString("type", "file");
        writer.writeAttributeString("device", "cdrom");
        writer.writeAttributeString("snapshot", "no");
        writer.writeStartElement("driver");
        writer.writeAttributeString("name", "qemu");
        writer.writeAttributeString("type", "raw");
        writer.writeAttributeString("error_policy", "report");
        writer.writeEndElement();
        writer.writeStartElement("source");
        writer.writeAttributeString("file", "PAYLOAD:");
        writer.writeAttributeString("startupPolicy", "optional");
        writer.writeEndElement();
        payloadIndex = VmDeviceCommonUtils.getCdPayloadDeviceIndex(cdInterface);
        writer.writeStartElement("target");
        String name = vmInfoBuildUtils.makeDiskName(cdInterface, payloadIndex);
        writer.writeAttributeString("dev", name);
        writer.writeAttributeString("bus", cdInterface);
        writer.writeEndElement();
        writer.writeElement("readonly");
        writeAlias(device);
        if ("scsi".equals(cdInterface)) {
            int index = VmDeviceCommonUtils.getCdPayloadDeviceIndex(cdInterface);
            writeAddress(vmInfoBuildUtils.createAddressForScsiDisk(0, index));
        }
        payloadMetadata = new Pair<>(name, new VmPayload(device));
        writer.writeEndElement();
    });
    // add a device that points to vm.getCdPath()
    String cdPath = vm.getCdPath();
    VmDevice nonPayload = devices.stream().filter(d -> !VmPayload.isPayload(d.getSpecParams())).findAny().orElse(null);
    if (nonPayload != null || (vm.isRunOnce() && !StringUtils.isEmpty(cdPath))) {
        cdRomIndex = VmDeviceCommonUtils.getCdDeviceIndex(cdInterface);
        String dev = vmInfoBuildUtils.makeDiskName(cdInterface, cdRomIndex);
        boolean isoOnBlockDomain = vmInfoBuildUtils.isBlockDomainPath(cdPath);
        if (isoOnBlockDomain) {
            diskMetadata.put(dev, vmInfoBuildUtils.createDiskUuidsMap(vm, cdPath));
        }
        writer.writeStartElement("disk");
        writer.writeAttributeString("type", isoOnBlockDomain ? "block" : "file");
        writer.writeAttributeString("device", "cdrom");
        writer.writeAttributeString("snapshot", "no");
        writer.writeStartElement("driver");
        writer.writeAttributeString("name", "qemu");
        writer.writeAttributeString("type", "raw");
        writer.writeAttributeString("error_policy", "report");
        writer.writeEndElement();
        writer.writeStartElement("source");
        writer.writeAttributeString(isoOnBlockDomain ? "dev" : "file", cdPath);
        writer.writeAttributeString("startupPolicy", "optional");
        writer.writeEndElement();
        writer.writeStartElement("target");
        writer.writeAttributeString("dev", dev);
        writer.writeAttributeString("bus", cdInterface);
        writer.writeEndElement();
        writer.writeElement("readonly");
        if (nonPayload != null) {
            writeAlias(nonPayload);
            if ("scsi".equals(cdInterface)) {
                writeAddress(vmInfoBuildUtils.createAddressForScsiDisk(0, cdRomIndex));
            } else {
                writeAddress(nonPayload);
            }
            writeBootOrder(nonPayload.getBootOrder());
        }
        writer.writeEndElement();
    }
}
Also used : Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) VmType(org.ovirt.engine.core.common.businessentities.VmType) PropagateErrors(org.ovirt.engine.core.common.businessentities.storage.PropagateErrors) VmInterfaceType(org.ovirt.engine.core.common.businessentities.network.VmInterfaceType) LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk) LoggerFactory(org.slf4j.LoggerFactory) GraphicsInfo(org.ovirt.engine.core.common.businessentities.GraphicsInfo) VmCpuCountHelper(org.ovirt.engine.core.common.utils.VmCpuCountHelper) XmlTextWriter(org.ovirt.engine.core.utils.ovf.xml.XmlTextWriter) HugePageUtils(org.ovirt.engine.core.common.utils.HugePageUtils) ChipsetType(org.ovirt.engine.core.common.businessentities.ChipsetType) VmDeviceCommonUtils(org.ovirt.engine.core.common.utils.VmDeviceCommonUtils) Map(java.util.Map) VdsNumaNode(org.ovirt.engine.core.common.businessentities.VdsNumaNode) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) StringMapUtils(org.ovirt.engine.core.utils.StringMapUtils) VmDeviceCommonUtils.updateVmDevicesBootOrder(org.ovirt.engine.core.common.utils.VmDeviceCommonUtils.updateVmDevicesBootOrder) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic) VdsStatistics(org.ovirt.engine.core.common.businessentities.VdsStatistics) Version(org.ovirt.engine.core.compat.Version) MemoizingSupplier(org.ovirt.engine.core.utils.MemoizingSupplier) DisplayType(org.ovirt.engine.core.common.businessentities.DisplayType) NetworkFilter(org.ovirt.engine.core.common.businessentities.network.NetworkFilter) DiskStorageType(org.ovirt.engine.core.common.businessentities.storage.DiskStorageType) VmNumaNode(org.ovirt.engine.core.common.businessentities.VmNumaNode) Collection(java.util.Collection) VmPayload(org.ovirt.engine.core.common.businessentities.VmPayload) Set(java.util.Set) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice) List(java.util.List) Stream(java.util.stream.Stream) DiskInterface(org.ovirt.engine.core.common.businessentities.storage.DiskInterface) Entry(java.util.Map.Entry) Optional(java.util.Optional) GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) NumaSettingFactory(org.ovirt.engine.core.vdsbroker.vdsbroker.NumaSettingFactory) FeatureSupported(org.ovirt.engine.core.common.FeatureSupported) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId) VmDeviceType(org.ovirt.engine.core.common.utils.VmDeviceType) ArchitectureType(org.ovirt.engine.core.common.businessentities.ArchitectureType) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) Guid(org.ovirt.engine.core.compat.Guid) HashMap(java.util.HashMap) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) NetworkUtils(org.ovirt.engine.core.utils.NetworkUtils) ArrayList(java.util.ArrayList) VmDeviceGeneralType(org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType) VmPropertiesUtils(org.ovirt.engine.core.common.utils.customprop.VmPropertiesUtils) HashSet(java.util.HashSet) ArchStrategyFactory(org.ovirt.engine.core.utils.archstrategy.ArchStrategyFactory) VdsProperties(org.ovirt.engine.core.vdsbroker.vdsbroker.VdsProperties) HugePage(org.ovirt.engine.core.common.businessentities.HugePage) Network(org.ovirt.engine.core.common.businessentities.network.Network) VolumeFormat(org.ovirt.engine.core.common.businessentities.storage.VolumeFormat) Pair(org.ovirt.engine.core.common.utils.Pair) Config(org.ovirt.engine.core.common.config.Config) Logger(org.slf4j.Logger) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) VmHostDevice(org.ovirt.engine.core.common.businessentities.VmHostDevice) VnicProfile(org.ovirt.engine.core.common.businessentities.network.VnicProfile) ConfigValues(org.ovirt.engine.core.common.config.ConfigValues) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) VM(org.ovirt.engine.core.common.businessentities.VM) NumaTuneMode(org.ovirt.engine.core.common.businessentities.NumaTuneMode) GetControllerIndices(org.ovirt.engine.core.vdsbroker.architecture.GetControllerIndices) IoTuneUtils.ioTuneListFrom(org.ovirt.engine.core.vdsbroker.vdsbroker.IoTuneUtils.ioTuneListFrom) Comparator(java.util.Comparator) Collections(java.util.Collections) StorageQos(org.ovirt.engine.core.common.businessentities.qos.StorageQos) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VmPayload(org.ovirt.engine.core.common.businessentities.VmPayload)

Example 8 with VmPayload

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

the class VmInfoBuildUtils method createCloudInitPayloadDevice.

public VmDevice createCloudInitPayloadDevice(Map<String, byte[]> cloudInitContent, VM vm) {
    VmPayload vmPayload = new VmPayload();
    vmPayload.setDeviceType(VmDeviceType.CDROM);
    vmPayload.setVolumeId(CLOUD_INIT_VOL_ID);
    for (Entry<String, byte[]> entry : cloudInitContent.entrySet()) {
        vmPayload.getFiles().put(entry.getKey(), new String(BASE_64.encode(entry.getValue()), StandardCharsets.UTF_8));
    }
    return new VmDevice(new VmDeviceId(Guid.newGuid(), vm.getId()), VmDeviceGeneralType.DISK, VmDeviceType.CDROM.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)

Example 9 with VmPayload

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

the class BackendVmPoolsResourceTest method addCommonAddExpectations.

private void addCommonAddExpectations() throws Exception {
    setUpGetEntityExpectations(QueryType.GetVmDataByPoolName, NameQueryParameters.class, new String[] { "Name" }, new Object[] { NAMES[0] }, getVmEntity());
    setUpGetEntityExpectations(QueryType.GetVmPayload, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[0] }, new VmPayload());
    setUpGetEntityExpectations(QueryType.IsBalloonEnabled, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[0] }, Boolean.FALSE);
    setUpGetEntityExpectations(QueryType.GetConsoleDevices, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[0] }, new ArrayList<>());
    setUpGetEntityExpectations(QueryType.GetVirtioScsiControllers, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[0] }, new ArrayList<>());
    setUpGetEntityExpectations(QueryType.GetSoundDevices, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[0] }, new ArrayList<>());
    setUpGetEntityExpectations(QueryType.GetRngDevice, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[0] }, new ArrayList<>());
}
Also used : VmPayload(org.ovirt.engine.core.common.businessentities.VmPayload)

Example 10 with VmPayload

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

the class UpdateVmCommand method updateVmPayload.

protected void updateVmPayload() {
    VmPayload payload = getParameters().getVmPayload();
    if (payload != null || getParameters().isClearPayload()) {
        List<VmDevice> disks = vmDeviceDao.getVmDeviceByVmIdAndType(getVmId(), VmDeviceGeneralType.DISK);
        VmDevice oldPayload = null;
        for (VmDevice disk : disks) {
            if (VmPayload.isPayload(disk.getSpecParams())) {
                oldPayload = disk;
                break;
            }
        }
        if (oldPayload != null) {
            List<VmDeviceId> devs = new ArrayList<>();
            devs.add(oldPayload.getId());
            vmDeviceDao.removeAll(devs);
        }
        if (!getParameters().isClearPayload()) {
            getVmDeviceUtils().addManagedDevice(new VmDeviceId(Guid.newGuid(), getVmId()), VmDeviceGeneralType.DISK, payload.getDeviceType(), payload.getSpecParams(), true, true);
        }
    }
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VmPayload(org.ovirt.engine.core.common.businessentities.VmPayload) ArrayList(java.util.ArrayList) 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