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;
}
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;
}
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;
}
Aggregations