Search in sources :

Example 21 with VirtualDiskFlatVer2BackingInfo

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

the class VmwareResource method getAbsoluteVmdkFile.

private String getAbsoluteVmdkFile(VirtualDisk disk) {
    String vmdkAbsFile = null;
    VirtualDeviceBackingInfo backingInfo = disk.getBacking();
    if (backingInfo instanceof VirtualDiskFlatVer2BackingInfo) {
        VirtualDiskFlatVer2BackingInfo diskBackingInfo = (VirtualDiskFlatVer2BackingInfo) backingInfo;
        vmdkAbsFile = diskBackingInfo.getFileName();
    }
    return vmdkAbsFile;
}
Also used : VirtualDiskFlatVer2BackingInfo(com.vmware.vim25.VirtualDiskFlatVer2BackingInfo) VirtualDeviceBackingInfo(com.vmware.vim25.VirtualDeviceBackingInfo)

Example 22 with VirtualDiskFlatVer2BackingInfo

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

the class VirtualMachineMO method getDiskInfoBuilder.

public VirtualMachineDiskInfoBuilder getDiskInfoBuilder() throws Exception {
    VirtualMachineDiskInfoBuilder builder = new VirtualMachineDiskInfoBuilder();
    List<VirtualDevice> devices = _context.getVimClient().getDynamicProperty(_mor, "config.hardware.device");
    if (devices != null && devices.size() > 0) {
        for (VirtualDevice device : devices) {
            if (device instanceof VirtualDisk) {
                VirtualDeviceBackingInfo backingInfo = ((VirtualDisk) device).getBacking();
                if (backingInfo instanceof VirtualDiskFlatVer2BackingInfo) {
                    VirtualDiskFlatVer2BackingInfo diskBackingInfo = (VirtualDiskFlatVer2BackingInfo) backingInfo;
                    while (diskBackingInfo != null) {
                        String deviceBusName = getDeviceBusName(devices, device);
                        builder.addDisk(deviceBusName, diskBackingInfo.getFileName());
                        diskBackingInfo = diskBackingInfo.getParent();
                    }
                }
            }
        }
    }
    return builder;
}
Also used : VirtualDiskFlatVer2BackingInfo(com.vmware.vim25.VirtualDiskFlatVer2BackingInfo) VirtualDevice(com.vmware.vim25.VirtualDevice) VirtualDeviceBackingInfo(com.vmware.vim25.VirtualDeviceBackingInfo) VirtualDisk(com.vmware.vim25.VirtualDisk)

Example 23 with VirtualDiskFlatVer2BackingInfo

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

the class VirtualMachineMO method getDiskDevice.

// return pair of VirtualDisk and disk device bus name(ide0:0, etc)
public Pair<VirtualDisk, String> getDiskDevice(String vmdkDatastorePath) throws Exception {
    List<VirtualDevice> devices = _context.getVimClient().getDynamicProperty(_mor, "config.hardware.device");
    ArrayList<Pair<VirtualDisk, String>> partialMatchingDiskDevices = new ArrayList<Pair<VirtualDisk, String>>();
    DatastoreFile dsSrcFile = new DatastoreFile(vmdkDatastorePath);
    String srcBaseName = dsSrcFile.getFileBaseName();
    String trimmedSrcBaseName = VmwareHelper.trimSnapshotDeltaPostfix(srcBaseName);
    s_logger.info("Look for disk device info for volume : " + vmdkDatastorePath + " with base name: " + srcBaseName);
    if (devices != null && devices.size() > 0) {
        for (VirtualDevice device : devices) {
            if (device instanceof VirtualDisk) {
                s_logger.info("Test against disk device, controller key: " + device.getControllerKey() + ", unit number: " + device.getUnitNumber());
                VirtualDeviceBackingInfo backingInfo = ((VirtualDisk) device).getBacking();
                if (backingInfo instanceof VirtualDiskFlatVer2BackingInfo) {
                    VirtualDiskFlatVer2BackingInfo diskBackingInfo = (VirtualDiskFlatVer2BackingInfo) backingInfo;
                    do {
                        s_logger.info("Test against disk backing : " + diskBackingInfo.getFileName());
                        DatastoreFile dsBackingFile = new DatastoreFile(diskBackingInfo.getFileName());
                        String backingBaseName = dsBackingFile.getFileBaseName();
                        if (backingBaseName.equalsIgnoreCase(srcBaseName)) {
                            String deviceNumbering = getDeviceBusName(devices, device);
                            s_logger.info("Disk backing : " + diskBackingInfo.getFileName() + " matches ==> " + deviceNumbering);
                            return new Pair<VirtualDisk, String>((VirtualDisk) device, deviceNumbering);
                        }
                        if (backingBaseName.contains(trimmedSrcBaseName)) {
                            String deviceNumbering = getDeviceBusName(devices, device);
                            partialMatchingDiskDevices.add(new Pair<VirtualDisk, String>((VirtualDisk) device, deviceNumbering));
                        }
                        diskBackingInfo = diskBackingInfo.getParent();
                    } while (diskBackingInfo != null);
                }
            }
        }
    }
    // No disk device was found with an exact match for the volume path, hence look for disk device that matches the trimmed name.
    s_logger.info("No disk device with an exact match found for volume : " + vmdkDatastorePath + ". Look for disk device info against trimmed base name: " + srcBaseName);
    if (partialMatchingDiskDevices != null) {
        if (partialMatchingDiskDevices.size() == 1) {
            VirtualDiskFlatVer2BackingInfo matchingDiskBackingInfo = (VirtualDiskFlatVer2BackingInfo) partialMatchingDiskDevices.get(0).first().getBacking();
            s_logger.info("Disk backing : " + matchingDiskBackingInfo.getFileName() + " matches ==> " + partialMatchingDiskDevices.get(0).second());
            return partialMatchingDiskDevices.get(0);
        } else if (partialMatchingDiskDevices.size() > 1) {
            s_logger.warn("Disk device info lookup for volume: " + vmdkDatastorePath + " failed as multiple disk devices were found to match" + " volume's trimmed base name: " + trimmedSrcBaseName);
            return null;
        }
    }
    s_logger.warn("Disk device info lookup for volume: " + vmdkDatastorePath + " failed as no matching disk device found");
    return null;
}
Also used : VirtualDiskFlatVer2BackingInfo(com.vmware.vim25.VirtualDiskFlatVer2BackingInfo) VirtualDevice(com.vmware.vim25.VirtualDevice) ArrayList(java.util.ArrayList) VirtualDeviceBackingInfo(com.vmware.vim25.VirtualDeviceBackingInfo) VirtualDisk(com.vmware.vim25.VirtualDisk) Pair(com.cloud.utils.Pair)

Example 24 with VirtualDiskFlatVer2BackingInfo

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

Example 25 with VirtualDiskFlatVer2BackingInfo

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

the class VmwareHelper method setParentBackingInfo.

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

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