Search in sources :

Example 1 with Disk

use of org.ovirt.engine.api.model.Disk 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 Disk

use of org.ovirt.engine.api.model.Disk in project ovirt-engine by oVirt.

the class BackendStorageDomainDisksResourceTest method testAddIdentifyStorageDomainByName.

@Test
public void testAddIdentifyStorageDomainByName() throws Exception {
    setUriInfo(setUpBasicUriExpectations());
    setUpHttpHeaderExpectations("Expect", "201-created");
    setUpEntityQueryExpectations(QueryType.GetDiskByDiskId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[0] }, getEntity(0));
    Disk model = getModel();
    model.getStorageDomains().getStorageDomains().get(0).setId(null);
    model.getStorageDomains().getStorageDomains().get(0).setName("Storage_Domain_1");
    setUpCreationExpectations(ActionType.AddDisk, AddDiskParameters.class, new String[] {}, new Object[] {}, true, true, GUIDS[0], asList(storagePoolId), asList(new AsyncTaskStatus(AsyncTaskStatusEnum.finished)), QueryType.GetDiskByDiskId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[0] }, getEntity(0));
    Response response = collection.add(model);
    assertEquals(201, response.getStatus());
    assertTrue(response.getEntity() instanceof Disk);
    verifyModel((Disk) response.getEntity(), 0);
    assertNull(((Disk) response.getEntity()).getCreationStatus());
}
Also used : Response(javax.ws.rs.core.Response) AsyncTaskStatus(org.ovirt.engine.core.common.businessentities.AsyncTaskStatus) Disk(org.ovirt.engine.api.model.Disk) Test(org.junit.Test)

Example 3 with Disk

use of org.ovirt.engine.api.model.Disk in project ovirt-engine by oVirt.

the class BackendDiskAttachmentsResource method attachDiskToVm.

protected Response attachDiskToVm(AbstractBackendCollectionResource resource, DiskAttachment attachment, IResolver entityResolver) {
    Guid diskId = Guid.createGuidFromStringDefaultEmpty(attachment.getDisk().getId());
    DiskVmElement dve = map(attachment);
    dve.getId().setVmId(vmId);
    dve.getId().setDeviceId(diskId);
    AttachDetachVmDiskParameters params = new AttachDetachVmDiskParameters(dve);
    Disk disk = attachment.getDisk();
    boolean isDiskActive = false;
    if (attachment.isSetActive()) {
        isDiskActive = BooleanUtils.toBoolean(attachment.isActive());
    }
    params.setPlugUnPlug(isDiskActive);
    if (disk.isSetReadOnly()) {
        dve.setReadOnly(BooleanUtils.toBoolean(disk.isReadOnly()));
    }
    if (disk.isSetSnapshot()) {
        validateParameters(disk, "snapshot.id");
        params.setSnapshotId(asGuid(disk.getSnapshot().getId()));
    }
    return resource.performCreate(ActionType.AttachDiskToVm, params, entityResolver);
}
Also used : AttachDetachVmDiskParameters(org.ovirt.engine.core.common.action.AttachDetachVmDiskParameters) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) Guid(org.ovirt.engine.core.compat.Guid) Disk(org.ovirt.engine.api.model.Disk)

Example 4 with Disk

use of org.ovirt.engine.api.model.Disk in project ovirt-engine by oVirt.

the class BackendDiskAttachmentsResource method createDisk.

protected Response createDisk(AbstractBackendCollectionResource resource, DiskAttachment attachment, IResolver entityResolver) {
    Disk disk = attachment.getDisk();
    validateDiskForCreation(disk);
    updateStorageTypeForDisk(disk);
    return resource.performCreate(ActionType.AddDisk, getAddParameters(attachment, DiskMapper.map(disk, null), disk), entityResolver);
}
Also used : Disk(org.ovirt.engine.api.model.Disk)

Example 5 with Disk

use of org.ovirt.engine.api.model.Disk in project ovirt-engine by oVirt.

the class BackendDiskResource method sparsify.

@Override
public Response sparsify(Action action) {
    Disk disk = get();
    if (disk == null) {
        throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).build());
    }
    Guid imageId = getDiskImageId(disk.getImageId());
    StorageJobCommandParameters params = new StorageJobCommandParameters(imageId);
    return doAction(ActionType.SparsifyImage, params, action);
}
Also used : StorageJobCommandParameters(org.ovirt.engine.core.common.action.StorageJobCommandParameters) WebApplicationException(javax.ws.rs.WebApplicationException) Guid(org.ovirt.engine.core.compat.Guid) Disk(org.ovirt.engine.api.model.Disk)

Aggregations

Disk (org.ovirt.engine.api.model.Disk)68 Test (org.junit.Test)33 Response (javax.ws.rs.core.Response)13 Guid (org.ovirt.engine.core.compat.Guid)13 WebApplicationException (javax.ws.rs.WebApplicationException)10 DiskAttachment (org.ovirt.engine.api.model.DiskAttachment)10 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)10 StorageDomain (org.ovirt.engine.api.model.StorageDomain)9 AsyncTaskStatus (org.ovirt.engine.core.common.businessentities.AsyncTaskStatus)7 Vm (org.ovirt.engine.api.model.Vm)6 StorageDomains (org.ovirt.engine.api.model.StorageDomains)4 V3Disk (org.ovirt.engine.api.v3.types.V3Disk)4 DiskAttachments (org.ovirt.engine.api.model.DiskAttachments)3 V3Disks (org.ovirt.engine.api.v3.types.V3Disks)3 UriInfo (javax.ws.rs.core.UriInfo)2 HostStorage (org.ovirt.engine.api.model.HostStorage)2 V3CdRoms (org.ovirt.engine.api.v3.types.V3CdRoms)2 V3CustomProperties (org.ovirt.engine.api.v3.types.V3CustomProperties)2 V3Floppies (org.ovirt.engine.api.v3.types.V3Floppies)2 V3KatelloErrata (org.ovirt.engine.api.v3.types.V3KatelloErrata)2