public void map(Disk disk, String snapshotId) { disk.setSnapshot(new Snapshot()); disk.getSnapshot().setId(snapshotId); }
@Override protected Disk addLinks(Disk model, String... subCollectionMembersToExclude) { Snapshot snapshotInfo = model.getSnapshot(); model.setSnapshot(null); super.addLinks(model, subCollectionMembersToExclude); if (snapshotInfo != null) { org.ovirt.engine.core.common.businessentities.Snapshot snapshot = getEntity(org.ovirt.engine.core.common.businessentities.Snapshot.class, QueryType.GetSnapshotBySnapshotId, new IdQueryParameters(asGuid(snapshotInfo.getId())), snapshotInfo.getId()); Vm vm = new Vm(); vm.setId(snapshot.getVmId().toString()); snapshotInfo.setVm(vm); model.setSnapshot(snapshotInfo); LinkHelper.addLinks(snapshotInfo, null, false); model.setSnapshot(snapshotInfo); } return model; }
@Override protected Disk addLinks(Disk model, String... subCollectionMembersToExclude) { Snapshot snapshotInfo = model.getSnapshot(); model.setSnapshot(null); super.addLinks(model, subCollectionMembersToExclude); if (snapshotInfo != null) { org.ovirt.engine.core.common.businessentities.Snapshot snapshot = getEntity(org.ovirt.engine.core.common.businessentities.Snapshot.class, QueryType.GetSnapshotBySnapshotId, new IdQueryParameters(asGuid(snapshotInfo.getId())), snapshotInfo.getId()); Vm vm = new Vm(); vm.setId(snapshot.getVmId().toString()); snapshotInfo.setVm(vm); model.setSnapshot(snapshotInfo); LinkHelper.addLinks(snapshotInfo, null, false); model.setSnapshot(snapshotInfo); } return model; }
@Test public void testAttachDiskSnapshot() { setUriInfo(setUpBasicUriExpectations()); Guid snapshotId = Guid.newGuid(); Disk model = getModel(); model.setSnapshot(new Snapshot()); model.getSnapshot().setId(snapshotId.toString()); model.setId(DISK_ID.toString()); //means this is an existing disk --> attach setUpCreationExpectations( ActionType.AttachDiskToVm, AttachDetachVmDiskParameters.class, new String[] { "VmId", "EntityInfo", "SnapshotId" }, new Object[] { VM_ID, new EntityInfo(VdcObjectType.Disk, DISK_ID), snapshotId }, true, true, null, null, null, QueryType.GetDiskByDiskId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { DISK_ID }, asList(getEntity(0)) ); Response response = collection.add(model); assertEquals(201, response.getStatus()); }
model.setSnapshot(new Snapshot()); model.getSnapshot().setId(entity.getSnapshotId().toString());
to.setSnapshot(adaptIn(from.getSnapshot()));