Search in sources :

Example 31 with Snapshot

use of org.ovirt.engine.core.common.businessentities.Snapshot in project ovirt-engine by oVirt.

the class RestoreAllSnapshotsCommandTest method mockSnapshotFromDb.

private void mockSnapshotFromDb() {
    mockSnapshot = new Snapshot();
    mockSnapshot.setType(SnapshotType.STATELESS);
    when(snapshotDao.get(any(Guid.class), any(SnapshotType.class), any(SnapshotStatus.class))).thenReturn(mockSnapshot);
    when(snapshotDao.get(any(Guid.class), any(SnapshotType.class))).thenReturn(mockSnapshot);
    when(snapshotDao.get(any(Guid.class), any(SnapshotStatus.class))).thenReturn(mockSnapshot);
}
Also used : Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) SnapshotStatus(org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotStatus) Guid(org.ovirt.engine.core.compat.Guid) SnapshotType(org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotType)

Example 32 with Snapshot

use of org.ovirt.engine.core.common.businessentities.Snapshot in project ovirt-engine by oVirt.

the class OvfVmReader method readSnapshotsSection.

@Override
protected void readSnapshotsSection(XmlNode section) {
    XmlNodeList list = selectNodes(section, "Snapshot");
    List<Snapshot> snapshots = new ArrayList<>();
    _vm.setSnapshots(snapshots);
    for (XmlNode node : list) {
        XmlNode vmConfiguration = selectSingleNode(node, "VmConfiguration", _xmlNS);
        Snapshot snapshot = new Snapshot(vmConfiguration != null);
        snapshot.setId(new Guid(node.attributes.get("ovf:id").getValue()));
        snapshot.setVmId(_vm.getId());
        snapshot.setType(SnapshotType.valueOf(selectSingleNode(node, "Type", _xmlNS).innerText));
        snapshot.setStatus(SnapshotStatus.OK);
        snapshot.setDescription(selectSingleNode(node, "Description", _xmlNS).innerText);
        XmlNode memory = selectSingleNode(node, "Memory", _xmlNS);
        if (memory != null) {
            List<Guid> guids = Guid.createGuidListFromString(memory.innerText);
            snapshot.setMemoryDiskId(guids.get(2));
            snapshot.setMetadataDiskId(guids.get(4));
        }
        final Date creationDate = OvfParser.utcDateStringToLocalDate(selectSingleNode(node, "CreationDate", _xmlNS).innerText);
        if (creationDate != null) {
            snapshot.setCreationDate(creationDate);
        }
        snapshot.setVmConfiguration(vmConfiguration == null ? null : new String(Base64.decodeBase64(vmConfiguration.innerText)));
        XmlNode appList = selectSingleNode(node, "ApplicationList", _xmlNS);
        if (appList != null) {
            snapshot.setAppList(appList.innerText);
        }
        snapshots.add(snapshot);
    }
}
Also used : Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) Date(java.util.Date) XmlNodeList(org.ovirt.engine.core.utils.ovf.xml.XmlNodeList)

Example 33 with Snapshot

use of org.ovirt.engine.core.common.businessentities.Snapshot in project ovirt-engine by oVirt.

the class OvfVmWriter method writeSnapshotsSection.

/**
 * Write the snapshots of the VM.<br>
 * If no snapshots were set to be written, this section will not be written.
 */
private void writeSnapshotsSection() {
    List<Snapshot> snapshots = vm.getSnapshots();
    if (snapshots == null || snapshots.isEmpty()) {
        return;
    }
    _writer.writeStartElement("Section");
    _writer.writeAttributeString(XSI_URI, "type", "ovf:SnapshotsSection_Type");
    for (Snapshot snapshot : snapshots) {
        _writer.writeStartElement("Snapshot");
        _writer.writeAttributeString(getOvfUri(), "id", snapshot.getId().toString());
        _writer.writeElement("Type", snapshot.getType().name());
        _writer.writeElement("Description", snapshot.getDescription());
        _writer.writeElement("CreationDate", OvfParser.localDateToUtcDateString(snapshot.getCreationDate()));
        if (snapshot.containsMemory()) {
            DiskImage memoryDump = memoryDisks.get(snapshot.getMemoryDiskId());
            DiskImage memoryConf = memoryDisks.get(snapshot.getMetadataDiskId());
            String memoryVolume = String.format("%1$s,%2$s,%3$s,%4$s,%5$s,%6$s", memoryDump.getStorageIds().get(0), memoryDump.getStoragePoolId(), memoryDump.getId(), memoryDump.getImageId(), memoryConf.getId(), memoryConf.getImageId());
            _writer.writeElement("Memory", memoryVolume);
        }
        if (snapshot.getAppList() != null) {
            _writer.writeElement("ApplicationList", snapshot.getAppList());
        }
        if (snapshot.getVmConfiguration() != null) {
            _writer.writeElement("VmConfiguration", Base64.encodeBase64String(snapshot.getVmConfiguration().getBytes()));
        }
        _writer.writeEndElement();
    }
    _writer.writeEndElement();
}
Also used : Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 34 with Snapshot

use of org.ovirt.engine.core.common.businessentities.Snapshot in project ovirt-engine by oVirt.

the class RemoveCinderVolumeParentCommand method getSnapshotWithoutCinderVolume.

protected Snapshot getSnapshotWithoutCinderVolume(CinderDisk lastCinderVolume) {
    Guid vmSnapshotId = lastCinderVolume.getVmSnapshotId();
    Snapshot updated = null;
    if (vmSnapshotId != null && !Guid.Empty.equals(vmSnapshotId)) {
        Snapshot snapshot = snapshotDao.get(vmSnapshotId);
        if (snapshot != null) {
            updated = imagesHandler.prepareSnapshotConfigWithoutImageSingleImage(snapshot, lastCinderVolume.getImageId(), ovfManager);
        }
    }
    return updated;
}
Also used : Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) Guid(org.ovirt.engine.core.compat.Guid)

Example 35 with Snapshot

use of org.ovirt.engine.core.common.businessentities.Snapshot in project ovirt-engine by oVirt.

the class ExportVmCommand method endCopyCollapseOperations.

private void endCopyCollapseOperations(VM vm) {
    vm.setVmtGuid(VmTemplateHandler.BLANK_VM_TEMPLATE_ID);
    vm.setVmtName(null);
    Snapshot activeSnapshot = snapshotDao.get(snapshotDao.getId(vm.getId(), SnapshotType.ACTIVE));
    vm.setSnapshots(Collections.singletonList(activeSnapshot));
    try {
        updateCopyVmInSpm(getVm().getStoragePoolId(), vm, getParameters().getStorageDomainId());
    } catch (EngineException e) {
        log.error("Updating VM OVF in export domain failed.", e);
        auditLogDirector.log(this, AuditLogType.IMPORTEXPORT_IMPORT_VM_FAILED_UPDATING_OVF);
    }
}
Also used : Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) EngineException(org.ovirt.engine.core.common.errors.EngineException)

Aggregations

Snapshot (org.ovirt.engine.core.common.businessentities.Snapshot)96 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)33 VM (org.ovirt.engine.core.common.businessentities.VM)32 Guid (org.ovirt.engine.core.compat.Guid)30 Test (org.junit.Test)21 ArrayList (java.util.ArrayList)15 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)12 List (java.util.List)11 SnapshotStatus (org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotStatus)9 Collections (java.util.Collections)8 Date (java.util.Date)8 Set (java.util.Set)8 Collectors (java.util.stream.Collectors)8 SnapshotType (org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotType)8 EngineException (org.ovirt.engine.core.common.errors.EngineException)8 ActionType (org.ovirt.engine.core.common.action.ActionType)7 DiskStorageType (org.ovirt.engine.core.common.businessentities.storage.DiskStorageType)6 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)6 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5