Search in sources :

Example 1 with VirtualDiskRawDiskMappingVer1BackingInfo

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

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

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

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

the class VirtualMachineMO method createDisk.

// vmdkDatastorePath: [datastore name] vmdkFilePath
public void createDisk(String vmdkDatastorePath, VirtualDiskType diskType, VirtualDiskMode diskMode, String rdmDeviceName, int sizeInMb, ManagedObjectReference morDs, int controllerKey) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - createDisk(). target MOR: " + _mor.get_value() + ", vmdkDatastorePath: " + vmdkDatastorePath + ", sizeInMb: " + sizeInMb + ", diskType: " + diskType + ", diskMode: " + diskMode + ", rdmDeviceName: " + rdmDeviceName + ", datastore: " + morDs.get_value() + ", controllerKey: " + controllerKey);
    assert (vmdkDatastorePath != null);
    assert (morDs != null);
    if (controllerKey < 0) {
        controllerKey = getIDEDeviceControllerKey();
    }
    VirtualDisk newDisk = new VirtualDisk();
    if (diskType == VirtualDiskType.thin || diskType == VirtualDiskType.preallocated || diskType == VirtualDiskType.eagerZeroedThick) {
        VirtualDiskFlatVer2BackingInfo backingInfo = new VirtualDiskFlatVer2BackingInfo();
        backingInfo.setDiskMode(diskMode.persistent.toString());
        if (diskType == VirtualDiskType.thin) {
            backingInfo.setThinProvisioned(true);
        } else {
            backingInfo.setThinProvisioned(false);
        }
        if (diskType == VirtualDiskType.eagerZeroedThick) {
            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(diskMode.persistent.toString());
        }
        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[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
    VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
    deviceConfigSpec.setDevice(newDisk);
    deviceConfigSpec.setFileOperation(VirtualDeviceConfigSpecFileOperation.create);
    deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.add);
    deviceConfigSpecArray[0] = deviceConfigSpec;
    reConfigSpec.setDeviceChange(deviceConfigSpecArray);
    ManagedObjectReference morTask = _context.getService().reconfigVM_Task(_mor, reConfigSpec);
    String result = _context.getServiceUtil().waitForTask(morTask);
    if (!result.equals("sucess")) {
        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) VirtualDiskRawDiskMappingVer1BackingInfo(com.vmware.vim25.VirtualDiskRawDiskMappingVer1BackingInfo) VirtualDisk(com.vmware.vim25.VirtualDisk) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 5 with VirtualDiskRawDiskMappingVer1BackingInfo

use of com.vmware.vim25.VirtualDiskRawDiskMappingVer1BackingInfo 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, int sizeInMb, ManagedObjectReference morDs, int controllerKey) 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);
    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) VirtualDiskRawDiskMappingVer1BackingInfo(com.vmware.vim25.VirtualDiskRawDiskMappingVer1BackingInfo) VirtualDisk(com.vmware.vim25.VirtualDisk) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Aggregations

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