Search in sources :

Example 1 with DiskResource

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

the class V3VmDiskServer method remove.

@DELETE
@Consumes({ "application/xml", "application/json" })
public Response remove(V3Action action) {
    // Detach the disk from the VM:
    Response response = adaptRemove(getDelegate()::remove);
    // need to delete the disk using the top level disks collection.
    if (!action.isSetDetach() || !action.isDetach()) {
        DisksResource disksResource = BackendApiResource.getInstance().getDisksResource();
        DiskResource diskResource = disksResource.getDiskResource(diskId);
        response = adaptRemove(diskResource::remove);
    }
    // Return the response:
    return response;
}
Also used : Response(javax.ws.rs.core.Response) VmDiskResource(org.ovirt.engine.api.resource.VmDiskResource) DiskResource(org.ovirt.engine.api.resource.DiskResource) DisksResource(org.ovirt.engine.api.resource.DisksResource) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes)

Example 2 with DiskResource

use of org.ovirt.engine.api.resource.DiskResource 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)

Aggregations

DiskResource (org.ovirt.engine.api.resource.DiskResource)2 DisksResource (org.ovirt.engine.api.resource.DisksResource)2 Consumes (javax.ws.rs.Consumes)1 DELETE (javax.ws.rs.DELETE)1 GET (javax.ws.rs.GET)1 Response (javax.ws.rs.core.Response)1 Disk (org.ovirt.engine.api.model.Disk)1 DiskAttachment (org.ovirt.engine.api.model.DiskAttachment)1 DiskAttachments (org.ovirt.engine.api.model.DiskAttachments)1 DiskAttachmentsResource (org.ovirt.engine.api.resource.DiskAttachmentsResource)1 SystemResource (org.ovirt.engine.api.resource.SystemResource)1 VmDiskResource (org.ovirt.engine.api.resource.VmDiskResource)1 VmDisksResource (org.ovirt.engine.api.resource.VmDisksResource)1 VmResource (org.ovirt.engine.api.resource.VmResource)1 VmsResource (org.ovirt.engine.api.resource.VmsResource)1 V3Disk (org.ovirt.engine.api.v3.types.V3Disk)1 V3Disks (org.ovirt.engine.api.v3.types.V3Disks)1