Search in sources :

Example 1 with VirtualMachineSnapshotTree

use of com.vmware.vim25.VirtualMachineSnapshotTree in project cloudstack by apache.

the class VirtualMachineMO method removeAllSnapshots.

public boolean removeAllSnapshots() throws Exception {
    VirtualMachineSnapshotInfo snapshotInfo = getSnapshotInfo();
    if (snapshotInfo != null && snapshotInfo.getRootSnapshotList() != null) {
        List<VirtualMachineSnapshotTree> tree = snapshotInfo.getRootSnapshotList();
        for (VirtualMachineSnapshotTree treeNode : tree) {
            ManagedObjectReference morTask = _context.getService().removeSnapshotTask(treeNode.getSnapshot(), true, true);
            boolean result = _context.getVimClient().waitForTask(morTask);
            if (result) {
                _context.waitForTaskProgressDone(morTask);
            } else {
                s_logger.error("VMware removeSnapshot_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
                return false;
            }
        }
    }
    return true;
}
Also used : VirtualMachineSnapshotInfo(com.vmware.vim25.VirtualMachineSnapshotInfo) VirtualMachineSnapshotTree(com.vmware.vim25.VirtualMachineSnapshotTree) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 2 with VirtualMachineSnapshotTree

use of com.vmware.vim25.VirtualMachineSnapshotTree in project cloudstack by apache.

the class VmwareHelper method findSnapshotInTree.

public static ManagedObjectReference findSnapshotInTree(List<VirtualMachineSnapshotTree> snapTree, String findName) {
    assert (findName != null);
    ManagedObjectReference snapMor = null;
    if (snapTree == null)
        return snapMor;
    for (int i = 0; i < snapTree.size() && snapMor == null; i++) {
        VirtualMachineSnapshotTree node = snapTree.get(i);
        if (node.getName().equals(findName)) {
            snapMor = node.getSnapshot();
        } else {
            List<VirtualMachineSnapshotTree> childTree = node.getChildSnapshotList();
            snapMor = findSnapshotInTree(childTree, findName);
        }
    }
    return snapMor;
}
Also used : ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) VirtualMachineSnapshotTree(com.vmware.vim25.VirtualMachineSnapshotTree)

Example 3 with VirtualMachineSnapshotTree

use of com.vmware.vim25.VirtualMachineSnapshotTree in project CloudStack-archive by CloudStack-extras.

the class VirtualMachineMO method removeAllSnapshots.

public boolean removeAllSnapshots() throws Exception {
    VirtualMachineSnapshotInfo snapshotInfo = getSnapshotInfo();
    if (snapshotInfo != null && snapshotInfo.getRootSnapshotList() != null) {
        VirtualMachineSnapshotTree[] tree = snapshotInfo.getRootSnapshotList();
        for (VirtualMachineSnapshotTree treeNode : tree) {
            ManagedObjectReference morTask = _context.getService().removeSnapshot_Task(treeNode.getSnapshot(), true);
            String result = _context.getServiceUtil().waitForTask(morTask);
            if (result.equals("sucess")) {
                _context.waitForTaskProgressDone(morTask);
            } else {
                s_logger.error("VMware removeSnapshot_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
                return false;
            }
        }
    }
    return true;
}
Also used : VirtualMachineSnapshotInfo(com.vmware.vim25.VirtualMachineSnapshotInfo) VirtualMachineSnapshotTree(com.vmware.vim25.VirtualMachineSnapshotTree) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 4 with VirtualMachineSnapshotTree

use of com.vmware.vim25.VirtualMachineSnapshotTree in project CloudStack-archive by CloudStack-extras.

the class VmwareHelper method findSnapshotInTree.

public static ManagedObjectReference findSnapshotInTree(VirtualMachineSnapshotTree[] snapTree, String findName) {
    assert (findName != null);
    ManagedObjectReference snapMor = null;
    if (snapTree == null)
        return snapMor;
    for (int i = 0; i < snapTree.length && snapMor == null; i++) {
        VirtualMachineSnapshotTree node = snapTree[i];
        if (node.getName().equals(findName)) {
            snapMor = node.getSnapshot();
        } else {
            VirtualMachineSnapshotTree[] childTree = node.getChildSnapshotList();
            snapMor = findSnapshotInTree(childTree, findName);
        }
    }
    return snapMor;
}
Also used : ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) VirtualMachineSnapshotTree(com.vmware.vim25.VirtualMachineSnapshotTree)

Example 5 with VirtualMachineSnapshotTree

use of com.vmware.vim25.VirtualMachineSnapshotTree in project photon-model by vmware.

the class VSphereVMSnapshotEnumerationHelper method processSnapshot.

static void processSnapshot(VSphereIncrementalEnumerationService service, VirtualMachineSnapshotTree current, String parentLink, EnumerationProgress enumerationProgress, VmOverlay vm, String vmSelfLink) {
    enumerationProgress.getSnapshotTracker().register();
    QueryTask task = queryForSnapshot(enumerationProgress, current.getId().toString(), vmSelfLink);
    VsphereEnumerationHelper.withTaskResults(service, task, (ServiceDocumentQueryResult result) -> {
        VsphereEnumerationHelper.submitWorkToVSpherePool(service, () -> {
            SnapshotState snapshotState = constructSnapshot(service, current, parentLink, vmSelfLink, enumerationProgress, vm);
            if (result.documentLinks.isEmpty()) {
                VSphereVirtualMachineEnumerationHelper.createSnapshot(service, snapshotState).thenCompose(createdSnapshotState -> trackAndProcessChildSnapshots(service, current, enumerationProgress, vm, vmSelfLink, createdSnapshotState)).whenComplete((ss, e) -> {
                    if (e != null) {
                        service.log(Level.SEVERE, "Creation of snapshot with name {%s} failed.", snapshotState.name);
                    }
                    enumerationProgress.getSnapshotTracker().arrive();
                });
            } else {
                SnapshotState oldState = VsphereEnumerationHelper.convertOnlyResultToDocument(result, SnapshotState.class);
                updateSnapshot(service, enumerationProgress, vm, oldState, snapshotState, current.getId().toString()).thenCompose(updatedSnapshotState -> trackAndProcessChildSnapshots(service, current, enumerationProgress, vm, vmSelfLink, updatedSnapshotState)).whenComplete((ss, e) -> {
                    if (e != null) {
                        service.logSevere("Updating of snapshot with name {%s}, selfLink {%s} failed", snapshotState.name, oldState.documentSelfLink);
                    }
                    enumerationProgress.getSnapshotTracker().arrive();
                });
            }
        });
    });
}
Also used : ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) Operation(com.vmware.xenon.common.Operation) QueryTask(com.vmware.xenon.services.common.QueryTask) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) SnapshotState(com.vmware.photon.controller.model.resources.SnapshotService.SnapshotState) Level(java.util.logging.Level) HashSet(java.util.HashSet) List(java.util.List) CollectionUtils(org.apache.commons.collections.CollectionUtils) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) VirtualMachineSnapshotTree(com.vmware.vim25.VirtualMachineSnapshotTree) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) Builder(com.vmware.xenon.services.common.QueryTask.Query.Builder) QueryTask(com.vmware.xenon.services.common.QueryTask) SnapshotState(com.vmware.photon.controller.model.resources.SnapshotService.SnapshotState) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult)

Aggregations

VirtualMachineSnapshotTree (com.vmware.vim25.VirtualMachineSnapshotTree)7 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)6 VirtualMachineSnapshotInfo (com.vmware.vim25.VirtualMachineSnapshotInfo)4 ArrayOfManagedObjectReference (com.vmware.vim25.ArrayOfManagedObjectReference)3 ComputeEnumerateResourceRequest (com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest)1 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)1 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)1 SnapshotState (com.vmware.photon.controller.model.resources.SnapshotService.SnapshotState)1 VirtualMachineSnapshot (com.vmware.vim25.mo.VirtualMachineSnapshot)1 DeferredResult (com.vmware.xenon.common.DeferredResult)1 Operation (com.vmware.xenon.common.Operation)1 ServiceDocumentQueryResult (com.vmware.xenon.common.ServiceDocumentQueryResult)1 UriUtils (com.vmware.xenon.common.UriUtils)1 QueryTask (com.vmware.xenon.services.common.QueryTask)1 Builder (com.vmware.xenon.services.common.QueryTask.Query.Builder)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Level (java.util.logging.Level)1 CollectionUtils (org.apache.commons.collections.CollectionUtils)1