Search in sources :

Example 11 with Snapshot

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

the class BackendSnapshotResource method get.

@Override
public Snapshot get() {
    org.ovirt.engine.core.common.businessentities.Snapshot entity = getSnapshot();
    Snapshot snapshot = populate(map(entity, null), entity);
    snapshot = addLinks(snapshot);
    snapshot = collection.addVmConfiguration(entity, snapshot);
    return snapshot;
}
Also used : Snapshot(org.ovirt.engine.api.model.Snapshot)

Example 12 with Snapshot

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

the class SnapshotMapper method map.

@Mapping(from = org.ovirt.engine.core.common.businessentities.Snapshot.class, to = Snapshot.class)
public static Snapshot map(org.ovirt.engine.core.common.businessentities.Snapshot entity, Snapshot template) {
    Snapshot model = template != null ? template : new Snapshot();
    model.setId(entity.getId().toString());
    if (entity.getDescription() != null) {
        model.setDescription(entity.getDescription());
    }
    if (entity.getCreationDate() != null) {
        model.setDate(DateMapper.map(entity.getCreationDate(), null));
    }
    if (entity.getStatus() != null) {
        model.setSnapshotStatus(map(entity.getStatus(), null));
    }
    if (entity.getType() != null) {
        model.setSnapshotType(map(entity.getType(), null));
    }
    model.setPersistMemorystate(entity.containsMemory());
    return model;
}
Also used : Snapshot(org.ovirt.engine.api.model.Snapshot)

Example 13 with Snapshot

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

the class BackendSnapshotsResourceTest method testGetWithPopulate.

@Test
public void testGetWithPopulate() throws Exception {
    List<String> populates = new ArrayList<>();
    populates.add("true");
    String ovfData = "data";
    org.ovirt.engine.core.common.businessentities.Snapshot resultSnapshot0 = new org.ovirt.engine.core.common.businessentities.Snapshot();
    resultSnapshot0.setVmConfiguration(ovfData);
    resultSnapshot0.setId(SNAPSHOT_IDS[0]);
    org.ovirt.engine.core.common.businessentities.Snapshot resultSnapshot1 = new org.ovirt.engine.core.common.businessentities.Snapshot();
    resultSnapshot1.setVmConfiguration(ovfData);
    resultSnapshot1.setId(SNAPSHOT_IDS[1]);
    when(httpHeaders.getRequestHeader(BackendResource.POPULATE)).thenReturn(populates);
    UriInfo uriInfo = setUpUriExpectations(null);
    setUriInfo(setUpBasicUriExpectations());
    setUpGetEntityExpectations(1);
    setUpGetSnapshotVmConfiguration(SNAPSHOT_IDS[0]);
    setUpGetSnapshotVmConfiguration(SNAPSHOT_IDS[1]);
    setUpEntityQueryExpectations(QueryType.GetSnapshotBySnapshotId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { SNAPSHOT_IDS[1] }, resultSnapshot0);
    setUpEntityQueryExpectations(QueryType.GetSnapshotBySnapshotId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { SNAPSHOT_IDS[0] }, resultSnapshot1);
    collection.setUriInfo(uriInfo);
    List<Snapshot> snapshots = getCollection();
    verifyCollection(snapshots);
    for (int i = 0; i < 2; i++) {
        verifyAllContent(snapshots.get(i), ConfigurationType.OVF, ovfData);
    }
}
Also used : ArrayList(java.util.ArrayList) Snapshot(org.ovirt.engine.api.model.Snapshot) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Example 14 with Snapshot

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

the class DiskMapper method mapDiskImageToDiskFields.

private static void mapDiskImageToDiskFields(DiskImage entity, Disk model) {
    if (entity.getImageId() != null) {
        model.setImageId(entity.getImageId().toString());
    }
    model.setProvisionedSize(entity.getSize());
    if (entity.hasActualSize()) {
        model.setActualSize(entity.getActualSizeInBytes());
        if (entity.isAllowSnapshot()) {
            model.setTotalSize((long) entity.getActualDiskWithSnapshotsSizeInBytes());
        }
    }
    if (entity.getSnapshotId() != null) {
        model.setSnapshot(new Snapshot());
        model.getSnapshot().setId(entity.getSnapshotId().toString());
    }
    if (entity.getVolumeFormat() != null) {
        model.setFormat(map(entity.getVolumeFormat(), null));
    }
    if (entity.getQcowCompat() != null) {
        model.setQcowVersion(mapQcowCompat(entity.getQcowCompat()));
    }
    if (entity.getImageStatus() != null) {
        model.setStatus(mapDiskStatus(entity.getImageStatus()));
    }
    model.setSparse(VolumeType.Sparse == entity.getVolumeType());
    if (entity.getStorageIds() != null && entity.getStorageIds().size() > 0) {
        if (!model.isSetStorageDomains()) {
            model.setStorageDomains(new StorageDomains());
        }
        for (Guid id : entity.getStorageIds()) {
            StorageDomain storageDomain = new StorageDomain();
            storageDomain.setId(id.toString());
            model.getStorageDomains().getStorageDomains().add(storageDomain);
        }
    }
    if (entity.getQuotaId() != null) {
        Quota quota = new Quota();
        quota.setId(entity.getQuotaId().toString());
        // Add DataCenter to the quota, so links are properly created
        if (entity.getStoragePoolId() != null) {
            quota.setDataCenter(new DataCenter());
            quota.getDataCenter().setId(entity.getStoragePoolId().toString());
        }
        model.setQuota(quota);
    }
    if (entity.getDiskProfileId() != null) {
        DiskProfile diskProfile = new DiskProfile();
        diskProfile.setId(entity.getDiskProfileId().toString());
        model.setDiskProfile(diskProfile);
    }
    if (entity.getCinderVolumeType() != null) {
        OpenStackVolumeType volumeType = model.getOpenstackVolumeType();
        if (volumeType == null) {
            volumeType = new OpenStackVolumeType();
            model.setOpenstackVolumeType(volumeType);
        }
        volumeType.setName(entity.getCinderVolumeType());
    }
}
Also used : OpenStackVolumeType(org.ovirt.engine.api.model.OpenStackVolumeType) Snapshot(org.ovirt.engine.api.model.Snapshot) StorageDomain(org.ovirt.engine.api.model.StorageDomain) DataCenter(org.ovirt.engine.api.model.DataCenter) Quota(org.ovirt.engine.api.model.Quota) Guid(org.ovirt.engine.core.compat.Guid) StorageDomains(org.ovirt.engine.api.model.StorageDomains) DiskProfile(org.ovirt.engine.api.model.DiskProfile)

Aggregations

Snapshot (org.ovirt.engine.api.model.Snapshot)14 Test (org.junit.Test)4 Response (javax.ws.rs.core.Response)3 ArrayList (java.util.ArrayList)2 Snapshots (org.ovirt.engine.api.model.Snapshots)2 Vm (org.ovirt.engine.api.model.Vm)2 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)2 Guid (org.ovirt.engine.core.compat.Guid)2 UriInfo (javax.ws.rs.core.UriInfo)1 Action (org.ovirt.engine.api.model.Action)1 Cdroms (org.ovirt.engine.api.model.Cdroms)1 CustomProperties (org.ovirt.engine.api.model.CustomProperties)1 DataCenter (org.ovirt.engine.api.model.DataCenter)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 DiskProfile (org.ovirt.engine.api.model.DiskProfile)1 Floppies (org.ovirt.engine.api.model.Floppies)1 KatelloErrata (org.ovirt.engine.api.model.KatelloErrata)1 Nics (org.ovirt.engine.api.model.Nics)1