com.vmware.vim25.VirtualDeviceConnectInfo Java Examples

The following examples show how to use com.vmware.vim25.VirtualDeviceConnectInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NetworkManager.java    From development with Apache License 2.0 6 votes vote down vote up
private static void replaceNetworkAdapter(
        VirtualMachineConfigSpec vmConfigSpec, VirtualDevice oldNIC,
        ManagedObjectReference newNetworkRef, String newNetworkName)
        throws Exception {
    logger.debug("new network: " + newNetworkName);
    VirtualEthernetCardNetworkBackingInfo nicBacking = new VirtualEthernetCardNetworkBackingInfo();
    nicBacking.setDeviceName(newNetworkName);
    nicBacking.setNetwork(newNetworkRef);
    nicBacking.setUseAutoDetect(true);
    oldNIC.setBacking(nicBacking);

    VirtualDeviceConnectInfo info = new VirtualDeviceConnectInfo();
    info.setConnected(true);
    info.setStartConnected(true);
    info.setAllowGuestControl(true);
    oldNIC.setConnectable(info);
    // oldNIC.getConnectable().setConnected(true);
    // oldNIC.getConnectable().setStartConnected(true);
    VirtualDeviceConfigSpec vmDeviceSpec = new VirtualDeviceConfigSpec();
    vmDeviceSpec.setOperation(VirtualDeviceConfigSpecOperation.EDIT);
    vmDeviceSpec.setDevice(oldNIC);
    vmConfigSpec.getDeviceChange().add(vmDeviceSpec);
}
 
Example #2
Source File: NetworkManager.java    From development with Apache License 2.0 5 votes vote down vote up
private static void connectNIC(VirtualMachineConfigSpec vmConfigSpec,
        VirtualDevice oldNIC, String vmNetworkName) throws Exception {

    logger.debug("networkName: " + vmNetworkName);

    VirtualDeviceConnectInfo info = new VirtualDeviceConnectInfo();
    info.setConnected(true);
    info.setStartConnected(true);
    info.setAllowGuestControl(true);
    oldNIC.setConnectable(info);
    VirtualDeviceConfigSpec vmDeviceSpec = new VirtualDeviceConfigSpec();
    vmDeviceSpec.setOperation(VirtualDeviceConfigSpecOperation.EDIT);
    vmDeviceSpec.setDevice(oldNIC);
    vmConfigSpec.getDeviceChange().add(vmDeviceSpec);
}
 
Example #3
Source File: VmwareProcessClient.java    From primecloud-controller with GNU General Public License v2.0 5 votes vote down vote up
protected VirtualDisk newDisk(VirtualMachine machine, Integer scsiId, Integer size) {
    // SCSIコントローラを取得
    VirtualSCSIController scsiController = getSCSIController(machine);

    // 仮想マシン自体のディスクを取得
    VirtualDisk machineDisk = getVirtualDisk(machine, 0);
    VirtualDiskFlatVer2BackingInfo machieBackingInfo = VirtualDiskFlatVer2BackingInfo.class
            .cast(machineDisk.getBacking());

    // VirtualDisk
    VirtualDisk disk = new VirtualDisk();
    disk.setUnitNumber(scsiId);
    disk.setCapacityInKB(size * 1024L * 1024L);
    disk.setControllerKey(scsiController.getKey());

    // VirtualDiskFlatVer2BackingInfo
    VirtualDiskFlatVer2BackingInfo backingInfo = new VirtualDiskFlatVer2BackingInfo();
    backingInfo.setDatastore(null);
    backingInfo.setFileName("");
    backingInfo.setDiskMode("persistent");
    backingInfo.setSplit(false);
    backingInfo.setEagerlyScrub(false);
    backingInfo.setThinProvisioned(machieBackingInfo.getThinProvisioned());
    backingInfo.setWriteThrough(false);
    disk.setBacking(backingInfo);

    // VirtualDeviceConnectInfo
    VirtualDeviceConnectInfo connectInfo = new VirtualDeviceConnectInfo();
    connectInfo.setAllowGuestControl(false);
    connectInfo.setStartConnected(true);
    connectInfo.setConnected(true);
    disk.setConnectable(connectInfo);

    return disk;
}
 
Example #4
Source File: VmwareProcessClient.java    From primecloud-controller with GNU General Public License v2.0 5 votes vote down vote up
protected VirtualDisk reuseDisk(VirtualMachine machine, Integer scsiId, String fileName) {
    // SCSIコントローラを取得
    VirtualSCSIController scsiController = getSCSIController(machine);

    // 仮想マシン自体のディスクを取得
    VirtualDisk machineDisk = getVirtualDisk(machine, 0);
    VirtualDiskFlatVer2BackingInfo machieBackingInfo = VirtualDiskFlatVer2BackingInfo.class
            .cast(machineDisk.getBacking());

    // VirtualDisk
    VirtualDisk disk = new VirtualDisk();
    disk.setUnitNumber(scsiId);
    disk.setControllerKey(scsiController.getKey());

    // VirtualDiskFlatVer2BackingInfo
    VirtualDiskFlatVer2BackingInfo backingInfo = new VirtualDiskFlatVer2BackingInfo();
    backingInfo.setFileName(fileName);
    backingInfo.setDiskMode("persistent");
    backingInfo.setSplit(false);
    backingInfo.setEagerlyScrub(false);
    backingInfo.setThinProvisioned(machieBackingInfo.getThinProvisioned());
    backingInfo.setWriteThrough(false);
    disk.setBacking(backingInfo);

    // VirtualDeviceConnectInfo
    VirtualDeviceConnectInfo connectInfo = new VirtualDeviceConnectInfo();
    connectInfo.setAllowGuestControl(false);
    connectInfo.setStartConnected(true);
    connectInfo.setConnected(true);
    disk.setConnectable(connectInfo);

    return disk;
}
 
Example #5
Source File: VmwareHelper.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static VirtualDeviceConnectInfo getVirtualDeviceConnectInfo(boolean connected, boolean connectOnStart) {
    VirtualDeviceConnectInfo connectInfo = new VirtualDeviceConnectInfo();
    connectInfo.setAllowGuestControl(true);
    connectInfo.setConnected(connected);
    connectInfo.setStartConnected(connectOnStart);
    return connectInfo;
}
 
Example #6
Source File: VmwareHelper.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
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.value());
    backingInfo.setThinProvisioned(true);
    backingInfo.setEagerlyScrub(false);
    backingInfo.setDatastore(morDs);
    backingInfo.setFileName(vmdkDatastorePath);
    disk.setBacking(backingInfo);

    int ideControllerKey = vmMo.getIDEDeviceControllerKey();
    if (controllerKey < 0)
        controllerKey = ideControllerKey;
    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;
}
 
Example #7
Source File: VMwareGuru.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
/**
 * Get network MO from VM NIC
 */
private NetworkMO getNetworkMO(VirtualE1000 nic, VmwareContext context) {
    VirtualDeviceConnectInfo connectable = nic.getConnectable();
    VirtualEthernetCardNetworkBackingInfo info = (VirtualEthernetCardNetworkBackingInfo)nic.getBacking();
    ManagedObjectReference networkMor = info.getNetwork();
    if (networkMor == null) {
        throw new CloudRuntimeException("Could not find network for NIC on: " + nic.getMacAddress());
    }
    return new NetworkMO(context, networkMor);
}
 
Example #8
Source File: VirtualMachineMO.java    From cloudstack with Apache License 2.0 4 votes vote down vote up
public void attachIso(String isoDatastorePath, ManagedObjectReference morDs,
boolean connect, boolean connectAtBoot, Integer key) throws Exception {

    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - attachIso(). target MOR: " + _mor.getValue() + ", isoDatastorePath: " + isoDatastorePath + ", datastore: " +
                morDs.getValue() + ", connect: " + connect + ", connectAtBoot: " + connectAtBoot);

    assert (isoDatastorePath != null);
    assert (morDs != null);

    boolean newCdRom = false;
    VirtualCdrom cdRom;
    if (key == null) {
        cdRom = (VirtualCdrom) getIsoDevice();
    } else {
        cdRom = (VirtualCdrom) getIsoDevice(key);
    }
    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.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 - attachIso() 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 - attachIso() done(successfully)");
}
 
Example #9
Source File: VmwareHelper.java    From cloudstack with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
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.value());
    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);

    int ideControllerKey = vmMo.getIDEDeviceControllerKey();
    if (controllerKey < 0)
        controllerKey = ideControllerKey;
    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;
}