Search in sources :

Example 6 with VirtualDiskType

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;
}
Also used : TaskInfo(com.vmware.vim25.TaskInfo) VirtualDiskFlatVer2BackingInfo(com.vmware.vim25.VirtualDiskFlatVer2BackingInfo) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) VirtualDiskType(com.vmware.vim25.VirtualDiskType) VirtualDiskSpec(com.vmware.vim25.VirtualDiskSpec) VirtualDisk(com.vmware.vim25.VirtualDisk) ClientUtils.getListOfVirtualDisk(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getListOfVirtualDisk) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 7 with VirtualDiskType

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;
}
Also used : VirtualDiskFlatVer2BackingInfo(com.vmware.vim25.VirtualDiskFlatVer2BackingInfo) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) VirtualDiskType(com.vmware.vim25.VirtualDiskType) VirtualDisk(com.vmware.vim25.VirtualDisk)

Example 8 with VirtualDiskType

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.
    }
}
Also used : VirtualDiskFlatVer1BackingInfo(com.vmware.vim25.VirtualDiskFlatVer1BackingInfo) VirtualDiskFlatVer2BackingInfo(com.vmware.vim25.VirtualDiskFlatVer2BackingInfo) VirtualDiskType(com.vmware.vim25.VirtualDiskType) FinderException(com.vmware.photon.controller.model.adapters.vsphere.util.finders.FinderException) KeyManagementException(java.security.KeyManagementException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) URISyntaxException(java.net.URISyntaxException)

Example 9 with VirtualDiskType

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;
}
Also used : VirtualDiskType(com.vmware.vim25.VirtualDiskType) FileBackedVirtualDiskSpec(com.vmware.vim25.FileBackedVirtualDiskSpec)

Example 10 with VirtualDiskType

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)");
}
Also used : VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) VirtualDiskFlatVer2BackingInfo(com.vmware.vim25.VirtualDiskFlatVer2BackingInfo) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) VirtualMachineDefinedProfileSpec(com.vmware.vim25.VirtualMachineDefinedProfileSpec) VirtualDiskRawDiskMappingVer1BackingInfo(com.vmware.vim25.VirtualDiskRawDiskMappingVer1BackingInfo) VirtualDisk(com.vmware.vim25.VirtualDisk) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Aggregations

VirtualDiskFlatVer2BackingInfo (com.vmware.vim25.VirtualDiskFlatVer2BackingInfo)8 VirtualDiskType (com.vmware.vim25.VirtualDiskType)7 VirtualDisk (com.vmware.vim25.VirtualDisk)6 ArrayOfManagedObjectReference (com.vmware.vim25.ArrayOfManagedObjectReference)5 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)5 VirtualDeviceConfigSpec (com.vmware.vim25.VirtualDeviceConfigSpec)5 VirtualDiskRawDiskMappingVer1BackingInfo (com.vmware.vim25.VirtualDiskRawDiskMappingVer1BackingInfo)3 VirtualMachineConfigSpec (com.vmware.vim25.VirtualMachineConfigSpec)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 ClientUtils.getListOfVirtualDisk (com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getListOfVirtualDisk)1 ImportOvfRequest (com.vmware.photon.controller.model.adapters.vsphere.ovf.ImportOvfRequest)1 BasicConnection (com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection)1 GetMoRef (com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef)1 FinderException (com.vmware.photon.controller.model.adapters.vsphere.util.finders.FinderException)1 ComputeDescriptionService (com.vmware.photon.controller.model.resources.ComputeDescriptionService)1 ComputeService (com.vmware.photon.controller.model.resources.ComputeService)1 DiskService (com.vmware.photon.controller.model.resources.DiskService)1 ProvisionComputeTaskService (com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService)1 FileBackedVirtualDiskSpec (com.vmware.vim25.FileBackedVirtualDiskSpec)1 TaskInfo (com.vmware.vim25.TaskInfo)1