public void copyVirtualDisk(String srcName, ManagedObjectReference morSrcDc, String destName, ManagedObjectReference morDestDc, VirtualDiskSpec diskSpec, boolean force) throws Exception { ManagedObjectReference morTask = _context.getService().copyVirtualDiskTask(_mor, srcName, morSrcDc, destName, morDestDc, diskSpec, force); boolean result = _context.getVimClient().waitForTask(morTask); if (!result) throw new Exception("Unable to copy virtual disk " + srcName + " to " + destName + " due to " + TaskMO.getTaskFailureInfo(_context, morTask)); _context.waitForTaskProgressDone(morTask); }
public void createVirtualDisk(String name, ManagedObjectReference morDc, VirtualDiskSpec diskSpec) throws Exception { ManagedObjectReference morTask = _context.getService().createVirtualDiskTask(_mor, name, morDc, diskSpec); boolean result = _context.getVimClient().waitForTask(morTask); if (!result) throw new Exception("Unable to create virtual disk " + name + " due to " + TaskMO.getTaskFailureInfo(_context, morTask)); _context.waitForTaskProgressDone(morTask); }
Task copyVirtualDiskTask(String sourceName, Datacenter sourceDatacenter, String destName, Datacenter destDatacenter, VirtualDiskSpec destSpec, Boolean force) throws FileFault, RuntimeFault, RemoteException;
private VirtualDeviceConfigSpec createFullCloneAndAttach(String sourcePath, DiskStateExpanded ds, String dir, VirtualDevice scsiController, int unitNumber, List<VirtualMachineDefinedProfileSpec> pbmSpec) throws Exception { ManagedObjectReference diskManager = this.connection.getServiceContent() .getVirtualDiskManager(); String dsDirForDisk = getDatastorePathForDisk(ds, dir); // put full clone in the vm folder String destName = makePathToVmdkFile(ds.name, dsDirForDisk); // all ops are within a datacenter ManagedObjectReference sourceDc = this.ctx.datacenterMoRef; ManagedObjectReference destDc = sourceDc; Boolean force = true; // spec is not supported, should use null for now VirtualDiskSpec spec = null; ManagedObjectReference task = getVimPort() .copyVirtualDiskTask(diskManager, sourcePath, sourceDc, destName, destDc, spec, force); // wait for the disk to be copied TaskInfo taskInfo = waitTaskEnd(task); if (taskInfo.getState() == TaskInfoState.ERROR) { return VimUtils.rethrow(taskInfo.getError()); } VirtualDiskFlatVer2BackingInfo backing = new VirtualDiskFlatVer2BackingInfo(); backing.setDiskMode(getDiskMode(ds)); VirtualDiskType provisionType = getDiskProvisioningType(ds); if (provisionType != null) { backing.setThinProvisioned(provisionType == VirtualDiskType.THIN); backing.setEagerlyScrub(provisionType == VirtualDiskType.EAGER_ZEROED_THICK); } backing.setFileName(destName); backing.setDatastore(getDataStoreForDisk(ds, pbmSpec)); VirtualDisk disk = new VirtualDisk(); disk.setBacking(backing); disk.setStorageIOAllocation(getStorageIOAllocationInfo(ds)); disk.setControllerKey(scsiController.getKey()); disk.setUnitNumber(unitNumber); fillInControllerUnitNumber(ds, unitNumber); disk.setKey(-1); VirtualDeviceConfigSpec change = new VirtualDeviceConfigSpec(); change.setDevice(disk); // Add storage policy spec if (pbmSpec != null) { pbmSpec.stream().forEach(sp -> { change.getProfile().add(sp); }); } change.setOperation(VirtualDeviceConfigSpecOperation.ADD); return change; }
Task createVirtualDiskTask(String name, Datacenter datacenter, VirtualDiskSpec spec) throws FileFault, RuntimeFault, RemoteException;