use of org.ovirt.engine.api.model.DiskAttachment in project ovirt-engine by oVirt.
the class V3VmDisksServer method list.
@GET
public V3Disks list() {
SystemResource systemResource = BackendApiResource.getInstance();
// In version 4 of the API the collection of disks of a virtual machine has been replaced by the collection of
// disk attachments, so we need to fetch the disk attachments:
VmsResource vmsResource = systemResource.getVmsResource();
VmResource vmResource = vmsResource.getVmResource(vmId);
DiskAttachmentsResource attachmentsResource = vmResource.getDiskAttachmentsResource();
DiskAttachments attachments = attachmentsResource.list();
// For each disk, we need now to fetch it from the top level disks collection, and add the information from
// the corresponding attachment:
DisksResource disksResource = systemResource.getDisksResource();
V3Disks disks = new V3Disks();
for (DiskAttachment attachment : attachments.getDiskAttachments()) {
DiskResource diskResource = disksResource.getDiskResource(attachment.getDisk().getId());
Disk v4Disk = diskResource.get();
V3Disk v3Disk = adaptOut(v4Disk);
V3VmHelper.addDiskAttachmentDetails(attachment, v3Disk);
V3VmHelper.fixDiskLinks(vmId, v3Disk);
disks.getDisks().add(v3Disk);
}
return disks;
}
use of org.ovirt.engine.api.model.DiskAttachment in project ovirt-engine by oVirt.
the class BackendDiskAttachmentResource method update.
@Override
public DiskAttachment update(DiskAttachment attachment) {
if (attachment.isSetActive()) {
DiskAttachment attachmentFromDb = get();
if (!attachmentFromDb.isActive().equals(attachment.isActive())) {
ActionType actionType = attachment.isActive() ? ActionType.HotPlugDiskToVm : ActionType.HotUnPlugDiskFromVm;
VmDiskOperationParameterBase params = new VmDiskOperationParameterBase(new DiskVmElement(guid, vmId));
try {
doAction(actionType, params);
} catch (BackendFailureException e) {
return handleError(e, false);
}
}
}
return performUpdate(attachment, new AddDiskResolver(), ActionType.UpdateVmDisk, new UpdateParametersProvider());
}
use of org.ovirt.engine.api.model.DiskAttachment in project ovirt-engine by oVirt.
the class V3VMInAdapter method adapt.
@Override
public Vm adapt(V3VM from) {
Vm to = new Vm();
if (from.isSetLinks()) {
to.getLinks().addAll(adaptIn(from.getLinks()));
}
if (from.isSetActions()) {
to.setActions(adaptIn(from.getActions()));
}
if (from.isSetBios()) {
to.setBios(adaptIn(from.getBios()));
}
if (from.isSetCdroms()) {
to.setCdroms(adaptIn(from.getCdroms()));
}
if (from.isSetCluster()) {
to.setCluster(adaptIn(from.getCluster()));
}
if (from.isSetComment()) {
to.setComment(from.getComment());
}
if (from.isSetConsole()) {
to.setConsole(adaptIn(from.getConsole()));
}
if (from.isSetCpu()) {
to.setCpu(adaptIn(from.getCpu()));
}
if (from.isSetCpuProfile()) {
to.setCpuProfile(adaptIn(from.getCpuProfile()));
}
if (from.isSetCpuShares()) {
to.setCpuShares(from.getCpuShares());
}
if (from.isSetCreationTime()) {
to.setCreationTime(from.getCreationTime());
}
if (from.isSetCustomCpuModel()) {
to.setCustomCpuModel(from.getCustomCpuModel());
}
if (from.isSetCustomEmulatedMachine()) {
to.setCustomEmulatedMachine(from.getCustomEmulatedMachine());
}
if (from.isSetCustomProperties()) {
to.setCustomProperties(adaptIn(from.getCustomProperties()));
}
if (from.isSetDeleteProtected()) {
to.setDeleteProtected(from.isDeleteProtected());
}
if (from.isSetDescription()) {
to.setDescription(from.getDescription());
}
if (from.isSetDisks()) {
DiskAttachments toAttachments = new DiskAttachments();
for (V3Disk fromDisk : from.getDisks().getDisks()) {
DiskAttachment toAttachment = new DiskAttachment();
toAttachment.setDisk(adaptIn(fromDisk));
toAttachments.getDiskAttachments().add(toAttachment);
}
to.setDiskAttachments(toAttachments);
}
if (from.isSetDisplay()) {
to.setDisplay(adaptIn(from.getDisplay()));
}
if (from.isSetDomain()) {
to.setDomain(adaptIn(from.getDomain()));
}
if (from.isSetExternalHostProvider()) {
to.setExternalHostProvider(adaptIn(from.getExternalHostProvider()));
}
if (from.isSetFloppies()) {
to.setFloppies(adaptIn(from.getFloppies()));
}
if (from.isSetGuestOperatingSystem()) {
to.setGuestOperatingSystem(adaptIn(from.getGuestOperatingSystem()));
}
if (from.isSetGuestTimeZone()) {
to.setGuestTimeZone(adaptIn(from.getGuestTimeZone()));
}
if (from.isSetHighAvailability()) {
to.setHighAvailability(adaptIn(from.getHighAvailability()));
}
if (from.isSetHost()) {
to.setHost(adaptIn(from.getHost()));
}
if (from.isSetId()) {
to.setId(from.getId());
}
if (from.isSetHref()) {
to.setHref(from.getHref());
}
if (from.isSetInitialization()) {
to.setInitialization(adaptIn(from.getInitialization()));
}
if (from.isSetInstanceType()) {
to.setInstanceType(adaptIn(from.getInstanceType()));
}
if (from.isSetIo()) {
to.setIo(adaptIn(from.getIo()));
}
if (from.isSetKatelloErrata()) {
to.setKatelloErrata(adaptIn(from.getKatelloErrata()));
}
if (from.isSetLargeIcon()) {
to.setLargeIcon(adaptIn(from.getLargeIcon()));
}
if (from.isSetMemory()) {
to.setMemory(from.getMemory());
}
if (from.isSetMemoryPolicy()) {
to.setMemoryPolicy(adaptIn(from.getMemoryPolicy()));
}
if (from.isSetMigration()) {
to.setMigration(adaptIn(from.getMigration()));
}
if (from.isSetMigrationDowntime()) {
to.setMigrationDowntime(from.getMigrationDowntime());
}
if (from.isSetName()) {
to.setName(from.getName());
}
if (from.isSetNextRunConfigurationExists()) {
to.setNextRunConfigurationExists(from.isNextRunConfigurationExists());
}
if (from.isSetNics()) {
to.setNics(adaptIn(from.getNics()));
}
if (from.isSetNumaTuneMode()) {
to.setNumaTuneMode(NumaTuneMode.fromValue(from.getNumaTuneMode()));
}
if (from.isSetOrigin()) {
to.setOrigin(from.getOrigin());
}
if (from.isSetOs()) {
to.setOs(adaptIn(from.getOs()));
}
if (from.isSetPayloads()) {
to.setPayloads(adaptIn(from.getPayloads()));
}
if (from.isSetPermissions()) {
to.setPermissions(adaptIn(from.getPermissions()));
}
if (from.isSetPlacementPolicy()) {
to.setPlacementPolicy(adaptIn(from.getPlacementPolicy()));
}
if (from.isSetQuota()) {
to.setQuota(adaptIn(from.getQuota()));
}
if (from.isSetReportedDevices()) {
to.setReportedDevices(adaptIn(from.getReportedDevices()));
}
if (from.isSetRngDevice()) {
to.setRngDevice(adaptIn(from.getRngDevice()));
}
if (from.isSetRunOnce()) {
to.setRunOnce(from.isRunOnce());
}
if (from.isSetSerialNumber()) {
to.setSerialNumber(adaptIn(from.getSerialNumber()));
}
if (from.isSetSmallIcon()) {
to.setSmallIcon(adaptIn(from.getSmallIcon()));
}
if (from.isSetSnapshots()) {
to.setSnapshots(adaptIn(from.getSnapshots()));
}
if (from.isSetSoundcardEnabled()) {
to.setSoundcardEnabled(from.isSoundcardEnabled());
}
if (from.isSetSso()) {
to.setSso(adaptIn(from.getSso()));
}
if (from.isSetStartPaused()) {
to.setStartPaused(from.isStartPaused());
}
if (from.isSetStartTime()) {
to.setStartTime(from.getStartTime());
}
if (from.isSetStateless()) {
to.setStateless(from.isStateless());
}
if (from.isSetStatistics()) {
to.setStatistics(adaptIn(from.getStatistics()));
}
V3Status status = from.getStatus();
if (status != null) {
if (status.isSetState()) {
to.setStatus(VmStatus.fromValue(status.getState()));
}
if (status.isSetDetail()) {
to.setStatusDetail(status.getDetail());
}
}
if (from.isSetStopReason()) {
to.setStopReason(from.getStopReason());
}
if (from.isSetStopTime()) {
to.setStopTime(from.getStopTime());
}
if (from.isSetStorageDomain()) {
to.setStorageDomain(adaptIn(from.getStorageDomain()));
}
if (from.isSetTags()) {
to.setTags(adaptIn(from.getTags()));
}
if (from.isSetTemplate()) {
to.setTemplate(adaptIn(from.getTemplate()));
}
if (from.isSetTimeZone()) {
to.setTimeZone(adaptIn(from.getTimeZone()));
}
if (from.isSetTunnelMigration()) {
to.setTunnelMigration(from.isTunnelMigration());
}
if (from.isSetType()) {
to.setType(VmType.fromValue(from.getType()));
}
if (from.isSetUsb()) {
to.setUsb(adaptIn(from.getUsb()));
}
if (from.isSetUseLatestTemplateVersion()) {
to.setUseLatestTemplateVersion(from.isUseLatestTemplateVersion());
}
if (from.isSetVirtioScsi()) {
to.setVirtioScsi(adaptIn(from.getVirtioScsi()));
}
if (from.isSetVmPool()) {
to.setVmPool(adaptIn(from.getVmPool()));
}
if (from.isSetWatchdogs()) {
to.setWatchdogs(adaptIn(from.getWatchdogs()));
}
// new structured "time_zone" element containing the name of the time zone and the UTC offset:
if (from.isSetTimezone() && !to.isSetTimeZone()) {
TimeZone timeZone = new TimeZone();
timeZone.setName(from.getTimezone());
to.setTimeZone(timeZone);
}
return to;
}
use of org.ovirt.engine.api.model.DiskAttachment in project ovirt-engine by oVirt.
the class V3VmHelper method addDiskAttachmentDetails.
/**
* In version 4 of the API the interface, some attributes have been moved from the disk to the disk attachment, as
* they are specific of the relationship between a particular VM and the disk. But in version 3 of the API we need
* to continue supporting them. To do so we need to find the disk attachment and copy these attributes to the disk.
*/
public static void addDiskAttachmentDetails(String vmId, V3Disk disk) {
if (vmId != null) {
SystemResource systemResource = BackendApiResource.getInstance();
VmsResource vmsResource = systemResource.getVmsResource();
VmResource vmResource = vmsResource.getVmResource(vmId);
DiskAttachmentsResource attachmentsResource = vmResource.getDiskAttachmentsResource();
String diskId = disk.getId();
if (diskId != null) {
DiskAttachmentResource attachmentResource = attachmentsResource.getAttachmentResource(diskId);
try {
DiskAttachment attachment = attachmentResource.get();
addDiskAttachmentDetails(attachment, disk);
} catch (WebApplicationException exception) {
// If an application exception is generated while retrieving the details of the disk attachment
// it is safe to ignore it, as it may be that the user just doesn't have permission to see
// attachment, but she may still have permissions to see the other details of the disk.
}
}
}
}
use of org.ovirt.engine.api.model.DiskAttachment in project ovirt-engine by oVirt.
the class BackendStorageDomainVmResource method setVolumesTypeFormat.
private void setVolumesTypeFormat(Action action) {
if (action.isSetVm()) {
Vm modelVm = action.getVm();
if (!modelVm.isSetDiskAttachments()) {
return;
}
Map<Guid, org.ovirt.engine.core.common.businessentities.storage.Disk> entityDisks = getDiskMap();
for (DiskAttachment modelDiskAttachment : modelVm.getDiskAttachments().getDiskAttachments()) {
Disk modelDisk = modelDiskAttachment.getDisk();
if (modelDisk != null) {
validateParameters(modelDisk, "id");
Guid modelDiskId = Guid.createGuidFromString(modelDisk.getId());
DiskImage entityDisk = (DiskImage) entityDisks.get(modelDiskId);
if (entityDisk == null) {
continue;
}
if (modelDisk.isSetFormat()) {
VolumeFormat entityDiskFormat = DiskMapper.map(modelDisk.getFormat(), null);
entityDisk.setVolumeFormat(entityDiskFormat);
}
if (modelDisk.isSetSparse()) {
entityDisk.setVolumeType(modelDisk.isSparse() ? VolumeType.Sparse : VolumeType.Preallocated);
}
}
}
}
}
Aggregations