private static int getMaxNodesPerControllerOfType(VirtualController controller) { int count = 0; if ( VirtualSCSIController.class.isInstance(controller) ) { // The actual device nodes of SCSI controller are 16 // but one of them is reserved for the controller itself // so this means that the maximum free nodes are 15. count = 16; } else if (VirtualIDEController.class.isInstance(controller)) { count = 2; } else { throw new RuntimeException("Unknown controller type - " + controller.getDeviceInfo().getLabel()); } return count; }
private <T extends VirtualController> T getFirstAvailableController(Class<T> clazz) { VirtualController vc = createControllerInstance(clazz); int maxNodes = getMaxNodesPerControllerOfType(vc); for (T controller : getVirtualDevicesOfType(clazz)) { // Check if controller can accept addition of new devices. if (controller.device == null || controller.device.length < maxNodes) { return controller; } } return null; }
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"); }