Search in sources :

Example 1 with VirtualDiskSparseVer1BackingInfo

use of com.vmware.vim25.VirtualDiskSparseVer1BackingInfo in project CloudStack-archive by CloudStack-extras.

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());
    }
    if (controllerKey < 0)
        controllerKey = vmMo.getIDEDeviceControllerKey();
    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 2 with VirtualDiskSparseVer1BackingInfo

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

the class VirtualMachineMO method getAllIndependentDiskDevice.

public VirtualDisk[] getAllIndependentDiskDevice() throws Exception {
    List<VirtualDisk> independentDisks = new ArrayList<VirtualDisk>();
    VirtualDisk[] allDisks = getAllDiskDevice();
    if (allDisks.length > 0) {
        for (VirtualDisk disk : allDisks) {
            String diskMode = "";
            if (disk.getBacking() instanceof VirtualDiskFlatVer1BackingInfo) {
                diskMode = ((VirtualDiskFlatVer1BackingInfo) disk.getBacking()).getDiskMode();
            } else if (disk.getBacking() instanceof VirtualDiskFlatVer2BackingInfo) {
                diskMode = ((VirtualDiskFlatVer2BackingInfo) disk.getBacking()).getDiskMode();
            } else if (disk.getBacking() instanceof VirtualDiskRawDiskMappingVer1BackingInfo) {
                diskMode = ((VirtualDiskRawDiskMappingVer1BackingInfo) disk.getBacking()).getDiskMode();
            } else if (disk.getBacking() instanceof VirtualDiskSparseVer1BackingInfo) {
                diskMode = ((VirtualDiskSparseVer1BackingInfo) disk.getBacking()).getDiskMode();
            } else if (disk.getBacking() instanceof VirtualDiskSparseVer2BackingInfo) {
                diskMode = ((VirtualDiskSparseVer2BackingInfo) disk.getBacking()).getDiskMode();
            }
            if (diskMode.indexOf("independent") != -1) {
                independentDisks.add(disk);
            }
        }
    }
    return independentDisks.toArray(new VirtualDisk[0]);
}
Also used : VirtualDiskSparseVer2BackingInfo(com.vmware.vim25.VirtualDiskSparseVer2BackingInfo) VirtualDiskFlatVer1BackingInfo(com.vmware.vim25.VirtualDiskFlatVer1BackingInfo) VirtualDiskSparseVer1BackingInfo(com.vmware.vim25.VirtualDiskSparseVer1BackingInfo) VirtualDiskFlatVer2BackingInfo(com.vmware.vim25.VirtualDiskFlatVer2BackingInfo) ArrayList(java.util.ArrayList) VirtualDiskRawDiskMappingVer1BackingInfo(com.vmware.vim25.VirtualDiskRawDiskMappingVer1BackingInfo) VirtualDisk(com.vmware.vim25.VirtualDisk)

Example 3 with VirtualDiskSparseVer1BackingInfo

use of com.vmware.vim25.VirtualDiskSparseVer1BackingInfo in project CloudStack-archive by CloudStack-extras.

the class VirtualMachineMO method getAllIndependentDiskDevice.

public VirtualDisk[] getAllIndependentDiskDevice() throws Exception {
    List<VirtualDisk> independentDisks = new ArrayList<VirtualDisk>();
    VirtualDisk[] allDisks = getAllDiskDevice();
    if (allDisks.length > 0) {
        for (VirtualDisk disk : allDisks) {
            String diskMode = "";
            if (disk.getBacking() instanceof VirtualDiskFlatVer1BackingInfo) {
                diskMode = ((VirtualDiskFlatVer1BackingInfo) disk.getBacking()).getDiskMode();
            } else if (disk.getBacking() instanceof VirtualDiskFlatVer2BackingInfo) {
                diskMode = ((VirtualDiskFlatVer2BackingInfo) disk.getBacking()).getDiskMode();
            } else if (disk.getBacking() instanceof VirtualDiskRawDiskMappingVer1BackingInfo) {
                diskMode = ((VirtualDiskRawDiskMappingVer1BackingInfo) disk.getBacking()).getDiskMode();
            } else if (disk.getBacking() instanceof VirtualDiskSparseVer1BackingInfo) {
                diskMode = ((VirtualDiskSparseVer1BackingInfo) disk.getBacking()).getDiskMode();
            } else if (disk.getBacking() instanceof VirtualDiskSparseVer2BackingInfo) {
                diskMode = ((VirtualDiskSparseVer2BackingInfo) disk.getBacking()).getDiskMode();
            }
            if (diskMode.indexOf("independent") != -1) {
                independentDisks.add(disk);
            }
        }
    }
    return independentDisks.toArray(new VirtualDisk[0]);
}
Also used : VirtualDiskSparseVer2BackingInfo(com.vmware.vim25.VirtualDiskSparseVer2BackingInfo) VirtualDiskFlatVer1BackingInfo(com.vmware.vim25.VirtualDiskFlatVer1BackingInfo) VirtualDiskSparseVer1BackingInfo(com.vmware.vim25.VirtualDiskSparseVer1BackingInfo) VirtualDiskFlatVer2BackingInfo(com.vmware.vim25.VirtualDiskFlatVer2BackingInfo) ArrayList(java.util.ArrayList) VirtualDiskRawDiskMappingVer1BackingInfo(com.vmware.vim25.VirtualDiskRawDiskMappingVer1BackingInfo) VirtualDisk(com.vmware.vim25.VirtualDisk)

Example 4 with VirtualDiskSparseVer1BackingInfo

use of com.vmware.vim25.VirtualDiskSparseVer1BackingInfo 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)

Aggregations

VirtualDisk (com.vmware.vim25.VirtualDisk)4 VirtualDiskFlatVer1BackingInfo (com.vmware.vim25.VirtualDiskFlatVer1BackingInfo)4 VirtualDiskFlatVer2BackingInfo (com.vmware.vim25.VirtualDiskFlatVer2BackingInfo)4 VirtualDiskRawDiskMappingVer1BackingInfo (com.vmware.vim25.VirtualDiskRawDiskMappingVer1BackingInfo)4 VirtualDiskSparseVer1BackingInfo (com.vmware.vim25.VirtualDiskSparseVer1BackingInfo)4 VirtualDiskSparseVer2BackingInfo (com.vmware.vim25.VirtualDiskSparseVer2BackingInfo)4 VirtualDeviceBackingInfo (com.vmware.vim25.VirtualDeviceBackingInfo)2 VirtualDeviceConnectInfo (com.vmware.vim25.VirtualDeviceConnectInfo)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2