Search in sources :

Example 41 with ManagedObjectReference

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

the class VmwareHelper method prepareDiskDevice.

// vmdkDatastorePath: [datastore name] vmdkFilePath
public static VirtualDevice prepareDiskDevice(VirtualMachineMO vmMo, int controllerKey, String vmdkDatastorePath, int sizeInMb, ManagedObjectReference morDs, int deviceNumber, int contextNumber) throws Exception {
    VirtualDisk disk = new VirtualDisk();
    VirtualDiskFlatVer2BackingInfo backingInfo = new VirtualDiskFlatVer2BackingInfo();
    backingInfo.setDiskMode(VirtualDiskMode.persistent.toString());
    backingInfo.setThinProvisioned(true);
    backingInfo.setEagerlyScrub(false);
    backingInfo.setDatastore(morDs);
    backingInfo.setFileName(vmdkDatastorePath);
    disk.setBacking(backingInfo);
    if (controllerKey < 0)
        controllerKey = vmMo.getIDEDeviceControllerKey();
    if (deviceNumber < 0)
        deviceNumber = vmMo.getNextDeviceNumber(controllerKey);
    disk.setControllerKey(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 : VirtualDiskFlatVer2BackingInfo(com.vmware.vim25.VirtualDiskFlatVer2BackingInfo) VirtualDeviceConnectInfo(com.vmware.vim25.VirtualDeviceConnectInfo) VirtualDisk(com.vmware.vim25.VirtualDisk)

Example 42 with ManagedObjectReference

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

the class VmwareHelper method prepareNicDevice.

public static VirtualDevice prepareNicDevice(VirtualMachineMO vmMo, ManagedObjectReference morNetwork, VirtualEthernetCardType deviceType, String portGroupName, String macAddress, int deviceNumber, int contextNumber, boolean conntected, boolean connectOnStart) throws Exception {
    VirtualEthernetCard nic;
    switch(deviceType) {
        case E1000:
            nic = new VirtualE1000();
            break;
        case PCNet32:
            nic = new VirtualPCNet32();
            break;
        case Vmxnet2:
            nic = new VirtualVmxnet2();
            break;
        case Vmxnet3:
            nic = new VirtualVmxnet3();
            break;
        default:
            assert (false);
            nic = new VirtualE1000();
    }
    VirtualEthernetCardNetworkBackingInfo nicBacking = new VirtualEthernetCardNetworkBackingInfo();
    nicBacking.setDeviceName(portGroupName);
    nicBacking.setNetwork(morNetwork);
    nic.setBacking(nicBacking);
    VirtualDeviceConnectInfo connectInfo = new VirtualDeviceConnectInfo();
    connectInfo.setAllowGuestControl(true);
    connectInfo.setConnected(conntected);
    connectInfo.setStartConnected(connectOnStart);
    nic.setAddressType("Manual");
    nic.setConnectable(connectInfo);
    nic.setMacAddress(macAddress);
    nic.setUnitNumber(deviceNumber);
    nic.setKey(-contextNumber);
    return nic;
}
Also used : VirtualEthernetCardNetworkBackingInfo(com.vmware.vim25.VirtualEthernetCardNetworkBackingInfo) VirtualPCNet32(com.vmware.vim25.VirtualPCNet32) VirtualVmxnet2(com.vmware.vim25.VirtualVmxnet2) VirtualVmxnet3(com.vmware.vim25.VirtualVmxnet3) VirtualEthernetCard(com.vmware.vim25.VirtualEthernetCard) VirtualDeviceConnectInfo(com.vmware.vim25.VirtualDeviceConnectInfo) VirtualE1000(com.vmware.vim25.VirtualE1000)

Example 43 with ManagedObjectReference

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

the class VmwareHelper method prepareDiskDevice.

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.toString());
    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);
    if (controllerKey < 0)
        controllerKey = vmMo.getIDEDeviceControllerKey();
    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 44 with ManagedObjectReference

use of com.vmware.vim25.ManagedObjectReference 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 45 with ManagedObjectReference

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

the class VmwareHelper method prepareDiskDevice.

// vmdkDatastorePath: [datastore name] vmdkFilePath
public static VirtualDevice prepareDiskDevice(VirtualMachineMO vmMo, int controllerKey, String[] vmdkDatastorePathChain, ManagedObjectReference morDs, int deviceNumber, int contextNumber) throws Exception {
    assert (vmdkDatastorePathChain != null);
    assert (vmdkDatastorePathChain.length >= 1);
    VirtualDisk disk = new VirtualDisk();
    VirtualDiskFlatVer2BackingInfo backingInfo = new VirtualDiskFlatVer2BackingInfo();
    backingInfo.setDatastore(morDs);
    backingInfo.setFileName(vmdkDatastorePathChain[0]);
    backingInfo.setDiskMode(VirtualDiskMode.persistent.toString());
    if (vmdkDatastorePathChain.length > 1) {
        String[] parentDisks = new String[vmdkDatastorePathChain.length - 1];
        for (int i = 0; i < vmdkDatastorePathChain.length - 1; i++) parentDisks[i] = vmdkDatastorePathChain[i + 1];
        setParentBackingInfo(backingInfo, morDs, parentDisks);
    }
    disk.setBacking(backingInfo);
    if (controllerKey < 0)
        controllerKey = vmMo.getIDEDeviceControllerKey();
    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)

Aggregations

ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)236 ArrayOfManagedObjectReference (com.vmware.vim25.ArrayOfManagedObjectReference)62 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)57 Pair (com.cloud.utils.Pair)49 RemoteException (java.rmi.RemoteException)48 ArrayList (java.util.ArrayList)45 UnsupportedEncodingException (java.io.UnsupportedEncodingException)39 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)35 VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)32 IOException (java.io.IOException)31 CloudException (com.cloud.exception.CloudException)30 DatastoreMO (com.cloud.hypervisor.vmware.mo.DatastoreMO)30 VirtualMachineConfigSpec (com.vmware.vim25.VirtualMachineConfigSpec)29 ObjectContent (com.vmware.vim25.ObjectContent)28 VirtualDeviceConfigSpec (com.vmware.vim25.VirtualDeviceConfigSpec)27 VirtualMachineMO (com.cloud.hypervisor.vmware.mo.VirtualMachineMO)25 ConfigurationException (javax.naming.ConfigurationException)24 InternalErrorException (com.cloud.exception.InternalErrorException)23 VirtualDisk (com.vmware.vim25.VirtualDisk)23 ConnectException (java.net.ConnectException)23