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;
}
}
}
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();
}
}
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);
}
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<>());
}
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);
}
}
}
Aggregations