mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Add support routines for incremental snapshot support
This commit is contained in:
parent
fa1bac5faf
commit
3020df75f1
36
core/test/com/cloud/hypervisor/vmware/mo/TestVmwareMO.java
Executable file → Normal file
36
core/test/com/cloud/hypervisor/vmware/mo/TestVmwareMO.java
Executable file → Normal file
@ -16,8 +16,10 @@ import java.util.GregorianCalendar;
|
|||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
import com.cloud.hypervisor.vmware.mo.SnapshotDescriptor.SnapshotInfo;
|
||||||
import com.cloud.hypervisor.vmware.util.VmwareContext;
|
import com.cloud.hypervisor.vmware.util.VmwareContext;
|
||||||
import com.cloud.serializer.GsonHelper;
|
import com.cloud.serializer.GsonHelper;
|
||||||
|
import com.cloud.utils.Pair;
|
||||||
import com.cloud.utils.testcase.Log4jEnabledTestCase;
|
import com.cloud.utils.testcase.Log4jEnabledTestCase;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.vmware.vim25.DynamicProperty;
|
import com.vmware.vim25.DynamicProperty;
|
||||||
@ -29,40 +31,6 @@ public class TestVmwareMO extends Log4jEnabledTestCase {
|
|||||||
private static final Logger s_logger = Logger.getLogger(TestVmwareMO.class);
|
private static final Logger s_logger = Logger.getLogger(TestVmwareMO.class);
|
||||||
|
|
||||||
public void test() {
|
public void test() {
|
||||||
try {
|
|
||||||
VmwareContext context = TestVmwareContextFactory.create(
|
|
||||||
"10.223.80.29", "Administrator", "Suite219");
|
|
||||||
|
|
||||||
HostMO hostMo = new HostMO(context, "HostSystem", "host-10");
|
|
||||||
ObjectContent[] ocs = hostMo.getVmPropertiesOnHyperHost(new String[] {"name", "config.template", "runtime.bootTime"});
|
|
||||||
if(ocs != null) {
|
|
||||||
for(ObjectContent oc : ocs) {
|
|
||||||
DynamicProperty[] props = oc.getPropSet();
|
|
||||||
if(props != null) {
|
|
||||||
String name = null;
|
|
||||||
boolean template = false;
|
|
||||||
GregorianCalendar bootTime = null;
|
|
||||||
|
|
||||||
for(DynamicProperty prop : props) {
|
|
||||||
if(prop.getName().equals("name"))
|
|
||||||
name = prop.getVal().toString();
|
|
||||||
else if(prop.getName().equals("config.template"))
|
|
||||||
template = (Boolean)prop.getVal();
|
|
||||||
else if(prop.getName().equals("runtime.bootTime"))
|
|
||||||
bootTime = (GregorianCalendar)prop.getVal();
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("name: " + name + ", template: " + template + ", bootTime: " + bootTime);
|
|
||||||
|
|
||||||
}
|
|
||||||
System.out.println("");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
context.close();
|
|
||||||
} catch(Exception e) {
|
|
||||||
s_logger.error("Unexpected exception : ", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
27
vmware-base/src/com/cloud/hypervisor/vmware/mo/SnapshotDescriptor.java
Executable file → Normal file
27
vmware-base/src/com/cloud/hypervisor/vmware/mo/SnapshotDescriptor.java
Executable file → Normal file
@ -248,6 +248,28 @@ public class SnapshotDescriptor {
|
|||||||
public DiskInfo[] getDisks() {
|
public DiskInfo[] getDisks() {
|
||||||
return _disks;
|
return _disks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
sb.append("SnapshotInfo : { id: ");
|
||||||
|
sb.append(_id);
|
||||||
|
sb.append(", displayName: ").append(_displayName);
|
||||||
|
sb.append(", numOfDisks: ").append(_numOfDisks);
|
||||||
|
sb.append(", disks: [");
|
||||||
|
if(_disks != null) {
|
||||||
|
int i = 0;
|
||||||
|
for(DiskInfo diskInfo : _disks) {
|
||||||
|
if(i > 0)
|
||||||
|
sb.append(", ");
|
||||||
|
sb.append(diskInfo.toString());
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sb.append("]}");
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class DiskInfo {
|
public static class DiskInfo {
|
||||||
@ -266,5 +288,10 @@ public class SnapshotDescriptor {
|
|||||||
public String getDeviceName() {
|
public String getDeviceName() {
|
||||||
return _deviceName;
|
return _deviceName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "DiskInfo: { device: " + _deviceName + ", file: " + _diskFileName + " }";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
33
vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
Executable file → Normal file
33
vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
Executable file → Normal file
@ -944,6 +944,39 @@ public class VirtualMachineMO extends BaseMO {
|
|||||||
s_logger.trace("vCenter API trace - attachDisk() done(successfully)");
|
s_logger.trace("vCenter API trace - attachDisk() done(successfully)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void attachDisk(Pair<String, ManagedObjectReference>[] vmdkDatastorePathChain, int controllerKey) throws Exception {
|
||||||
|
|
||||||
|
if(s_logger.isTraceEnabled())
|
||||||
|
s_logger.trace("vCenter API trace - attachDisk(). target MOR: " + _mor.get_value() + ", vmdkDatastorePath: "
|
||||||
|
+ new Gson().toJson(vmdkDatastorePathChain));
|
||||||
|
|
||||||
|
VirtualDevice newDisk = VmwareHelper.prepareDiskDevice(this, controllerKey,
|
||||||
|
vmdkDatastorePathChain, -1, 1);
|
||||||
|
VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec();
|
||||||
|
VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
|
||||||
|
VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
|
||||||
|
|
||||||
|
deviceConfigSpec.setDevice(newDisk);
|
||||||
|
deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.add);
|
||||||
|
|
||||||
|
deviceConfigSpecArray[0] = deviceConfigSpec;
|
||||||
|
reConfigSpec.setDeviceChange(deviceConfigSpecArray);
|
||||||
|
|
||||||
|
ManagedObjectReference morTask = _context.getService().reconfigVM_Task(_mor, reConfigSpec);
|
||||||
|
String result = _context.getServiceUtil().waitForTask(morTask);
|
||||||
|
|
||||||
|
if(!result.equals("sucess")) {
|
||||||
|
if(s_logger.isTraceEnabled())
|
||||||
|
s_logger.trace("vCenter API trace - attachDisk() done(failed)");
|
||||||
|
throw new Exception("Failed to attach disk due to " + TaskMO.getTaskFailureInfo(_context, morTask));
|
||||||
|
}
|
||||||
|
|
||||||
|
_context.waitForTaskProgressDone(morTask);
|
||||||
|
|
||||||
|
if(s_logger.isTraceEnabled())
|
||||||
|
s_logger.trace("vCenter API trace - attachDisk() done(successfully)");
|
||||||
|
}
|
||||||
|
|
||||||
// vmdkDatastorePath: [datastore name] vmdkFilePath
|
// vmdkDatastorePath: [datastore name] vmdkFilePath
|
||||||
public List<Pair<String, ManagedObjectReference>> detachDisk(String vmdkDatastorePath, boolean deleteBackingFile) throws Exception {
|
public List<Pair<String, ManagedObjectReference>> detachDisk(String vmdkDatastorePath, boolean deleteBackingFile) throws Exception {
|
||||||
|
|
||||||
|
|||||||
58
vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareHelper.java
Executable file → Normal file
58
vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareHelper.java
Executable file → Normal file
@ -246,6 +246,46 @@ public class VmwareHelper {
|
|||||||
return disk;
|
return disk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static VirtualDevice prepareDiskDevice(VirtualMachineMO vmMo, int controllerKey,
|
||||||
|
Pair<String, ManagedObjectReference>[] vmdkDatastorePathChain,
|
||||||
|
int deviceNumber, int contextNumber) throws Exception {
|
||||||
|
|
||||||
|
assert(vmdkDatastorePathChain != null);
|
||||||
|
assert(vmdkDatastorePathChain.length >= 1);
|
||||||
|
|
||||||
|
VirtualDisk disk = new VirtualDisk();
|
||||||
|
|
||||||
|
VirtualDiskFlatVer2BackingInfo backingInfo = new VirtualDiskFlatVer2BackingInfo();
|
||||||
|
backingInfo.setDatastore(vmdkDatastorePathChain[0].second());
|
||||||
|
backingInfo.setFileName(vmdkDatastorePathChain[0].first());
|
||||||
|
backingInfo.setDiskMode(VirtualDiskMode.persistent.toString());
|
||||||
|
if(vmdkDatastorePathChain.length > 1) {
|
||||||
|
Pair<String, ManagedObjectReference>[] parentDisks = new Pair[vmdkDatastorePathChain.length - 1];
|
||||||
|
for(int i = 0; i < vmdkDatastorePathChain.length - 1; i++)
|
||||||
|
parentDisks[i] = vmdkDatastorePathChain[i + 1];
|
||||||
|
|
||||||
|
setParentBackingInfo(backingInfo, parentDisks);
|
||||||
|
}
|
||||||
|
|
||||||
|
disk.setBacking(backingInfo);
|
||||||
|
|
||||||
|
if(controllerKey < 0)
|
||||||
|
controllerKey = vmMo.getIDEDeviceControllerKey();
|
||||||
|
if(deviceNumber < 0)
|
||||||
|
deviceNumber = vmMo.getNextDeviceNumber(controllerKey);
|
||||||
|
|
||||||
|
disk.setControllerKey(controllerKey);
|
||||||
|
disk.setKey(-contextNumber);
|
||||||
|
disk.setUnitNumber(deviceNumber);
|
||||||
|
|
||||||
|
VirtualDeviceConnectInfo connectInfo = new VirtualDeviceConnectInfo();
|
||||||
|
connectInfo.setConnected(true);
|
||||||
|
connectInfo.setStartConnected(true);
|
||||||
|
disk.setConnectable(connectInfo);
|
||||||
|
|
||||||
|
return disk;
|
||||||
|
}
|
||||||
|
|
||||||
private static void setParentBackingInfo(VirtualDiskFlatVer2BackingInfo backingInfo,
|
private static void setParentBackingInfo(VirtualDiskFlatVer2BackingInfo backingInfo,
|
||||||
ManagedObjectReference morDs, String[] parentDatastorePathList) {
|
ManagedObjectReference morDs, String[] parentDatastorePathList) {
|
||||||
|
|
||||||
@ -264,6 +304,24 @@ public class VmwareHelper {
|
|||||||
backingInfo.setParent(parentBacking);
|
backingInfo.setParent(parentBacking);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void setParentBackingInfo(VirtualDiskFlatVer2BackingInfo backingInfo,
|
||||||
|
Pair<String, ManagedObjectReference>[] parentDatastorePathList) {
|
||||||
|
|
||||||
|
VirtualDiskFlatVer2BackingInfo parentBacking = new VirtualDiskFlatVer2BackingInfo();
|
||||||
|
parentBacking.setDatastore(parentDatastorePathList[0].second());
|
||||||
|
parentBacking.setDiskMode(VirtualDiskMode.persistent.toString());
|
||||||
|
|
||||||
|
if(parentDatastorePathList.length > 1) {
|
||||||
|
Pair<String, ManagedObjectReference>[] nextDatastorePathList = new Pair[parentDatastorePathList.length -1];
|
||||||
|
for(int i = 0; i < parentDatastorePathList.length -1; i++)
|
||||||
|
nextDatastorePathList[i] = parentDatastorePathList[i + 1];
|
||||||
|
setParentBackingInfo(parentBacking, nextDatastorePathList);
|
||||||
|
}
|
||||||
|
parentBacking.setFileName(parentDatastorePathList[0].first());
|
||||||
|
|
||||||
|
backingInfo.setParent(parentBacking);
|
||||||
|
}
|
||||||
|
|
||||||
public static Pair<VirtualDevice, Boolean> prepareIsoDevice(VirtualMachineMO vmMo, String isoDatastorePath, ManagedObjectReference morDs,
|
public static Pair<VirtualDevice, Boolean> prepareIsoDevice(VirtualMachineMO vmMo, String isoDatastorePath, ManagedObjectReference morDs,
|
||||||
boolean connect, boolean connectAtBoot, int deviceNumber, int contextNumber) throws Exception {
|
boolean connect, boolean connectAtBoot, int deviceNumber, int contextNumber) throws Exception {
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user