use of com.vmware.vim25.VirtualDiskType in project photon-model by vmware.
the class InstanceClient method createFullCloneAndAttach.
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;
}
use of com.vmware.vim25.VirtualDiskType in project photon-model by vmware.
the class ClientUtils method createHdd.
/**
* Creates HDD virtual disk
*/
public static VirtualDeviceConfigSpec createHdd(Integer controllerKey, int unitNumber, DiskService.DiskStateExpanded ds, String diskName, ManagedObjectReference datastore, List<VirtualMachineDefinedProfileSpec> pbmSpec, boolean isCreateFile) throws FinderException, InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
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(diskName);
backing.setDatastore(datastore);
VirtualDisk disk = new VirtualDisk();
disk.setCapacityInKB(toKb(ds.capacityMBytes));
disk.setBacking(backing);
disk.setStorageIOAllocation(getStorageIOAllocationInfo(ds));
disk.setControllerKey(controllerKey);
disk.setUnitNumber(unitNumber);
fillInControllerUnitNumber(ds, unitNumber);
disk.setKey(-1);
VirtualDeviceConfigSpec change = new VirtualDeviceConfigSpec();
change.setDevice(disk);
if (pbmSpec != null) {
// Add storage policy spec
pbmSpec.stream().forEach(sp -> {
change.getProfile().add(sp);
});
}
change.setOperation(VirtualDeviceConfigSpecOperation.ADD);
if (isCreateFile) {
change.setFileOperation(VirtualDeviceConfigSpecFileOperation.CREATE);
}
return change;
}
use of com.vmware.vim25.VirtualDiskType in project photon-model by vmware.
the class ClientUtils method updateDiskStateFromBackingInfo.
private static void updateDiskStateFromBackingInfo(VirtualDeviceFileBackingInfo backing, DiskService.DiskState ds) {
try {
if (backing instanceof VirtualDiskFlatVer1BackingInfo) {
VirtualDiskFlatVer1BackingInfo flatVer1 = (VirtualDiskFlatVer1BackingInfo) backing;
updateDiskModeInDiskState(VirtualDiskMode.fromValue(flatVer1.getDiskMode()), ds);
} else if (backing instanceof VirtualDiskFlatVer2BackingInfo) {
VirtualDiskFlatVer2BackingInfo flatVer2 = (VirtualDiskFlatVer2BackingInfo) backing;
updateDiskModeInDiskState(VirtualDiskMode.fromValue(flatVer2.getDiskMode()), ds);
// Update the provisioning type as well.
VirtualDiskType diskType = VirtualDiskType.THICK;
if (flatVer2.isThinProvisioned()) {
diskType = VirtualDiskType.THIN;
} else if (flatVer2.isEagerlyScrub()) {
diskType = VirtualDiskType.EAGER_ZEROED_THICK;
}
CustomProperties.of(ds).put(PROVISION_TYPE, diskType.value());
}
} catch (Exception e) {
// any exception ignore it. it won't update the properties in the disk.
}
}
use of com.vmware.vim25.VirtualDiskType in project photon-model by vmware.
the class DiskClient method createVirtualDiskSpec.
/**
* Create virtual disk spec for creating the virtual disk
*/
private FileBackedVirtualDiskSpec createVirtualDiskSpec(DiskStateExpanded diskStateExpanded, List<VirtualMachineDefinedProfileSpec> pbmSpec) {
if (diskStateExpanded.capacityMBytes <= 0) {
throw new IllegalArgumentException("Capacity of disk should be greater than 0");
}
if (diskStateExpanded.name == null || diskStateExpanded.name.isEmpty()) {
throw new IllegalArgumentException("Disk name should not be empty");
}
FileBackedVirtualDiskSpec diskSpec = new FileBackedVirtualDiskSpec();
diskSpec.setCapacityKb(toKb(diskStateExpanded.capacityMBytes));
VirtualDiskType provisionType = getDiskProvisioningType(diskStateExpanded);
if (provisionType != null) {
diskSpec.setDiskType(provisionType.value());
} else {
// Default it to THIN
diskSpec.setDiskType(VirtualDiskType.THIN.value());
}
diskSpec.setAdapterType(VirtualDiskAdapterType.LSI_LOGIC.value());
if (pbmSpec != null) {
diskSpec.getProfile().addAll(pbmSpec);
}
return diskSpec;
}
use of com.vmware.vim25.VirtualDiskType in project cloudstack by apache.
the class VirtualMachineMO method createDisk.
// vmdkDatastorePath: [datastore name] vmdkFilePath
public void createDisk(String vmdkDatastorePath, VirtualDiskType diskType, VirtualDiskMode diskMode, String rdmDeviceName, long sizeInMb, ManagedObjectReference morDs, int controllerKey, String vSphereStoragePolicyId) throws Exception {
if (s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - createDisk(). target MOR: " + _mor.getValue() + ", vmdkDatastorePath: " + vmdkDatastorePath + ", sizeInMb: " + sizeInMb + ", diskType: " + diskType + ", diskMode: " + diskMode + ", rdmDeviceName: " + rdmDeviceName + ", datastore: " + morDs.getValue() + ", controllerKey: " + controllerKey);
assert (vmdkDatastorePath != null);
assert (morDs != null);
int ideControllerKey = getIDEDeviceControllerKey();
if (controllerKey < 0) {
controllerKey = ideControllerKey;
}
VirtualDisk newDisk = new VirtualDisk();
if (diskType == VirtualDiskType.THIN || diskType == VirtualDiskType.PREALLOCATED || diskType == VirtualDiskType.EAGER_ZEROED_THICK) {
VirtualDiskFlatVer2BackingInfo backingInfo = new VirtualDiskFlatVer2BackingInfo();
backingInfo.setDiskMode(VirtualDiskMode.PERSISTENT.value());
if (diskType == VirtualDiskType.THIN) {
backingInfo.setThinProvisioned(true);
} else {
backingInfo.setThinProvisioned(false);
}
if (diskType == VirtualDiskType.EAGER_ZEROED_THICK) {
backingInfo.setEagerlyScrub(true);
} else {
backingInfo.setEagerlyScrub(false);
}
backingInfo.setDatastore(morDs);
backingInfo.setFileName(vmdkDatastorePath);
newDisk.setBacking(backingInfo);
} else if (diskType == VirtualDiskType.RDM || diskType == VirtualDiskType.RDMP) {
VirtualDiskRawDiskMappingVer1BackingInfo backingInfo = new VirtualDiskRawDiskMappingVer1BackingInfo();
if (diskType == VirtualDiskType.RDM) {
backingInfo.setCompatibilityMode("virtualMode");
} else {
backingInfo.setCompatibilityMode("physicalMode");
}
backingInfo.setDeviceName(rdmDeviceName);
if (diskType == VirtualDiskType.RDM) {
backingInfo.setDiskMode(VirtualDiskMode.PERSISTENT.value());
}
backingInfo.setDatastore(morDs);
backingInfo.setFileName(vmdkDatastorePath);
newDisk.setBacking(backingInfo);
}
int deviceNumber = getNextDeviceNumber(controllerKey);
newDisk.setControllerKey(controllerKey);
newDisk.setKey(-deviceNumber);
newDisk.setUnitNumber(deviceNumber);
newDisk.setCapacityInKB(sizeInMb * 1024);
VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec();
VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
deviceConfigSpec.setDevice(newDisk);
deviceConfigSpec.setFileOperation(VirtualDeviceConfigSpecFileOperation.CREATE);
deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);
if (StringUtils.isNotEmpty(vSphereStoragePolicyId)) {
PbmProfileManagerMO profMgrMo = new PbmProfileManagerMO(getContext());
VirtualMachineDefinedProfileSpec diskProfileSpec = profMgrMo.getProfileSpec(vSphereStoragePolicyId);
deviceConfigSpec.getProfile().add(diskProfileSpec);
if (s_logger.isDebugEnabled()) {
s_logger.debug(String.format("Adding vSphere storage profile: %s to volume [%s]", vSphereStoragePolicyId, vmdkDatastorePath));
}
}
reConfigSpec.getDeviceChange().add(deviceConfigSpec);
ManagedObjectReference morTask = _context.getService().reconfigVMTask(_mor, reConfigSpec);
boolean result = _context.getVimClient().waitForTask(morTask);
if (!result) {
if (s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - createDisk() done(failed)");
throw new Exception("Unable to create disk " + vmdkDatastorePath + " due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
_context.waitForTaskProgressDone(morTask);
if (s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - createDisk() done(successfully)");
}
Aggregations