private VMSnapshot takeHypervisorSnapshot(VolumeInfo volumeInfo) {
VirtualMachine virtualMachine = volumeInfo.getAttachedVM();
if (virtualMachine != null && VirtualMachine.State.Running.equals(virtualMachine.getState())) {
String vmSnapshotName = UUID.randomUUID().toString().replace("-", "");
VMSnapshotVO vmSnapshotVO =
new VMSnapshotVO(virtualMachine.getAccountId(), virtualMachine.getDomainId(), virtualMachine.getId(), vmSnapshotName, vmSnapshotName,
vmSnapshotName, virtualMachine.getServiceOfferingId(), VMSnapshot.Type.Disk, null);
VMSnapshot vmSnapshot = vmSnapshotDao.persist(vmSnapshotVO);
if (vmSnapshot == null) {
throw new CloudRuntimeException("Unable to allocate a VM snapshot object");
}
vmSnapshot = vmSnapshotService.createVMSnapshot(virtualMachine.getId(), vmSnapshot.getId(), true);
if (vmSnapshot == null) {
throw new CloudRuntimeException("Unable to create a hypervisor-side snapshot");
}
try {
Thread.sleep(60000);
}
catch (Exception ex) {
s_logger.warn(ex.getMessage(), ex);
}
return vmSnapshot;
}
return null;
}