Search in sources :

Example 1 with RestoreVMSnapshotCommand

use of com.cloud.legacymodel.communication.command.RestoreVMSnapshotCommand in project cosmic by MissionCriticalCloud.

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;
        }
    }
    final UserVmVO userVm = _userVmDao.findById(vm.getId());
    if (userVm != null) {
        final List<VMSnapshotVO> vmSnapshots = _vmSnapshotDao.findByVm(vm.getId());
        final RestoreVMSnapshotCommand command = _vmSnapshotMgr.createRestoreCommand(userVm, vmSnapshots);
        if (command != null) {
            final 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.legacymodel.communication.answer.CheckVirtualMachineAnswer) UnPlugNicAnswer(com.cloud.legacymodel.communication.answer.UnPlugNicAnswer) AgentControlAnswer(com.cloud.legacymodel.communication.answer.AgentControlAnswer) ClusterVMMetaDataSyncAnswer(com.cloud.legacymodel.communication.answer.ClusterVMMetaDataSyncAnswer) RestoreVMSnapshotAnswer(com.cloud.legacymodel.communication.answer.RestoreVMSnapshotAnswer) RebootAnswer(com.cloud.legacymodel.communication.answer.RebootAnswer) StartAnswer(com.cloud.legacymodel.communication.answer.StartAnswer) PlugNicAnswer(com.cloud.legacymodel.communication.answer.PlugNicAnswer) CheckVirtualMachineAnswer(com.cloud.legacymodel.communication.answer.CheckVirtualMachineAnswer) StopAnswer(com.cloud.legacymodel.communication.answer.StopAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) VMSnapshotVO(com.cloud.vm.snapshot.VMSnapshotVO) RestoreVMSnapshotCommand(com.cloud.legacymodel.communication.command.RestoreVMSnapshotCommand) RestoreVMSnapshotAnswer(com.cloud.legacymodel.communication.answer.RestoreVMSnapshotAnswer) CheckVirtualMachineCommand(com.cloud.legacymodel.communication.command.CheckVirtualMachineCommand)

Example 2 with RestoreVMSnapshotCommand

use of com.cloud.legacymodel.communication.command.RestoreVMSnapshotCommand in project cosmic by MissionCriticalCloud.

the class UserVmManagerImpl method finalizeCommandsOnStart.

@Override
public boolean finalizeCommandsOnStart(final Commands cmds, final VirtualMachineProfile profile) {
    final UserVmVO vm = _vmDao.findById(profile.getId());
    final List<VMSnapshotVO> vmSnapshots = _vmSnapshotDao.findByVm(vm.getId());
    final 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.legacymodel.communication.command.RestoreVMSnapshotCommand)

Example 3 with RestoreVMSnapshotCommand

use of com.cloud.legacymodel.communication.command.RestoreVMSnapshotCommand in project cosmic by MissionCriticalCloud.

the class VMSnapshotManagerImpl method createRestoreCommand.

@Override
public RestoreVMSnapshotCommand createRestoreCommand(final UserVmVO userVm, final List<VMSnapshotVO> vmSnapshotVOs) {
    if (!HypervisorType.KVM.equals(userVm.getHypervisorType())) {
        return null;
    }
    final List<VMSnapshotTO> snapshots = new ArrayList<>();
    final Map<Long, VMSnapshotTO> snapshotAndParents = new HashMap<>();
    for (final VMSnapshotVO vmSnapshotVO : vmSnapshotVOs) {
        if (vmSnapshotVO.getType() == VMSnapshot.Type.DiskAndMemory) {
            final VMSnapshotVO snapshot = _vmSnapshotDao.findById(vmSnapshotVO.getId());
            final VMSnapshotTO parent = getSnapshotWithParents(snapshot).getParent();
            final VMSnapshotOptions options = snapshot.getOptions();
            boolean quiescevm = true;
            if (options != null) {
                quiescevm = options.needQuiesceVM();
            }
            final 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
    final String vmInstanceName = userVm.getInstanceName();
    final List<VolumeObjectTO> volumeTOs = getVolumeTOList(userVm.getId());
    final GuestOSVO guestOS = _guestOSDao.findById(userVm.getGuestOSId());
    final RestoreVMSnapshotCommand restoreSnapshotCommand = new RestoreVMSnapshotCommand(vmInstanceName, null, volumeTOs, guestOS.getDisplayName());
    restoreSnapshotCommand.setSnapshots(snapshots);
    restoreSnapshotCommand.setSnapshotAndParents(snapshotAndParents);
    return restoreSnapshotCommand;
}
Also used : HashMap(java.util.HashMap) VMSnapshotOptions(com.cloud.engine.subsystem.api.storage.VMSnapshotOptions) ArrayList(java.util.ArrayList) GuestOSVO(com.cloud.storage.GuestOSVO) RestoreVMSnapshotCommand(com.cloud.legacymodel.communication.command.RestoreVMSnapshotCommand) VMSnapshotTO(com.cloud.legacymodel.to.VMSnapshotTO) VolumeObjectTO(com.cloud.legacymodel.to.VolumeObjectTO)

Aggregations

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