Search in sources :

Example 6 with Disk

use of org.ovirt.engine.api.model.Disk 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);
                }
            }
        }
    }
}
Also used : VolumeFormat(org.ovirt.engine.core.common.businessentities.storage.VolumeFormat) DiskAttachment(org.ovirt.engine.api.model.DiskAttachment) Vm(org.ovirt.engine.api.model.Vm) Guid(org.ovirt.engine.core.compat.Guid) Disk(org.ovirt.engine.api.model.Disk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 7 with Disk

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

the class BackendStorageDomainDiskResource method get.

@Override
public Disk get() {
    Disk disk;
    boolean unregistered = ParametersHelper.getBooleanParameter(httpHeaders, uriInfo, UNREGISTERED_CONSTRAINT_PARAMETER, true, false);
    if (unregistered) {
        QueryReturnValue result = runQuery(QueryType.GetDiskByDiskId, new IdQueryParameters(guid));
        if (!result.getSucceeded() || result.getReturnValue() == null) {
            Guid dataCenterId = BackendDataCenterHelper.lookupByStorageDomainId(this, storageDomainId);
            disk = performGet(QueryType.GetUnregisteredDisk, new GetUnregisteredDiskQueryParameters(guid, storageDomainId, dataCenterId));
        } else {
            // parameter was passed.
            return notFound();
        }
    } else {
        disk = getDelegate().get();
    }
    if (disk.isSetStorageDomains() && !disk.getStorageDomains().getStorageDomains().isEmpty()) {
        for (StorageDomain sd : disk.getStorageDomains().getStorageDomains()) {
            if (sd.isSetId() && sd.getId().equals(storageDomainId.toString())) {
                return disk;
            }
        }
    }
    return notFound();
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) StorageDomain(org.ovirt.engine.api.model.StorageDomain) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) Guid(org.ovirt.engine.core.compat.Guid) GetUnregisteredDiskQueryParameters(org.ovirt.engine.core.common.queries.GetUnregisteredDiskQueryParameters) Disk(org.ovirt.engine.api.model.Disk)

Example 8 with Disk

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

the class BackendSnapshotDisksResource method list.

@Override
public Disks list() {
    Disks disks = new Disks();
    if (parent.getSnapshot().isVmConfigurationAvailable()) {
        VM vm = parent.collection.getVmPreview(parent.get());
        for (DiskImage disk : vm.getDiskList()) {
            Disk d = DiskMapper.map(disk, null);
            map(d, parent.id);
            disks.getDisks().add(d);
        }
    }
    return disks;
}
Also used : VM(org.ovirt.engine.core.common.businessentities.VM) Disks(org.ovirt.engine.api.model.Disks) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Disk(org.ovirt.engine.api.model.Disk)

Example 9 with Disk

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

the class BackendVmDiskResourceTest method testUpdate.

@Test
public void testUpdate() throws Exception {
    setUpGetEntityExpectations(2);
    setUpDiskVmElementExpectations();
    setUriInfo(setUpActionExpectations(ActionType.UpdateVmDisk, VmDiskOperationParameterBase.class, new String[] { "VmId", "DiskInfo.WipeAfterDelete" }, new Object[] { VM_ID, Boolean.FALSE }, true, true));
    Disk disk = resource.update(getUpdate());
    assertNotNull(disk);
}
Also used : Disk(org.ovirt.engine.api.model.Disk) VmDiskOperationParameterBase(org.ovirt.engine.core.common.action.VmDiskOperationParameterBase) Test(org.junit.Test)

Example 10 with Disk

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

the class BackendVmDiskResourceTest method testGetIncludeStatistics.

@Test
public void testGetIncludeStatistics() throws Exception {
    try {
        accepts.add("application/xml; detail=statistics");
        setUriInfo(setUpBasicUriExpectations());
        setUpEntityQueryExpectations(1);
        Disk disk = resource.get();
        assertTrue(disk.isSetStatistics());
        verifyModelSpecific(disk, 1);
        verifyLinks(disk);
    } finally {
        accepts.clear();
    }
}
Also used : Disk(org.ovirt.engine.api.model.Disk) Test(org.junit.Test)

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