@Override
public VcTask cloneVmAsync(final CreateSpec vmSpec,
final DeviceId[] removeDisks) throws Exception {
final VcSnapshot parentVcSnap = vmSpec.getParentSnapshot();
final ConfigSpec configSpec =
(vmSpec.spec != null ? vmSpec.spec : new ConfigSpecImpl());
List<VirtualDeviceSpec> devChanges = new ArrayList<VirtualDeviceSpec>();
/*
* No device changes should be set already.
*/
if (configSpec.getDeviceChange() != null &&
configSpec.getDeviceChange().length > 0) {
AuAssert.INTERNAL();
return null;
}
/*
* Append config for removing disks.
*/
if (removeDisks != null) {
for (DeviceId deviceId : removeDisks) {
VirtualDevice dev = parentVcSnap.getVirtualDevice(deviceId);
if (dev != null) {
devChanges.add(VmConfigUtil.removeDeviceSpec(dev));
}
}
}
if (!devChanges.isEmpty()) {
configSpec.setDeviceChange(
devChanges.toArray(new VirtualDeviceSpec[devChanges.size()]));
}
return vmSpec.getParentVm().cloneSnapshot(vmSpec.name, vmSpec.rp, vmSpec.ds,
parentVcSnap, vmSpec.folder, vmSpec.host, vmSpec.linkClone, configSpec, VcCache.getRefreshVcTaskCB(vmSpec.rp));