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