Search in sources :

Example 1 with DiskAttachmentsResource

use of org.ovirt.engine.api.resource.DiskAttachmentsResource 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;
}
Also used : VmResource(org.ovirt.engine.api.resource.VmResource) DiskResource(org.ovirt.engine.api.resource.DiskResource) DiskAttachmentsResource(org.ovirt.engine.api.resource.DiskAttachmentsResource) DiskAttachment(org.ovirt.engine.api.model.DiskAttachment) V3Disk(org.ovirt.engine.api.v3.types.V3Disk) VmsResource(org.ovirt.engine.api.resource.VmsResource) V3Disks(org.ovirt.engine.api.v3.types.V3Disks) VmDisksResource(org.ovirt.engine.api.resource.VmDisksResource) DisksResource(org.ovirt.engine.api.resource.DisksResource) SystemResource(org.ovirt.engine.api.resource.SystemResource) DiskAttachments(org.ovirt.engine.api.model.DiskAttachments) Disk(org.ovirt.engine.api.model.Disk) V3Disk(org.ovirt.engine.api.v3.types.V3Disk) GET(javax.ws.rs.GET)

Example 2 with DiskAttachmentsResource

use of org.ovirt.engine.api.resource.DiskAttachmentsResource 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.
            }
        }
    }
}
Also used : VmResource(org.ovirt.engine.api.resource.VmResource) DiskAttachmentsResource(org.ovirt.engine.api.resource.DiskAttachmentsResource) DiskAttachmentResource(org.ovirt.engine.api.resource.DiskAttachmentResource) DiskAttachment(org.ovirt.engine.api.model.DiskAttachment) WebApplicationException(javax.ws.rs.WebApplicationException) VmsResource(org.ovirt.engine.api.resource.VmsResource) SystemResource(org.ovirt.engine.api.resource.SystemResource)

Example 3 with DiskAttachmentsResource

use of org.ovirt.engine.api.resource.DiskAttachmentsResource in project ovirt-engine by oVirt.

the class V3DiskSnapshotOutAdapter method adapt.

@Override
public V3DiskSnapshot adapt(DiskSnapshot from) {
    V3DiskSnapshot to = new V3DiskSnapshot();
    if (from.isSetLinks()) {
        to.getLinks().addAll(adaptOut(from.getLinks()));
    }
    if (from.isSetActions()) {
        to.setActions(adaptOut(from.getActions()));
    }
    if (from.isSetActualSize()) {
        to.setActualSize(from.getActualSize());
    }
    if (from.isSetAlias()) {
        to.setAlias(from.getAlias());
    }
    if (from.isSetComment()) {
        to.setComment(from.getComment());
    }
    if (from.isSetDescription()) {
        to.setDescription(from.getDescription());
    }
    if (from.isSetDisk()) {
        to.setDisk(adaptOut(from.getDisk()));
    }
    if (from.isSetDiskProfile()) {
        to.setDiskProfile(adaptOut(from.getDiskProfile()));
    }
    if (from.isSetFormat()) {
        to.setFormat(from.getFormat().value());
    }
    if (from.isSetId()) {
        to.setId(from.getId());
    }
    if (from.isSetHref()) {
        to.setHref(from.getHref());
    }
    if (from.isSetImageId()) {
        to.setImageId(from.getImageId());
    }
    if (from.isSetInstanceType()) {
        to.setInstanceType(adaptOut(from.getInstanceType()));
    }
    if (from.isSetLogicalName()) {
        to.setLogicalName(from.getLogicalName());
    }
    if (from.isSetLunStorage()) {
        to.setLunStorage(adaptOut(from.getLunStorage()));
    }
    if (from.isSetName()) {
        to.setName(from.getName());
    }
    if (from.isSetOpenstackVolumeType()) {
        to.setOpenstackVolumeType(adaptOut(from.getOpenstackVolumeType()));
    }
    if (from.isSetPropagateErrors()) {
        to.setPropagateErrors(from.isPropagateErrors());
    }
    if (from.isSetProvisionedSize()) {
        to.setProvisionedSize(from.getProvisionedSize());
    }
    if (from.isSetQuota()) {
        to.setQuota(adaptOut(from.getQuota()));
    }
    if (from.isSetReadOnly()) {
        to.setReadOnly(from.isReadOnly());
    }
    if (from.isSetSgio()) {
        to.setSgio(from.getSgio().value());
    }
    if (from.isSetShareable()) {
        to.setShareable(from.isShareable());
    }
    if (from.isSetSnapshot()) {
        to.setSnapshot(adaptOut(from.getSnapshot()));
    }
    if (from.isSetSparse()) {
        to.setSparse(from.isSparse());
    }
    if (from.isSetStatistics()) {
        to.setStatistics(new V3Statistics());
        to.getStatistics().getStatistics().addAll(adaptOut(from.getStatistics().getStatistics()));
    }
    if (from.isSetStatus()) {
        V3Status status = new V3Status();
        status.setState(from.getStatus().value());
        to.setStatus(status);
    }
    if (from.isSetStorageDomain()) {
        to.setStorageDomain(adaptOut(from.getStorageDomain()));
    }
    if (from.isSetStorageDomains()) {
        to.setStorageDomains(new V3StorageDomains());
        to.getStorageDomains().getStorageDomains().addAll(adaptOut(from.getStorageDomains().getStorageDomains()));
    }
    if (from.isSetStorageType()) {
        to.setStorageType(from.getStorageType().value());
    }
    if (from.isSetTemplate()) {
        to.setTemplate(adaptOut(from.getTemplate()));
    }
    if (from.isSetUsesScsiReservation()) {
        to.setUsesScsiReservation(from.isUsesScsiReservation());
    }
    if (from.isSetVm()) {
        to.setVm(adaptOut(from.getVm()));
    }
    if (from.isSetVms()) {
        to.setVms(new V3VMs());
        to.getVms().getVMs().addAll(adaptOut(from.getVms().getVms()));
    }
    if (from.isSetWipeAfterDelete()) {
        to.setWipeAfterDelete(from.isWipeAfterDelete());
    }
    // continue supporting it. To do so we need to find the disk attachment and copy this attribute to the disk.
    if (to.isSetId() && to.isSetVm() && to.getVm().isSetId()) {
        String diskId = to.getId();
        String vmId = to.getVm().getId();
        VmsResource vmsResource = BackendApiResource.getInstance().getVmsResource();
        VmResource vmResource = vmsResource.getVmResource(vmId);
        DiskAttachmentsResource attachmentsResource = vmResource.getDiskAttachmentsResource();
        DiskAttachmentResource attachmentResource = attachmentsResource.getAttachmentResource(diskId);
        DiskAttachment attachment = attachmentResource.get();
        if (attachment.isSetActive()) {
            to.setActive(attachment.isActive());
        }
    }
    return to;
}
Also used : VmResource(org.ovirt.engine.api.resource.VmResource) DiskAttachmentsResource(org.ovirt.engine.api.resource.DiskAttachmentsResource) DiskAttachmentResource(org.ovirt.engine.api.resource.DiskAttachmentResource) DiskAttachment(org.ovirt.engine.api.model.DiskAttachment) VmsResource(org.ovirt.engine.api.resource.VmsResource) V3DiskSnapshot(org.ovirt.engine.api.v3.types.V3DiskSnapshot) V3Status(org.ovirt.engine.api.v3.types.V3Status) V3Statistics(org.ovirt.engine.api.v3.types.V3Statistics) V3VMs(org.ovirt.engine.api.v3.types.V3VMs) V3StorageDomains(org.ovirt.engine.api.v3.types.V3StorageDomains)

Aggregations

DiskAttachment (org.ovirt.engine.api.model.DiskAttachment)3 DiskAttachmentsResource (org.ovirt.engine.api.resource.DiskAttachmentsResource)3 VmResource (org.ovirt.engine.api.resource.VmResource)3 VmsResource (org.ovirt.engine.api.resource.VmsResource)3 DiskAttachmentResource (org.ovirt.engine.api.resource.DiskAttachmentResource)2 SystemResource (org.ovirt.engine.api.resource.SystemResource)2 GET (javax.ws.rs.GET)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Disk (org.ovirt.engine.api.model.Disk)1 DiskAttachments (org.ovirt.engine.api.model.DiskAttachments)1 DiskResource (org.ovirt.engine.api.resource.DiskResource)1 DisksResource (org.ovirt.engine.api.resource.DisksResource)1 VmDisksResource (org.ovirt.engine.api.resource.VmDisksResource)1 V3Disk (org.ovirt.engine.api.v3.types.V3Disk)1 V3DiskSnapshot (org.ovirt.engine.api.v3.types.V3DiskSnapshot)1 V3Disks (org.ovirt.engine.api.v3.types.V3Disks)1 V3Statistics (org.ovirt.engine.api.v3.types.V3Statistics)1 V3Status (org.ovirt.engine.api.v3.types.V3Status)1 V3StorageDomains (org.ovirt.engine.api.v3.types.V3StorageDomains)1 V3VMs (org.ovirt.engine.api.v3.types.V3VMs)1