Search in sources :

Example 1 with VirtualDeviceConnectInfo

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

the class VirtualMachineMO method attachIso.

// isoDatastorePath: [datastore name] isoFilePath
public void attachIso(String isoDatastorePath, ManagedObjectReference morDs, boolean connect, boolean connectAtBoot) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - detachIso(). target MOR: " + _mor.get_value() + ", isoDatastorePath: " + isoDatastorePath + ", datastore: " + morDs.get_value() + ", connect: " + connect + ", connectAtBoot: " + connectAtBoot);
    assert (isoDatastorePath != null);
    assert (morDs != null);
    boolean newCdRom = false;
    VirtualCdrom cdRom = (VirtualCdrom) getIsoDevice();
    if (cdRom == null) {
        newCdRom = true;
        cdRom = new VirtualCdrom();
        cdRom.setControllerKey(getIDEDeviceControllerKey());
        int deviceNumber = getNextIDEDeviceNumber();
        cdRom.setUnitNumber(deviceNumber);
        cdRom.setKey(-deviceNumber);
    }
    VirtualDeviceConnectInfo cInfo = new VirtualDeviceConnectInfo();
    cInfo.setConnected(connect);
    cInfo.setStartConnected(connectAtBoot);
    cdRom.setConnectable(cInfo);
    VirtualCdromIsoBackingInfo backingInfo = new VirtualCdromIsoBackingInfo();
    backingInfo.setFileName(isoDatastorePath);
    backingInfo.setDatastore(morDs);
    cdRom.setBacking(backingInfo);
    VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec();
    VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
    VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
    deviceConfigSpec.setDevice(cdRom);
    if (newCdRom) {
        deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.add);
    } else {
        deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.edit);
    }
    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 - detachIso() done(failed)");
        throw new Exception("Failed to attach ISO due to " + TaskMO.getTaskFailureInfo(_context, morTask));
    }
    _context.waitForTaskProgressDone(morTask);
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - detachIso() done(successfully)");
}
Also used : VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) VirtualCdromIsoBackingInfo(com.vmware.vim25.VirtualCdromIsoBackingInfo) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) VirtualCdrom(com.vmware.vim25.VirtualCdrom) VirtualDeviceConnectInfo(com.vmware.vim25.VirtualDeviceConnectInfo) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 2 with VirtualDeviceConnectInfo

use of com.vmware.vim25.VirtualDeviceConnectInfo 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 3 with VirtualDeviceConnectInfo

use of com.vmware.vim25.VirtualDeviceConnectInfo 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 4 with VirtualDeviceConnectInfo

use of com.vmware.vim25.VirtualDeviceConnectInfo 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 5 with VirtualDeviceConnectInfo

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

Aggregations

VirtualDeviceConnectInfo (com.vmware.vim25.VirtualDeviceConnectInfo)20 VirtualDisk (com.vmware.vim25.VirtualDisk)8 VirtualDiskFlatVer2BackingInfo (com.vmware.vim25.VirtualDiskFlatVer2BackingInfo)8 VirtualCdrom (com.vmware.vim25.VirtualCdrom)7 VirtualDeviceConfigSpec (com.vmware.vim25.VirtualDeviceConfigSpec)6 VirtualCdromIsoBackingInfo (com.vmware.vim25.VirtualCdromIsoBackingInfo)5 Pair (com.cloud.utils.Pair)4 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)4 ArrayOfManagedObjectReference (com.vmware.vim25.ArrayOfManagedObjectReference)3 VirtualMachineConfigSpec (com.vmware.vim25.VirtualMachineConfigSpec)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 VirtualCdromRemotePassthroughBackingInfo (com.vmware.vim25.VirtualCdromRemotePassthroughBackingInfo)2 VirtualDeviceBackingInfo (com.vmware.vim25.VirtualDeviceBackingInfo)2 VirtualDiskFlatVer1BackingInfo (com.vmware.vim25.VirtualDiskFlatVer1BackingInfo)2 VirtualDiskRawDiskMappingVer1BackingInfo (com.vmware.vim25.VirtualDiskRawDiskMappingVer1BackingInfo)2 VirtualDiskSparseVer1BackingInfo (com.vmware.vim25.VirtualDiskSparseVer1BackingInfo)2 VirtualDiskSparseVer2BackingInfo (com.vmware.vim25.VirtualDiskSparseVer2BackingInfo)2 VirtualE1000 (com.vmware.vim25.VirtualE1000)2 VirtualEthernetCard (com.vmware.vim25.VirtualEthernetCard)2 VirtualEthernetCardNetworkBackingInfo (com.vmware.vim25.VirtualEthernetCardNetworkBackingInfo)2