use of com.vmware.vim25.VirtualMachineRelocateSpecDiskLocator in project photon-model by vmware.
the class InstanceClient method setProvisioningType.
private VirtualMachineRelocateSpecDiskLocator setProvisioningType(VirtualDisk vDisk, ManagedObjectReference datastore, List<VirtualMachineDefinedProfileSpec> pbmSpec) throws InvalidPropertyFaultMsg, FinderException, RuntimeFaultFaultMsg {
if (vDisk == null) {
return null;
}
// datastore from that.
if (datastore == null) {
ManagedObjectReference dsFromSp = getDatastoreFromStoragePolicy(this.connection, pbmSpec);
datastore = dsFromSp == null ? getDatastore() : dsFromSp;
}
VirtualDiskFlatVer2BackingInfo flatBacking = (VirtualDiskFlatVer2BackingInfo) vDisk.getBacking();
VirtualDiskType provisioningType = getDiskProvisioningType(this.bootDisk);
boolean wasThinProvision = flatBacking.isThinProvisioned();
Boolean wasEagerScrubbed = flatBacking.isEagerlyScrub() != null ? flatBacking.isEagerlyScrub() : false;
if (provisioningType != null) {
flatBacking.setThinProvisioned(provisioningType == VirtualDiskType.THIN);
flatBacking.setEagerlyScrub(provisioningType == VirtualDiskType.EAGER_ZEROED_THICK);
}
VirtualMachineRelocateSpecDiskLocator diskLocator = new VirtualMachineRelocateSpecDiskLocator();
diskLocator.setDiskId(vDisk.getKey());
diskLocator.setDiskBackingInfo(flatBacking);
diskLocator.setDatastore(datastore);
Boolean isEagerScrub = flatBacking.isEagerlyScrub() != null ? flatBacking.isEagerlyScrub() : false;
// to MOVE_ALL_DISK_BACKINGS_AND_DISALLOW_SHARING
if (wasThinProvision != flatBacking.isThinProvisioned() || !wasEagerScrubbed.equals(isEagerScrub)) {
diskLocator.setDiskMoveType(VirtualMachineRelocateDiskMoveOptions.MOVE_ALL_DISK_BACKINGS_AND_DISALLOW_SHARING.value());
}
return diskLocator;
}
use of com.vmware.vim25.VirtualMachineRelocateSpecDiskLocator in project cloudstack by apache.
the class VmwareResource method relocateVirtualMachine.
/*
* Method to relocate a virtual machine. This migrates VM and its volumes to given host, datastores.
* It is used for MigrateVolumeCommand (detached volume case), MigrateVmToPoolCommand and MigrateVmWithStorageCommand.
*/
private List<VolumeObjectTO> relocateVirtualMachine(final VmwareHypervisorHost hypervisorHost, final String name, final VirtualMachineTO vmTo, final String targetHost, final VmwareHypervisorHost hostInTargetCluster, final String poolUuid, final List<Pair<VolumeTO, StorageFilerTO>> volToFiler) throws Exception {
String vmName = name;
if (vmName == null && vmTo != null) {
vmName = vmTo.getName();
}
VmwareHypervisorHost sourceHyperHost = hypervisorHost;
VmwareHypervisorHost targetHyperHost = hostInTargetCluster;
VirtualMachineMO vmMo = null;
ManagedObjectReference morSourceHostDc = null;
VirtualMachineRelocateSpec relocateSpec = new VirtualMachineRelocateSpec();
List<VirtualMachineRelocateSpecDiskLocator> diskLocators = new ArrayList<VirtualMachineRelocateSpecDiskLocator>();
Set<String> mountedDatastoresAtSource = new HashSet<String>();
List<VolumeObjectTO> volumeToList = new ArrayList<>();
Map<Long, Integer> volumeDeviceKey = new HashMap<Long, Integer>();
try {
if (sourceHyperHost == null) {
sourceHyperHost = getHyperHost(getServiceContext());
}
if (targetHyperHost == null && StringUtils.isNotBlank(targetHost)) {
targetHyperHost = VmwareHelper.getHostMOFromHostName(getServiceContext(), targetHost);
}
morSourceHostDc = sourceHyperHost.getHyperHostDatacenter();
DatacenterMO dcMo = new DatacenterMO(sourceHyperHost.getContext(), morSourceHostDc);
if (targetHyperHost != null) {
ManagedObjectReference morTargetHostDc = targetHyperHost.getHyperHostDatacenter();
if (!morSourceHostDc.getValue().equalsIgnoreCase(morTargetHostDc.getValue())) {
String msg = String.format("VM: %s cannot be migrated between different datacenter", vmName);
throw new CloudRuntimeException(msg);
}
}
// find VM through source host (VM is not at the target host yet)
vmMo = sourceHyperHost.findVmOnHyperHost(vmName);
if (vmMo == null) {
String msg = String.format("VM: %s does not exist on host: %s", vmName, sourceHyperHost.getHyperHostName());
s_logger.warn(msg);
// find VM through source host (VM is not at the target host yet)
vmMo = dcMo.findVm(vmName);
if (vmMo == null) {
msg = String.format("VM: %s does not exist on datacenter: %s", vmName, dcMo.getName());
s_logger.error(msg);
throw new Exception(msg);
}
// VM host has changed
sourceHyperHost = vmMo.getRunningHost();
}
vmName = vmMo.getName();
String srcHostApiVersion = ((HostMO) sourceHyperHost).getHostAboutInfo().getApiVersion();
if (StringUtils.isNotBlank(poolUuid)) {
VmwareHypervisorHost dsHost = targetHyperHost == null ? sourceHyperHost : targetHyperHost;
ManagedObjectReference morDatastore = null;
morDatastore = getTargetDatastoreMOReference(poolUuid, dsHost);
if (morDatastore == null) {
String msg = String.format("Unable to find the target datastore: %s on host: %s to execute migration", poolUuid, dsHost.getHyperHostName());
s_logger.error(msg);
throw new CloudRuntimeException(msg);
}
relocateSpec.setDatastore(morDatastore);
} else if (CollectionUtils.isNotEmpty(volToFiler)) {
// Specify destination datastore location for each volume
VmwareHypervisorHost dsHost = targetHyperHost == null ? sourceHyperHost : targetHyperHost;
for (Pair<VolumeTO, StorageFilerTO> entry : volToFiler) {
VolumeTO volume = entry.first();
StorageFilerTO filerTo = entry.second();
if (s_logger.isDebugEnabled()) {
s_logger.debug(String.format("Preparing spec for volume: %s to migrate it to datastore: %s", volume.getName(), filerTo.getUuid()));
}
ManagedObjectReference morVolumeDatastore = getTargetDatastoreMOReference(filerTo.getUuid(), dsHost);
if (morVolumeDatastore == null) {
String msg = String.format("Unable to find the target datastore: %s in datacenter: %s to execute migration", filerTo.getUuid(), dcMo.getName());
s_logger.error(msg);
throw new CloudRuntimeException(msg);
}
String mountedDs = getMountedDatastoreName(sourceHyperHost, srcHostApiVersion, filerTo);
if (mountedDs != null) {
mountedDatastoresAtSource.add(mountedDs);
}
if (volume.getType() == Volume.Type.ROOT) {
relocateSpec.setDatastore(morVolumeDatastore);
}
VirtualMachineRelocateSpecDiskLocator diskLocator = new VirtualMachineRelocateSpecDiskLocator();
diskLocator.setDatastore(morVolumeDatastore);
Pair<VirtualDisk, String> diskInfo = getVirtualDiskInfo(vmMo, volume.getPath() + VMDK_EXTENSION);
String vmdkAbsFile = getAbsoluteVmdkFile(diskInfo.first());
if (vmdkAbsFile != null && !vmdkAbsFile.isEmpty()) {
vmMo.updateAdapterTypeIfRequired(vmdkAbsFile);
}
int diskId = diskInfo.first().getKey();
diskLocator.setDiskId(diskId);
diskLocators.add(diskLocator);
volumeDeviceKey.put(volume.getId(), diskId);
}
// If a target datastore is provided for the VM, then by default all volumes associated with the VM will be migrated to that target datastore.
// Hence set the existing datastore as target datastore for volumes that are not to be migrated.
List<Pair<Integer, ManagedObjectReference>> diskDatastores = vmMo.getAllDiskDatastores();
for (Pair<Integer, ManagedObjectReference> diskDatastore : diskDatastores) {
if (!volumeDeviceKey.containsValue(diskDatastore.first().intValue())) {
VirtualMachineRelocateSpecDiskLocator diskLocator = new VirtualMachineRelocateSpecDiskLocator();
diskLocator.setDiskId(diskDatastore.first().intValue());
diskLocator.setDatastore(diskDatastore.second());
diskLocators.add(diskLocator);
}
}
relocateSpec.getDisk().addAll(diskLocators);
}
// Specific section for MigrateVmWithStorageCommand
if (vmTo != null) {
// Prepare network at target before migration
NicTO[] nics = vmTo.getNics();
for (NicTO nic : nics) {
// prepare network on the host
prepareNetworkFromNicInfo((HostMO) targetHyperHost, nic, false, vmTo.getType());
}
// Ensure secondary storage mounted on target host
VmwareManager mgr = targetHyperHost.getContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
Pair<String, Long> secStoreUrlAndId = mgr.getSecondaryStorageStoreUrlAndId(Long.parseLong(_dcId));
String secStoreUrl = secStoreUrlAndId.first();
Long secStoreId = secStoreUrlAndId.second();
if (secStoreUrl == null) {
String msg = "secondary storage for dc " + _dcId + " is not ready yet?";
throw new Exception(msg);
}
mgr.prepareSecondaryStorageStore(secStoreUrl, secStoreId);
ManagedObjectReference morSecDs = prepareSecondaryDatastoreOnSpecificHost(secStoreUrl, targetHyperHost);
if (morSecDs == null) {
throw new Exception(String.format("Failed to prepare secondary storage on host, secondary store url: %s", secStoreUrl));
}
}
if (srcHostApiVersion.compareTo("5.1") < 0) {
// Migrate VM's volumes to target datastore(s).
if (!vmMo.changeDatastore(relocateSpec)) {
throw new Exception("Change datastore operation failed during storage migration");
} else {
s_logger.debug(String.format("Successfully migrated storage of VM: %s to target datastore(s)", vmName));
}
// Migrate VM to target host.
if (targetHyperHost != null) {
ManagedObjectReference morPool = targetHyperHost.getHyperHostOwnerResourcePool();
if (!vmMo.migrate(morPool, targetHyperHost.getMor())) {
throw new Exception("VM migration to target host failed during storage migration");
} else {
s_logger.debug(String.format("Successfully migrated VM: %s from host %s to %s", vmName, sourceHyperHost.getHyperHostName(), targetHyperHost.getHyperHostName()));
}
}
} else {
// Add target host to relocate spec
if (targetHyperHost != null) {
relocateSpec.setHost(targetHyperHost.getMor());
relocateSpec.setPool(targetHyperHost.getHyperHostOwnerResourcePool());
}
if (!vmMo.changeDatastore(relocateSpec)) {
throw new Exception("Change datastore operation failed during storage migration");
} else {
String msg = String.format("Successfully migrated VM: %s with its storage to target datastore(s)", vmName);
if (targetHyperHost != null) {
msg = String.format("%s from host %s to %s", msg, sourceHyperHost.getHyperHostName(), targetHyperHost.getHyperHostName());
}
s_logger.debug(msg);
}
}
// In case of a linked clone VM, if VM's disks are not consolidated, further VM operations such as volume snapshot, VM snapshot etc. will result in DB inconsistencies.
if (!vmMo.consolidateVmDisks()) {
s_logger.warn("VM disk consolidation failed after storage migration. Yet proceeding with VM migration.");
} else {
s_logger.debug(String.format("Successfully consolidated disks of VM: %s", vmName));
}
if (MapUtils.isNotEmpty(volumeDeviceKey)) {
// Update and return volume path and chain info for every disk because that could have changed after migration
VirtualMachineDiskInfoBuilder diskInfoBuilder = vmMo.getDiskInfoBuilder();
for (Pair<VolumeTO, StorageFilerTO> entry : volToFiler) {
final VolumeTO volume = entry.first();
final long volumeId = volume.getId();
VirtualDisk[] disks = vmMo.getAllDiskDevice();
for (VirtualDisk disk : disks) {
if (volumeDeviceKey.get(volumeId) == disk.getKey()) {
VolumeObjectTO newVol = new VolumeObjectTO();
newVol.setDataStoreUuid(entry.second().getUuid());
String newPath = vmMo.getVmdkFileBaseName(disk);
ManagedObjectReference morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(targetHyperHost != null ? targetHyperHost : sourceHyperHost, entry.second().getUuid());
DatastoreMO dsMo = new DatastoreMO(getServiceContext(), morDs);
VirtualMachineDiskInfo diskInfo = diskInfoBuilder.getDiskInfoByBackingFileBaseName(newPath, dsMo.getName());
newVol.setId(volumeId);
newVol.setPath(newPath);
newVol.setChainInfo(_gson.toJson(diskInfo));
volumeToList.add(newVol);
break;
}
}
}
}
} catch (Throwable e) {
if (e instanceof RemoteException) {
s_logger.warn("Encountered remote exception at vCenter, invalidating VMware session context");
invalidateServiceContext();
}
throw e;
} finally {
// Cleanup datastores mounted on source host
for (String mountedDatastore : mountedDatastoresAtSource) {
s_logger.debug("Attempting to unmount datastore " + mountedDatastore + " at " + sourceHyperHost.getHyperHostName());
try {
sourceHyperHost.unmountDatastore(mountedDatastore);
} catch (Exception unmountEx) {
s_logger.warn("Failed to unmount datastore " + mountedDatastore + " at " + sourceHyperHost.getHyperHostName() + ". Seems the datastore is still being used by " + sourceHyperHost.getHyperHostName() + ". Please unmount manually to cleanup.");
}
s_logger.debug("Successfully unmounted datastore " + mountedDatastore + " at " + sourceHyperHost.getHyperHostName());
}
}
// Only when volToFiler is not empty a filled list of VolumeObjectTO is returned else it will be empty
return volumeToList;
}
use of com.vmware.vim25.VirtualMachineRelocateSpecDiskLocator in project cloudstack by apache.
the class VirtualMachineMO method createLinkedClone.
public boolean createLinkedClone(String cloneName, ManagedObjectReference morBaseSnapshot, ManagedObjectReference morFolder, ManagedObjectReference morResourcePool, ManagedObjectReference morDs) throws Exception {
assert (morBaseSnapshot != null);
assert (morFolder != null);
assert (morResourcePool != null);
assert (morDs != null);
VirtualDisk[] independentDisks = getAllIndependentDiskDevice();
VirtualMachineRelocateSpec rSpec = new VirtualMachineRelocateSpec();
if (independentDisks.length > 0) {
List<VirtualMachineRelocateSpecDiskLocator> diskLocator = new ArrayList<VirtualMachineRelocateSpecDiskLocator>(independentDisks.length);
for (int i = 0; i < independentDisks.length; i++) {
VirtualMachineRelocateSpecDiskLocator loc = new VirtualMachineRelocateSpecDiskLocator();
loc.setDatastore(morDs);
loc.setDiskId(independentDisks[i].getKey());
loc.setDiskMoveType(VirtualMachineRelocateDiskMoveOptions.MOVE_ALL_DISK_BACKINGS_AND_DISALLOW_SHARING.value());
diskLocator.add(loc);
}
rSpec.setDiskMoveType(VirtualMachineRelocateDiskMoveOptions.CREATE_NEW_CHILD_DISK_BACKING.value());
rSpec.getDisk().addAll(diskLocator);
} else {
rSpec.setDiskMoveType(VirtualMachineRelocateDiskMoveOptions.CREATE_NEW_CHILD_DISK_BACKING.value());
}
rSpec.setPool(morResourcePool);
VirtualMachineCloneSpec cloneSpec = new VirtualMachineCloneSpec();
cloneSpec.setPowerOn(false);
cloneSpec.setTemplate(false);
cloneSpec.setLocation(rSpec);
cloneSpec.setSnapshot(morBaseSnapshot);
ManagedObjectReference morTask = _context.getService().cloneVMTask(_mor, morFolder, cloneName, cloneSpec);
boolean result = _context.getVimClient().waitForTask(morTask);
if (result) {
_context.waitForTaskProgressDone(morTask);
return true;
} else {
s_logger.error("VMware cloneVM_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
return false;
}
use of com.vmware.vim25.VirtualMachineRelocateSpecDiskLocator in project CloudStack-archive by CloudStack-extras.
the class VirtualMachineMO method createLinkedClone.
public boolean createLinkedClone(String cloneName, ManagedObjectReference morBaseSnapshot, ManagedObjectReference morFolder, ManagedObjectReference morResourcePool, ManagedObjectReference morDs) throws Exception {
assert (morBaseSnapshot != null);
assert (morFolder != null);
assert (morResourcePool != null);
assert (morDs != null);
VirtualDisk[] independentDisks = getAllIndependentDiskDevice();
VirtualMachineRelocateSpec rSpec = new VirtualMachineRelocateSpec();
if (independentDisks.length > 0) {
VirtualMachineRelocateSpecDiskLocator[] diskLocator = new VirtualMachineRelocateSpecDiskLocator[independentDisks.length];
for (int i = 0; i < diskLocator.length; i++) {
diskLocator[i] = new VirtualMachineRelocateSpecDiskLocator();
diskLocator[i].setDatastore(morDs);
diskLocator[i].setDiskId(independentDisks[i].getKey());
diskLocator[i].setDiskMoveType(VirtualMachineRelocateDiskMoveOptions._moveAllDiskBackingsAndDisallowSharing);
}
rSpec.setDiskMoveType(VirtualMachineRelocateDiskMoveOptions._createNewChildDiskBacking);
rSpec.setDisk(diskLocator);
} else {
rSpec.setDiskMoveType(VirtualMachineRelocateDiskMoveOptions._createNewChildDiskBacking);
}
rSpec.setPool(morResourcePool);
VirtualMachineCloneSpec cloneSpec = new VirtualMachineCloneSpec();
cloneSpec.setPowerOn(false);
cloneSpec.setTemplate(false);
cloneSpec.setLocation(rSpec);
cloneSpec.setSnapshot(morBaseSnapshot);
ManagedObjectReference morTask = _context.getService().cloneVM_Task(_mor, morFolder, cloneName, cloneSpec);
String result = _context.getServiceUtil().waitForTask(morTask);
if (result.equals("sucess")) {
_context.waitForTaskProgressDone(morTask);
return true;
} else {
s_logger.error("VMware cloneVM_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
return false;
}
use of com.vmware.vim25.VirtualMachineRelocateSpecDiskLocator in project photon-model by vmware.
the class InstanceClient method cloneOvfBasedTemplate.
private ManagedObjectReference cloneOvfBasedTemplate(ManagedObjectReference vmTempl, ManagedObjectReference datastore, ManagedObjectReference folder, ManagedObjectReference resourcePool, List<VirtualMachineDefinedProfileSpec> pbmSpec) throws Exception {
String vmName = this.ctx.child.name;
Map<String, Object> props = this.get.entityProps(vmTempl, VimPath.vm_summary_config_numCpu, VimPath.vm_summary_config_memorySizeMB, VimPath.vm_snapshot, VimPath.vm_config_hardware_device, VimPath.vm_config_vAppConfig_property);
VirtualMachineSnapshotInfo snapshot = (VirtualMachineSnapshotInfo) props.get(VimPath.vm_snapshot);
ArrayOfVirtualDevice devices = (ArrayOfVirtualDevice) props.get(VimPath.vm_config_hardware_device);
VirtualDisk vd = devices.getVirtualDevice().stream().filter(d -> d instanceof VirtualDisk).map(d -> (VirtualDisk) d).findFirst().orElse(null);
VirtualSCSIController scsiController = getFirstScsiController(devices);
Integer[] scsiUnit = findFreeScsiUnit(scsiController, devices.getVirtualDevice());
VirtualMachineRelocateDiskMoveOptions diskMoveOption = computeDiskMoveType();
boolean customizeImageDisk = false;
List<VirtualDeviceConfigSpec> newDisks = new ArrayList<>();
VirtualMachineRelocateSpecDiskLocator bootDiskLocator = null;
List<VirtualDisk> vDisks = null;
if (this.bootDisk != null) {
if (vd == null) {
String datastoreName = this.get.entityProp(datastore, VimPath.ds_summary_name);
String path = makePathToVmdkFile("ephemeral_disk", vmName);
String diskName = String.format(VM_PATH_FORMAT, datastoreName, path);
VirtualDeviceConfigSpec hdd = createHdd(scsiController.getKey(), scsiUnit[0], this.bootDisk, diskName, datastore, pbmSpec);
newDisks.add(hdd);
} else {
// strategy
if (this.imageDisks != null && !this.imageDisks.isEmpty()) {
vDisks = devices.getVirtualDevice().stream().filter(d -> d instanceof VirtualDisk).map(d -> (VirtualDisk) d).filter(d -> {
DiskStateExpanded ds = findMatchingImageDiskState(d, this.imageDisks);
return toKb(ds.capacityMBytes) > d.getCapacityInKB() || ds.customProperties != null;
}).collect(Collectors.toList());
if (vDisks.size() > 0) {
diskMoveOption = VirtualMachineRelocateDiskMoveOptions.MOVE_ALL_DISK_BACKINGS_AND_DISALLOW_SHARING;
logger.warn("Changing clone strategy to MOVE_ALL_DISK_BACKINGS_AND_DISALLOW_SHARING, as there is disk resize requested");
customizeImageDisk = true;
bootDiskLocator = setProvisioningType(vDisks.get(0), datastore, pbmSpec);
}
}
}
}
VirtualCdrom vcd = devices.getVirtualDevice().stream().filter(d -> d instanceof VirtualCdrom).map(d -> (VirtualCdrom) d).findFirst().orElse(null);
// add a cdrom so that ovf transport works
if (vcd == null) {
VirtualDevice ideController = getFirstIdeController(devices);
int ideUnit = findFreeUnit(ideController, devices.getVirtualDevice());
VirtualDeviceConfigSpec cdrom = createCdrom(ideController, ideUnit);
newDisks.add(cdrom);
} else {
VirtualDeviceConfigSpec cdrom = reconfigureCdrom(vcd);
newDisks.add(cdrom);
}
VirtualMachineConfigSpec spec = new VirtualMachineConfigSpec();
// even though this is a clone, hw config from the compute resource
// is takes precedence
spec.setNumCPUs((int) this.ctx.child.description.cpuCount);
spec.setMemoryMB(toMemoryMb(this.ctx.child.description.totalMemoryBytes));
String gt = CustomProperties.of(this.ctx.child).getString(CustomProperties.GUEST_ID, null);
if (gt != null) {
spec.setGuestId(gt);
}
// set ovf environment
ArrayOfVAppPropertyInfo infos = (ArrayOfVAppPropertyInfo) props.get(// this.get.entityProp(vmTempl,
VimPath.vm_config_vAppConfig_property);
// VimPath.vm_config_vAppConfig_property);
populateVAppProperties(spec, infos);
populateCloudConfig(spec, infos);
recordTimestamp(spec.getExtraConfig());
// set the maximum snapshot limit if specified
final String snapshotLimit = CustomProperties.of(this.ctx.child).getString(CustomProperties.SNAPSHOT_MAXIMUM_LIMIT);
recordSnapshotLimit(spec.getExtraConfig(), snapshotLimit);
// add disks one at a time
for (VirtualDeviceConfigSpec newDisk : newDisks) {
spec.getDeviceChange().add(newDisk);
}
// configure network
VirtualPCIController pci = getFirstPciController(devices);
for (NetworkInterfaceStateWithDetails nicWithDetails : this.ctx.nics) {
VirtualDevice nic = createNic(nicWithDetails, pci.getControllerKey());
addDeviceToVm(spec, nic);
}
// remove any networks from the template
devices.getVirtualDevice().stream().filter(d -> VirtualEthernetCard.class.isAssignableFrom(d.getClass())).forEach(d -> addRemoveDeviceFromVm(spec, d));
VirtualMachineRelocateSpec relocSpec = new VirtualMachineRelocateSpec();
if (pbmSpec != null) {
pbmSpec.stream().forEach(sp -> {
relocSpec.getProfile().add(sp);
});
}
relocSpec.setDatastore(datastore);
relocSpec.setFolder(folder);
relocSpec.setPool(resourcePool);
relocSpec.setDiskMoveType(diskMoveOption.value());
VirtualMachineCloneSpec cloneSpec = new VirtualMachineCloneSpec();
cloneSpec.setLocation(relocSpec);
cloneSpec.setPowerOn(false);
cloneSpec.setTemplate(false);
if (snapshot != null) {
cloneSpec.setSnapshot(snapshot.getCurrentSnapshot());
}
cloneSpec.setConfig(spec);
if (bootDiskLocator != null) {
cloneSpec.getLocation().getDisk().add(bootDiskLocator);
}
ManagedObjectReference cloneTask = getVimPort().cloneVMTask(vmTempl, folder, vmName, cloneSpec);
TaskInfo info = waitTaskEnd(cloneTask);
if (info.getState() == TaskInfoState.ERROR) {
return VimUtils.rethrow(info.getError());
}
ManagedObjectReference vmMoref = (ManagedObjectReference) info.getResult();
// Apply boot disk customization if any, if done through full clone.
if (customizeImageDisk) {
ArrayOfVirtualDevice virtualDevices = this.get.entityProp(vmMoref, VimPath.vm_config_hardware_device);
reconfigureBootDisk(vmMoref, getCustomizationConfigSpecs(virtualDevices, this.imageDisks));
}
return vmMoref;
}
Aggregations