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;
}
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());
}
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);
}
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);
}
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);
}
Aggregations