Search in sources :

Example 1 with RestoreVMSnapshotCommand

use of com.cloud.agent.api.RestoreVMSnapshotCommand in project cloudstack by apache.

the class VMSnapshotManagerImpl method createRestoreCommand.

@Override
public RestoreVMSnapshotCommand createRestoreCommand(UserVmVO userVm, List<VMSnapshotVO> vmSnapshotVOs) {
    if (!HypervisorType.KVM.equals(userVm.getHypervisorType()))
        return null;
    List<VMSnapshotTO> snapshots = new ArrayList<VMSnapshotTO>();
    Map<Long, VMSnapshotTO> snapshotAndParents = new HashMap<Long, VMSnapshotTO>();
    for (VMSnapshotVO vmSnapshotVO : vmSnapshotVOs) {
        if (vmSnapshotVO.getType() == VMSnapshot.Type.DiskAndMemory) {
            VMSnapshotVO snapshot = _vmSnapshotDao.findById(vmSnapshotVO.getId());
            VMSnapshotTO parent = getSnapshotWithParents(snapshot).getParent();
            VMSnapshotOptions options = snapshot.getOptions();
            boolean quiescevm = true;
            if (options != null)
                quiescevm = options.needQuiesceVM();
            VMSnapshotTO vmSnapshotTO = new VMSnapshotTO(snapshot.getId(), snapshot.getName(), snapshot.getType(), snapshot.getCreated().getTime(), snapshot.getDescription(), snapshot.getCurrent(), parent, quiescevm);
            snapshots.add(vmSnapshotTO);
            snapshotAndParents.put(vmSnapshotVO.getId(), parent);
        }
    }
    if (snapshotAndParents.isEmpty())
        return null;
    // prepare RestoreVMSnapshotCommand
    String vmInstanceName = userVm.getInstanceName();
    List<VolumeObjectTO> volumeTOs = getVolumeTOList(userVm.getId());
    GuestOSVO guestOS = _guestOSDao.findById(userVm.getGuestOSId());
    RestoreVMSnapshotCommand restoreSnapshotCommand = new RestoreVMSnapshotCommand(vmInstanceName, null, volumeTOs, guestOS.getDisplayName());
    restoreSnapshotCommand.setSnapshots(snapshots);
    restoreSnapshotCommand.setSnapshotAndParents(snapshotAndParents);
    return restoreSnapshotCommand;
}
Also used : HashMap(java.util.HashMap) VMSnapshotOptions(org.apache.cloudstack.engine.subsystem.api.storage.VMSnapshotOptions) ArrayList(java.util.ArrayList) GuestOSVO(com.cloud.storage.GuestOSVO) RestoreVMSnapshotCommand(com.cloud.agent.api.RestoreVMSnapshotCommand) VMSnapshotTO(com.cloud.agent.api.VMSnapshotTO) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO)

Example 2 with RestoreVMSnapshotCommand

use of com.cloud.agent.api.RestoreVMSnapshotCommand in project cloudstack by apache.

the class VirtualMachineManagerImpl method checkVmOnHost.

protected boolean checkVmOnHost(final VirtualMachine vm, final long hostId) throws AgentUnavailableException, OperationTimedoutException {
    final Answer answer = _agentMgr.send(hostId, new CheckVirtualMachineCommand(vm.getInstanceName()));
    if (answer == null || !answer.getResult()) {
        return false;
    }
    if (answer instanceof CheckVirtualMachineAnswer) {
        final CheckVirtualMachineAnswer vmAnswer = (CheckVirtualMachineAnswer) answer;
        if (vmAnswer.getState() == PowerState.PowerOff) {
            return false;
        }
    }
    UserVmVO userVm = _userVmDao.findById(vm.getId());
    if (userVm != null) {
        List<VMSnapshotVO> vmSnapshots = _vmSnapshotDao.findByVm(vm.getId());
        RestoreVMSnapshotCommand command = _vmSnapshotMgr.createRestoreCommand(userVm, vmSnapshots);
        if (command != null) {
            RestoreVMSnapshotAnswer restoreVMSnapshotAnswer = (RestoreVMSnapshotAnswer) _agentMgr.send(hostId, command);
            if (restoreVMSnapshotAnswer == null || !restoreVMSnapshotAnswer.getResult()) {
                s_logger.warn("Unable to restore the vm snapshot from image file after live migration of vm with vmsnapshots: " + restoreVMSnapshotAnswer.getDetails());
            }
        }
    }
    return true;
}
Also used : CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) RebootAnswer(com.cloud.agent.api.RebootAnswer) StartAnswer(com.cloud.agent.api.StartAnswer) RestoreVMSnapshotAnswer(com.cloud.agent.api.RestoreVMSnapshotAnswer) PlugNicAnswer(com.cloud.agent.api.PlugNicAnswer) StopAnswer(com.cloud.agent.api.StopAnswer) Answer(com.cloud.agent.api.Answer) UnPlugNicAnswer(com.cloud.agent.api.UnPlugNicAnswer) ClusterVMMetaDataSyncAnswer(com.cloud.agent.api.ClusterVMMetaDataSyncAnswer) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) VMSnapshotVO(com.cloud.vm.snapshot.VMSnapshotVO) RestoreVMSnapshotCommand(com.cloud.agent.api.RestoreVMSnapshotCommand) RestoreVMSnapshotAnswer(com.cloud.agent.api.RestoreVMSnapshotAnswer) CheckVirtualMachineCommand(com.cloud.agent.api.CheckVirtualMachineCommand)

Example 3 with RestoreVMSnapshotCommand

use of com.cloud.agent.api.RestoreVMSnapshotCommand in project cloudstack by apache.

the class UserVmManagerImpl method finalizeCommandsOnStart.

@Override
public boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile profile) {
    UserVmVO vm = _vmDao.findById(profile.getId());
    List<VMSnapshotVO> vmSnapshots = _vmSnapshotDao.findByVm(vm.getId());
    RestoreVMSnapshotCommand command = _vmSnapshotMgr.createRestoreCommand(vm, vmSnapshots);
    if (command != null)
        cmds.addCommand("restoreVMSnapshot", command);
    return true;
}
Also used : VMSnapshotVO(com.cloud.vm.snapshot.VMSnapshotVO) RestoreVMSnapshotCommand(com.cloud.agent.api.RestoreVMSnapshotCommand)

Aggregations

RestoreVMSnapshotCommand (com.cloud.agent.api.RestoreVMSnapshotCommand)3 VMSnapshotVO (com.cloud.vm.snapshot.VMSnapshotVO)2 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)1 Answer (com.cloud.agent.api.Answer)1 CheckVirtualMachineAnswer (com.cloud.agent.api.CheckVirtualMachineAnswer)1 CheckVirtualMachineCommand (com.cloud.agent.api.CheckVirtualMachineCommand)1 ClusterVMMetaDataSyncAnswer (com.cloud.agent.api.ClusterVMMetaDataSyncAnswer)1 PlugNicAnswer (com.cloud.agent.api.PlugNicAnswer)1 RebootAnswer (com.cloud.agent.api.RebootAnswer)1 RestoreVMSnapshotAnswer (com.cloud.agent.api.RestoreVMSnapshotAnswer)1 StartAnswer (com.cloud.agent.api.StartAnswer)1 StopAnswer (com.cloud.agent.api.StopAnswer)1 UnPlugNicAnswer (com.cloud.agent.api.UnPlugNicAnswer)1 VMSnapshotTO (com.cloud.agent.api.VMSnapshotTO)1 GuestOSVO (com.cloud.storage.GuestOSVO)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 VMSnapshotOptions (org.apache.cloudstack.engine.subsystem.api.storage.VMSnapshotOptions)1 VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)1