Java Code Examples for com.vmware.vim25.VirtualDevice#getKey()

The following examples show how to use com.vmware.vim25.VirtualDevice#getKey() . 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: VirtualMachineMO.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
private int getControllerBusNumber(int controllerKey) throws Exception {
    List<VirtualDevice> devices = (List<VirtualDevice>)_context.getVimClient().
            getDynamicProperty(_mor, "config.hardware.device");

    if (devices != null && devices.size() > 0) {
        for (VirtualDevice device : devices) {
            if (device instanceof VirtualController && device.getKey() == controllerKey) {
                return ((VirtualController)device).getBusNumber();
            }
        }
    }
    throw new Exception("SCSI Controller with key " + controllerKey + " is Not Found");

}
 
Example 2
Source File: VirtualMachineMO.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
public int getPvScsiDeviceControllerKeyNoException() throws Exception {
    List<VirtualDevice> devices = (List<VirtualDevice>)_context.getVimClient().
            getDynamicProperty(_mor, "config.hardware.device");

    if (devices != null && devices.size() > 0) {
        for (VirtualDevice device : devices) {
            if (device instanceof ParaVirtualSCSIController) {
                return device.getKey();
            }
        }
    }

    return -1;
}
 
Example 3
Source File: VirtualMachineMO.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
public int getPvScsiDeviceControllerKey() throws Exception {
    List<VirtualDevice> devices = (List<VirtualDevice>)_context.getVimClient().
            getDynamicProperty(_mor, "config.hardware.device");

    if (devices != null && devices.size() > 0) {
        for (VirtualDevice device : devices) {
            if (device instanceof ParaVirtualSCSIController) {
                return device.getKey();
            }
        }
    }

    assert (false);
    throw new Exception("VMware Paravirtual SCSI Controller Not Found");
}
 
Example 4
Source File: VirtualMachineMO.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
public int getScsiDeviceControllerKey() throws Exception {
    List<VirtualDevice> devices = _context.getVimClient().getDynamicProperty(_mor, "config.hardware.device");

    if (devices != null && devices.size() > 0) {
        for (VirtualDevice device : devices) {
            if (device instanceof VirtualSCSIController) {
                return device.getKey();
            }
        }
    }

    assert (false);
    throw new Exception("SCSI Controller Not Found");
}
 
Example 5
Source File: VirtualMachineMO.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
public int getGenericScsiDeviceControllerKeyNoException() throws Exception {
    List<VirtualDevice> devices = _context.getVimClient().getDynamicProperty(_mor, "config.hardware.device");

    if (devices != null && devices.size() > 0) {
        for (VirtualDevice device : devices) {
            if (device instanceof VirtualSCSIController) {
                return device.getKey();
            }
        }
    }

    return -1;
}
 
Example 6
Source File: VirtualMachineMO.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
public int getScsiDeviceControllerKeyNoException() throws Exception {
    List<VirtualDevice> devices = (List<VirtualDevice>)_context.getVimClient().
        getDynamicProperty(_mor, "config.hardware.device");

    if(devices != null && devices.size() > 0) {
        for(VirtualDevice device : devices) {
            if(device instanceof VirtualSCSIController) {
                return device.getKey();
            }
        }
    }

    return -1;
}
 
Example 7
Source File: VirtualMachineMO.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
private int getLsiLogicDeviceControllerKeyNoException() throws Exception {
    List<VirtualDevice> devices = (List<VirtualDevice>)_context.getVimClient().
            getDynamicProperty(_mor, "config.hardware.device");

    if (devices != null && devices.size() > 0) {
        for (VirtualDevice device : devices) {
            if (device instanceof VirtualLsiLogicController) {
                return device.getKey();
            }
        }
    }

    return -1;
}
 
Example 8
Source File: VirtualMachineMO.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
public String getDeviceBusName(List<VirtualDevice> allDevices, VirtualDevice theDevice) throws Exception {
    for (VirtualDevice device : allDevices) {
        if (device.getKey() == theDevice.getControllerKey().intValue()) {
            if (device instanceof VirtualIDEController) {
                return String.format("ide%d:%d", ((VirtualIDEController)device).getBusNumber(), theDevice.getUnitNumber());
            } else if (device instanceof VirtualSCSIController) {
                return String.format("scsi%d:%d", ((VirtualSCSIController)device).getBusNumber(), theDevice.getUnitNumber());
            } else {
                throw new Exception("Device controller is not supported yet");
            }
        }
    }
    throw new Exception("Unable to find device controller");
}
 
Example 9
Source File: VirtualMachineMO.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
public VirtualDevice getIsoDevice(int key) throws Exception {
    List<VirtualDevice> devices = _context.getVimClient().getDynamicProperty(_mor, "config.hardware.device");
    if (devices != null && devices.size() > 0) {
        for (VirtualDevice device : devices) {
            if (device instanceof VirtualCdrom && device.getKey() == key) {
                return device;
            }
        }
    }
    return null;
}
 
Example 10
Source File: VirtualMachineMO.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
private int getLsiLogicSasDeviceControllerKeyNoException() throws Exception {
    List<VirtualDevice> devices = (List<VirtualDevice>)_context.getVimClient().
            getDynamicProperty(_mor, "config.hardware.device");

    if (devices != null && devices.size() > 0) {
        for (VirtualDevice device : devices) {
            if (device instanceof VirtualLsiLogicSASController) {
                return device.getKey();
            }
        }
    }

    return -1;
}
 
Example 11
Source File: VirtualMachineMO.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
private int getBusLogicDeviceControllerKeyNoException() throws Exception {
    List<VirtualDevice> devices = (List<VirtualDevice>)_context.getVimClient().
            getDynamicProperty(_mor, "config.hardware.device");

    if (devices != null && devices.size() > 0) {
        for (VirtualDevice device : devices) {
            if (device instanceof VirtualBusLogicController) {
                return device.getKey();
            }
        }
    }

    return -1;
}
 
Example 12
Source File: VMwareUtil.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
public static String getDeviceBusName(List<VirtualDevice> allDevices, VirtualDisk disk) throws Exception {
    for (VirtualDevice device : allDevices) {
        if (device.getKey() == disk.getControllerKey()) {
            if (device instanceof VirtualIDEController) {
                return String.format("ide%d:%d", ((VirtualIDEController)device).getBusNumber(), disk.getUnitNumber());
            } else if (device instanceof VirtualSCSIController) {
                return String.format("scsi%d:%d", ((VirtualSCSIController)device).getBusNumber(), disk.getUnitNumber());
            } else {
                throw new Exception("The device controller is not supported.");
            }
        }
    }

    throw new Exception("The device controller could not be located.");
}
 
Example 13
Source File: DiskManager.java    From development with Apache License 2.0 4 votes vote down vote up
private void configureDataDisks(VirtualMachineConfigSpec vmConfigSpec,
        List<VirtualDevice> devices, VirtualDisk vdSystemDisk)
        throws Exception {

    Double[] dataDisksMB = paramHandler.getDataDisksMB();

    if (dataDisksMB.length == 0) {
        logger.debug("Reconfiguration of data disk not possible because data disk size is not defined.");
        return;
    }

    int maxDeviceKey = 0;
    int maxUnitNumber = 0;
    for (VirtualDevice vdDev : devices) {
        if (vdDev instanceof VirtualDisk) {
            if (vdDev.getKey() > maxDeviceKey) {
                maxDeviceKey = vdDev.getKey();
            }
            if (vdDev.getUnitNumber().intValue() > maxUnitNumber) {
                maxUnitNumber = vdDev.getUnitNumber().intValue();
            }
        }
    }

    int vdIndex = 0;
    for (Double dataDiskMB : dataDisksMB) {
        vdIndex++;
        int vdKey = paramHandler.getDataDiskKey(vdIndex);
        long newDiskSpace = dataDiskMB.longValue() * 1024;

        if (vdKey == 0) {
            ++maxDeviceKey;
            ++maxUnitNumber;
            VirtualDeviceConfigSpec vmDeviceSpec = createNewDataDisk(
                    vdSystemDisk, newDiskSpace, maxDeviceKey, maxUnitNumber);
            vmConfigSpec.getDeviceChange().add(vmDeviceSpec);
            paramHandler.setDataDiskKey(vdIndex, maxDeviceKey);
        } else {
            updateDiskConfiguration(vmConfigSpec, devices, vdKey,
                    newDiskSpace);
        }
    }
}