Search in sources :

Example 26 with VirtualDisk

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

the class VirtualMachineMO method getDiskDeviceByBusName.

public VirtualDisk getDiskDeviceByBusName(List<VirtualDevice> allDevices, String busName) throws Exception {
    for (VirtualDevice device : allDevices) {
        if (device instanceof VirtualDisk) {
            VirtualDisk disk = (VirtualDisk) device;
            String diskBusName = getDeviceBusName(allDevices, disk);
            if (busName.equalsIgnoreCase(diskBusName))
                return disk;
        }
    }
    return null;
}
Also used : VirtualDevice(com.vmware.vim25.VirtualDevice) VirtualDisk(com.vmware.vim25.VirtualDisk)

Example 27 with VirtualDisk

use of com.vmware.vim25.VirtualDisk 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 28 with VirtualDisk

use of com.vmware.vim25.VirtualDisk 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 29 with VirtualDisk

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

the class VirtualMachineMO method createLinkedClone.

public boolean createLinkedClone(String cloneName, ManagedObjectReference morBaseSnapshot, ManagedObjectReference morFolder, ManagedObjectReference morResourcePool, ManagedObjectReference morDs) throws Exception {
    assert (morBaseSnapshot != null);
    assert (morFolder != null);
    assert (morResourcePool != null);
    assert (morDs != null);
    VirtualDisk[] independentDisks = getAllIndependentDiskDevice();
    VirtualMachineRelocateSpec rSpec = new VirtualMachineRelocateSpec();
    if (independentDisks.length > 0) {
        VirtualMachineRelocateSpecDiskLocator[] diskLocator = new VirtualMachineRelocateSpecDiskLocator[independentDisks.length];
        for (int i = 0; i < diskLocator.length; i++) {
            diskLocator[i] = new VirtualMachineRelocateSpecDiskLocator();
            diskLocator[i].setDatastore(morDs);
            diskLocator[i].setDiskId(independentDisks[i].getKey());
            diskLocator[i].setDiskMoveType(VirtualMachineRelocateDiskMoveOptions._moveAllDiskBackingsAndDisallowSharing);
        }
        rSpec.setDiskMoveType(VirtualMachineRelocateDiskMoveOptions._createNewChildDiskBacking);
        rSpec.setDisk(diskLocator);
    } else {
        rSpec.setDiskMoveType(VirtualMachineRelocateDiskMoveOptions._createNewChildDiskBacking);
    }
    rSpec.setPool(morResourcePool);
    VirtualMachineCloneSpec cloneSpec = new VirtualMachineCloneSpec();
    cloneSpec.setPowerOn(false);
    cloneSpec.setTemplate(false);
    cloneSpec.setLocation(rSpec);
    cloneSpec.setSnapshot(morBaseSnapshot);
    ManagedObjectReference morTask = _context.getService().cloneVM_Task(_mor, morFolder, cloneName, cloneSpec);
    String result = _context.getServiceUtil().waitForTask(morTask);
    if (result.equals("sucess")) {
        _context.waitForTaskProgressDone(morTask);
        return true;
    } else {
        s_logger.error("VMware cloneVM_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
    }
    return false;
}
Also used : VirtualMachineRelocateSpec(com.vmware.vim25.VirtualMachineRelocateSpec) VirtualMachineCloneSpec(com.vmware.vim25.VirtualMachineCloneSpec) VirtualDisk(com.vmware.vim25.VirtualDisk) VirtualMachineRelocateSpecDiskLocator(com.vmware.vim25.VirtualMachineRelocateSpecDiskLocator) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 30 with VirtualDisk

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

the class VirtualMachineMO method getAllDiskDevice.

public VirtualDisk[] getAllDiskDevice() throws Exception {
    List<VirtualDisk> deviceList = new ArrayList<VirtualDisk>();
    VirtualDevice[] devices = (VirtualDevice[]) _context.getServiceUtil().getDynamicProperty(_mor, "config.hardware.device");
    if (devices != null && devices.length > 0) {
        for (VirtualDevice device : devices) {
            if (device instanceof VirtualDisk) {
                deviceList.add((VirtualDisk) device);
            }
        }
    }
    return deviceList.toArray(new VirtualDisk[0]);
}
Also used : ArrayList(java.util.ArrayList) VirtualDevice(com.vmware.vim25.VirtualDevice) VirtualDisk(com.vmware.vim25.VirtualDisk)

Aggregations

VirtualDisk (com.vmware.vim25.VirtualDisk)41 VirtualDiskFlatVer2BackingInfo (com.vmware.vim25.VirtualDiskFlatVer2BackingInfo)24 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)20 VirtualDevice (com.vmware.vim25.VirtualDevice)17 ArrayList (java.util.ArrayList)17 Pair (com.cloud.utils.Pair)16 ArrayOfManagedObjectReference (com.vmware.vim25.ArrayOfManagedObjectReference)16 VirtualDeviceBackingInfo (com.vmware.vim25.VirtualDeviceBackingInfo)11 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)9 VirtualDeviceConfigSpec (com.vmware.vim25.VirtualDeviceConfigSpec)9 VirtualMachineConfigSpec (com.vmware.vim25.VirtualMachineConfigSpec)9 RemoteException (java.rmi.RemoteException)9 VirtualMachineMO (com.cloud.hypervisor.vmware.mo.VirtualMachineMO)8 VirtualDeviceConnectInfo (com.vmware.vim25.VirtualDeviceConnectInfo)8 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7 VirtualDiskRawDiskMappingVer1BackingInfo (com.vmware.vim25.VirtualDiskRawDiskMappingVer1BackingInfo)6 IOException (java.io.IOException)6 CloudException (com.cloud.exception.CloudException)4 InternalErrorException (com.cloud.exception.InternalErrorException)4 DatastoreMO (com.cloud.hypervisor.vmware.mo.DatastoreMO)4