Search in sources :

Example 26 with VirtualDiskFlatVer2BackingInfo

use of com.vmware.vim25.VirtualDiskFlatVer2BackingInfo in project cloudstack by apache.

the class VmwareHelper method prepareDiskDevice.

// vmdkDatastorePath: [datastore name] vmdkFilePath, create delta disk based on disk from template
public static VirtualDevice prepareDiskDevice(VirtualMachineMO vmMo, int controllerKey, String vmdkDatastorePath, int sizeInMb, ManagedObjectReference morDs, VirtualDisk templateDisk, int deviceNumber, int contextNumber) throws Exception {
    assert (templateDisk != null);
    VirtualDeviceBackingInfo parentBacking = templateDisk.getBacking();
    assert (parentBacking != null);
    // TODO Not sure if we need to check if the disk in template and the new disk needs to share the
    // same datastore
    VirtualDisk disk = new VirtualDisk();
    if (parentBacking instanceof VirtualDiskFlatVer1BackingInfo) {
        VirtualDiskFlatVer1BackingInfo backingInfo = new VirtualDiskFlatVer1BackingInfo();
        backingInfo.setDiskMode(((VirtualDiskFlatVer1BackingInfo) parentBacking).getDiskMode());
        backingInfo.setDatastore(morDs);
        backingInfo.setFileName(vmdkDatastorePath);
        backingInfo.setParent((VirtualDiskFlatVer1BackingInfo) parentBacking);
        disk.setBacking(backingInfo);
    } else if (parentBacking instanceof VirtualDiskFlatVer2BackingInfo) {
        VirtualDiskFlatVer2BackingInfo backingInfo = new VirtualDiskFlatVer2BackingInfo();
        backingInfo.setDiskMode(((VirtualDiskFlatVer2BackingInfo) parentBacking).getDiskMode());
        backingInfo.setDatastore(morDs);
        backingInfo.setFileName(vmdkDatastorePath);
        backingInfo.setParent((VirtualDiskFlatVer2BackingInfo) parentBacking);
        disk.setBacking(backingInfo);
    } else if (parentBacking instanceof VirtualDiskRawDiskMappingVer1BackingInfo) {
        VirtualDiskRawDiskMappingVer1BackingInfo backingInfo = new VirtualDiskRawDiskMappingVer1BackingInfo();
        backingInfo.setDiskMode(((VirtualDiskRawDiskMappingVer1BackingInfo) parentBacking).getDiskMode());
        backingInfo.setDatastore(morDs);
        backingInfo.setFileName(vmdkDatastorePath);
        backingInfo.setParent((VirtualDiskRawDiskMappingVer1BackingInfo) parentBacking);
        disk.setBacking(backingInfo);
    } else if (parentBacking instanceof VirtualDiskSparseVer1BackingInfo) {
        VirtualDiskSparseVer1BackingInfo backingInfo = new VirtualDiskSparseVer1BackingInfo();
        backingInfo.setDiskMode(((VirtualDiskSparseVer1BackingInfo) parentBacking).getDiskMode());
        backingInfo.setDatastore(morDs);
        backingInfo.setFileName(vmdkDatastorePath);
        backingInfo.setParent((VirtualDiskSparseVer1BackingInfo) parentBacking);
        disk.setBacking(backingInfo);
    } else if (parentBacking instanceof VirtualDiskSparseVer2BackingInfo) {
        VirtualDiskSparseVer2BackingInfo backingInfo = new VirtualDiskSparseVer2BackingInfo();
        backingInfo.setDiskMode(((VirtualDiskSparseVer2BackingInfo) parentBacking).getDiskMode());
        backingInfo.setDatastore(morDs);
        backingInfo.setFileName(vmdkDatastorePath);
        backingInfo.setParent((VirtualDiskSparseVer2BackingInfo) parentBacking);
        disk.setBacking(backingInfo);
    } else {
        throw new Exception("Unsupported disk backing: " + parentBacking.getClass().getCanonicalName());
    }
    int ideControllerKey = vmMo.getIDEDeviceControllerKey();
    if (controllerKey < 0)
        controllerKey = ideControllerKey;
    disk.setControllerKey(controllerKey);
    if (deviceNumber < 0) {
        deviceNumber = vmMo.getNextDeviceNumber(controllerKey);
    }
    disk.setKey(-contextNumber);
    disk.setUnitNumber(deviceNumber);
    disk.setCapacityInKB(sizeInMb * 1024);
    VirtualDeviceConnectInfo connectInfo = new VirtualDeviceConnectInfo();
    connectInfo.setConnected(true);
    connectInfo.setStartConnected(true);
    disk.setConnectable(connectInfo);
    return disk;
}
Also used : VirtualDiskSparseVer2BackingInfo(com.vmware.vim25.VirtualDiskSparseVer2BackingInfo) VirtualDiskFlatVer1BackingInfo(com.vmware.vim25.VirtualDiskFlatVer1BackingInfo) VirtualDiskSparseVer1BackingInfo(com.vmware.vim25.VirtualDiskSparseVer1BackingInfo) VirtualDiskFlatVer2BackingInfo(com.vmware.vim25.VirtualDiskFlatVer2BackingInfo) VirtualDeviceBackingInfo(com.vmware.vim25.VirtualDeviceBackingInfo) VirtualDiskRawDiskMappingVer1BackingInfo(com.vmware.vim25.VirtualDiskRawDiskMappingVer1BackingInfo) VirtualDeviceConnectInfo(com.vmware.vim25.VirtualDeviceConnectInfo) VirtualDisk(com.vmware.vim25.VirtualDisk) IOException(java.io.IOException)

Example 27 with VirtualDiskFlatVer2BackingInfo

use of com.vmware.vim25.VirtualDiskFlatVer2BackingInfo in project cloudstack by apache.

the class VmwareHelper method prepareDiskDevice.

@SuppressWarnings("unchecked")
public static VirtualDevice prepareDiskDevice(VirtualMachineMO vmMo, int controllerKey, Pair<String, ManagedObjectReference>[] vmdkDatastorePathChain, int deviceNumber, int contextNumber) throws Exception {
    assert (vmdkDatastorePathChain != null);
    assert (vmdkDatastorePathChain.length >= 1);
    VirtualDisk disk = new VirtualDisk();
    VirtualDiskFlatVer2BackingInfo backingInfo = new VirtualDiskFlatVer2BackingInfo();
    backingInfo.setDatastore(vmdkDatastorePathChain[0].second());
    backingInfo.setFileName(vmdkDatastorePathChain[0].first());
    backingInfo.setDiskMode(VirtualDiskMode.PERSISTENT.value());
    if (vmdkDatastorePathChain.length > 1) {
        Pair<String, ManagedObjectReference>[] parentDisks = new Pair[vmdkDatastorePathChain.length - 1];
        for (int i = 0; i < vmdkDatastorePathChain.length - 1; i++) parentDisks[i] = vmdkDatastorePathChain[i + 1];
        setParentBackingInfo(backingInfo, parentDisks);
    }
    disk.setBacking(backingInfo);
    int ideControllerKey = vmMo.getIDEDeviceControllerKey();
    if (controllerKey < 0)
        controllerKey = ideControllerKey;
    if (deviceNumber < 0) {
        deviceNumber = vmMo.getNextDeviceNumber(controllerKey);
    }
    disk.setControllerKey(controllerKey);
    disk.setKey(-contextNumber);
    disk.setUnitNumber(deviceNumber);
    VirtualDeviceConnectInfo connectInfo = new VirtualDeviceConnectInfo();
    connectInfo.setConnected(true);
    connectInfo.setStartConnected(true);
    disk.setConnectable(connectInfo);
    return disk;
}
Also used : VirtualDiskFlatVer2BackingInfo(com.vmware.vim25.VirtualDiskFlatVer2BackingInfo) VirtualDeviceConnectInfo(com.vmware.vim25.VirtualDeviceConnectInfo) VirtualDisk(com.vmware.vim25.VirtualDisk) Pair(com.cloud.utils.Pair)

Example 28 with VirtualDiskFlatVer2BackingInfo

use of com.vmware.vim25.VirtualDiskFlatVer2BackingInfo in project cloudstack by apache.

the class VmwareHelper method setParentBackingInfo.

@SuppressWarnings("unchecked")
private static void setParentBackingInfo(VirtualDiskFlatVer2BackingInfo backingInfo, Pair<String, ManagedObjectReference>[] parentDatastorePathList) {
    VirtualDiskFlatVer2BackingInfo parentBacking = new VirtualDiskFlatVer2BackingInfo();
    parentBacking.setDatastore(parentDatastorePathList[0].second());
    parentBacking.setDiskMode(VirtualDiskMode.PERSISTENT.value());
    if (parentDatastorePathList.length > 1) {
        Pair<String, ManagedObjectReference>[] nextDatastorePathList = new Pair[parentDatastorePathList.length - 1];
        for (int i = 0; i < parentDatastorePathList.length - 1; i++) nextDatastorePathList[i] = parentDatastorePathList[i + 1];
        setParentBackingInfo(parentBacking, nextDatastorePathList);
    }
    parentBacking.setFileName(parentDatastorePathList[0].first());
    backingInfo.setParent(parentBacking);
}
Also used : VirtualDiskFlatVer2BackingInfo(com.vmware.vim25.VirtualDiskFlatVer2BackingInfo) Pair(com.cloud.utils.Pair)

Example 29 with VirtualDiskFlatVer2BackingInfo

use of com.vmware.vim25.VirtualDiskFlatVer2BackingInfo in project cloudstack by apache.

the class VirtualMachineMO method getVmdkFileBaseName.

public String getVmdkFileBaseName(VirtualDisk disk) throws Exception {
    String vmdkFileBaseName = null;
    VirtualDeviceBackingInfo backingInfo = disk.getBacking();
    if (backingInfo instanceof VirtualDiskFlatVer2BackingInfo) {
        VirtualDiskFlatVer2BackingInfo diskBackingInfo = (VirtualDiskFlatVer2BackingInfo) backingInfo;
        DatastoreFile dsBackingFile = new DatastoreFile(diskBackingInfo.getFileName());
        vmdkFileBaseName = dsBackingFile.getFileBaseName();
    }
    return vmdkFileBaseName;
}
Also used : VirtualDiskFlatVer2BackingInfo(com.vmware.vim25.VirtualDiskFlatVer2BackingInfo) VirtualDeviceBackingInfo(com.vmware.vim25.VirtualDeviceBackingInfo)

Aggregations

VirtualDiskFlatVer2BackingInfo (com.vmware.vim25.VirtualDiskFlatVer2BackingInfo)29 VirtualDisk (com.vmware.vim25.VirtualDisk)20 VirtualDeviceBackingInfo (com.vmware.vim25.VirtualDeviceBackingInfo)11 Pair (com.cloud.utils.Pair)9 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)8 VirtualDeviceConnectInfo (com.vmware.vim25.VirtualDeviceConnectInfo)8 ArrayList (java.util.ArrayList)8 ArrayOfManagedObjectReference (com.vmware.vim25.ArrayOfManagedObjectReference)7 VirtualDevice (com.vmware.vim25.VirtualDevice)7 VirtualDiskRawDiskMappingVer1BackingInfo (com.vmware.vim25.VirtualDiskRawDiskMappingVer1BackingInfo)6 VirtualDeviceConfigSpec (com.vmware.vim25.VirtualDeviceConfigSpec)5 VirtualMachineConfigSpec (com.vmware.vim25.VirtualMachineConfigSpec)5 VirtualDiskFlatVer1BackingInfo (com.vmware.vim25.VirtualDiskFlatVer1BackingInfo)4 VirtualDiskSparseVer1BackingInfo (com.vmware.vim25.VirtualDiskSparseVer1BackingInfo)4 VirtualDiskSparseVer2BackingInfo (com.vmware.vim25.VirtualDiskSparseVer2BackingInfo)4 IOException (java.io.IOException)3 VirtualMachineFileInfo (com.vmware.vim25.VirtualMachineFileInfo)2 ResizeVolumeAnswer (com.cloud.agent.api.storage.ResizeVolumeAnswer)1 CloudException (com.cloud.exception.CloudException)1 InternalErrorException (com.cloud.exception.InternalErrorException)1