Add quiesce vm for vmware during vm snapshot

This commit is contained in:
Edison Su 2013-11-08 15:46:48 -08:00
parent d9ebbaeb77
commit 4815b024bf
5 changed files with 25 additions and 8 deletions

View File

@ -31,6 +31,7 @@ public class VMSnapshotTO {
private String description;
private VMSnapshotTO parent;
private List<VolumeObjectTO> volumes;
private boolean quiescevm;
public Long getId() {
return id;
@ -40,7 +41,8 @@ public class VMSnapshotTO {
}
public VMSnapshotTO(Long id, String snapshotName,
VMSnapshot.Type type, Long createTime,
String description, Boolean current, VMSnapshotTO parent) {
String description, Boolean current, VMSnapshotTO parent,
boolean quiescevm) {
super();
this.id = id;
this.snapshotName = snapshotName;
@ -49,9 +51,10 @@ public class VMSnapshotTO {
this.current = current;
this.description = description;
this.parent = parent;
this.quiescevm = quiescevm;
}
public VMSnapshotTO() {
this.quiescevm = true;
}
public String getDescription() {
return description;
@ -99,4 +102,12 @@ public class VMSnapshotTO {
public void setVolumes(List<VolumeObjectTO> volumes) {
this.volumes = volumes;
}
public boolean getQuiescevm() {
return this.quiescevm;
}
public void setQuiescevm(boolean quiescevm) {
this.quiescevm = quiescevm;
}
}

View File

@ -25,6 +25,7 @@ import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.cloudstack.engine.subsystem.api.storage.StrategyPriority;
import org.apache.cloudstack.engine.subsystem.api.storage.VMSnapshotOptions;
import org.apache.cloudstack.engine.subsystem.api.storage.VMSnapshotStrategy;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.storage.to.VolumeObjectTO;
@ -111,8 +112,12 @@ public class DefaultVMSnapshotStrategy extends ManagerBase implements VMSnapshot
VMSnapshotVO currentSnapshot = vmSnapshotDao.findCurrentSnapshotByVmId(userVm.getId());
if (currentSnapshot != null)
current = vmSnapshotHelper.getSnapshotWithParents(currentSnapshot);
VMSnapshotOptions options = ((VMSnapshotVO) vmSnapshot).getOptions();
boolean quiescevm = true;
if (options != null)
quiescevm = options.needQuiesceVM();
VMSnapshotTO target = new VMSnapshotTO(vmSnapshot.getId(), vmSnapshot.getName(), vmSnapshot.getType(), null, vmSnapshot.getDescription(), false,
current);
current, quiescevm);
if (current == null)
vmSnapshotVO.setParent(null);
else
@ -174,7 +179,7 @@ public class DefaultVMSnapshotStrategy extends ManagerBase implements VMSnapshot
String vmInstanceName = userVm.getInstanceName();
VMSnapshotTO parent = vmSnapshotHelper.getSnapshotWithParents(vmSnapshotVO).getParent();
VMSnapshotTO vmSnapshotTO = new VMSnapshotTO(vmSnapshot.getId(), vmSnapshot.getName(), vmSnapshot.getType(),
vmSnapshot.getCreated().getTime(), vmSnapshot.getDescription(), vmSnapshot.getCurrent(), parent);
vmSnapshot.getCreated().getTime(), vmSnapshot.getDescription(), vmSnapshot.getCurrent(), parent, true);
GuestOSVO guestOS = guestOSDao.findById(userVm.getGuestOSId());
DeleteVMSnapshotCommand deleteSnapshotCommand = new DeleteVMSnapshotCommand(vmInstanceName, vmSnapshotTO, volumeTOs,guestOS.getDisplayName());
@ -330,7 +335,7 @@ public class DefaultVMSnapshotStrategy extends ManagerBase implements VMSnapshot
VMSnapshotTO parent = vmSnapshotHelper.getSnapshotWithParents(snapshot).getParent();
VMSnapshotTO vmSnapshotTO = new VMSnapshotTO(snapshot.getId(), snapshot.getName(), snapshot.getType(),
snapshot.getCreated().getTime(), snapshot.getDescription(), snapshot.getCurrent(), parent);
snapshot.getCreated().getTime(), snapshot.getDescription(), snapshot.getCurrent(), parent, true);
Long hostId = vmSnapshotHelper.pickRunningHost(vmSnapshot.getVmId());
GuestOSVO guestOS = guestOSDao.findById(userVm.getGuestOSId());
RevertToVMSnapshotCommand revertToSnapshotCommand = new RevertToVMSnapshotCommand(vmInstanceName, vmSnapshotTO, volumeTOs, guestOS.getDisplayName());

View File

@ -111,7 +111,7 @@ public class HypervisorHelperImpl implements HypervisorHelper {
int wait = NumbersUtil.parseInt(value, 1800);
Long hostId = vmSnapshotHelper.pickRunningHost(virtualMachine.getId());
VMSnapshotTO vmSnapshotTO = new VMSnapshotTO(1L, UUID.randomUUID().toString(), VMSnapshot.Type.DiskAndMemory, null, null, false,
null);
null, true);
GuestOSVO guestOS = guestOSDao.findById(virtualMachine.getGuestOSId());
List<VolumeObjectTO> volumeTOs = vmSnapshotHelper.getVolumeTOList(virtualMachine.getId());
CreateVMSnapshotCommand ccmd = new CreateVMSnapshotCommand(virtualMachine.getInstanceName(),vmSnapshotTO ,volumeTOs, guestOS.getDisplayName(),virtualMachine.getState());

View File

@ -122,7 +122,7 @@ public class VMSnapshotHelperImpl implements VMSnapshotHelper {
private VMSnapshotTO convert2VMSnapshotTO(VMSnapshotVO vo) {
return new VMSnapshotTO(vo.getId(), vo.getName(), vo.getType(), vo.getCreated().getTime(), vo.getDescription(),
vo.getCurrent(), null);
vo.getCurrent(), null, true);
}
@Override

View File

@ -1275,6 +1275,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
String vmSnapshotName = cmd.getTarget().getSnapshotName();
String vmSnapshotDesc = cmd.getTarget().getDescription();
boolean snapshotMemory = cmd.getTarget().getType() == VMSnapshot.Type.DiskAndMemory;
boolean quiescevm = cmd.getTarget().getQuiescevm();
VirtualMachineMO vmMo = null;
VmwareContext context = hostService.getServiceContext(cmd);
Map<String, String> mapNewDisk = new HashMap<String, String>();
@ -1303,7 +1304,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
} else {
if (vmMo.getSnapshotMor(vmSnapshotName) != null){
s_logger.debug("VM snapshot " + vmSnapshotName + " already exists");
}else if (!vmMo.createSnapshot(vmSnapshotName, vmSnapshotDesc, snapshotMemory, true)) {
}else if (!vmMo.createSnapshot(vmSnapshotName, vmSnapshotDesc, snapshotMemory, quiescevm)) {
return new CreateVMSnapshotAnswer(cmd, false,
"Unable to create snapshot due to esxi internal failed");
}