/** * Method used to connect to data center to retrieve a list with all the guest operating system descriptors * supported by the host system. * * @param httpInputs Object that has all the inputs necessary to made a connection to data center * @param vmInputs Object that has all the specific inputs necessary to identify the targeted host system * @param delimiter String that represents the delimiter needed in the result list * @return Map with String as key and value that contains returnCode of the operation, a list that contains all the * guest operating system descriptors supported by the host system or failure message and the exception if there is one * @throws Exception */ public Map<String, String> getOsDescriptors(HttpInputs httpInputs, VmInputs vmInputs, String delimiter) throws Exception { ConnectionResources connectionResources = new ConnectionResources(httpInputs, vmInputs); try { ManagedObjectReference environmentBrowserMor = new MorObjectHandler() .getEnvironmentBrowser(connectionResources, ManagedObjectType.ENVIRONMENT_BROWSER.getValue()); VirtualMachineConfigOption configOptions = connectionResources.getVimPortType() .queryConfigOption(environmentBrowserMor, null, connectionResources.getHostMor()); List<GuestOsDescriptor> guestOSDescriptors = configOptions.getGuestOSDescriptor(); return ResponseUtils.getResultsMap(ResponseUtils.getResponseStringFromCollection(guestOSDescriptors, delimiter), Outputs.RETURN_CODE_SUCCESS); } catch (Exception ex) { return ResponseUtils.getResultsMap(ex.toString(), Outputs.RETURN_CODE_FAILURE); } finally { if (httpInputs.isCloseSession()) { connectionResources.getConnection().disconnect(); clearConnectionFromContext(httpInputs.getGlobalSessionObject()); } } }
public GuestOsDescriptor getGuestOsDescriptor(String guestOsId) throws Exception { GuestOsDescriptor guestOsDescriptor = null; String guestId = guestOsId; if (guestId == null) { guestId = getGuestId(); } ManagedObjectReference vmEnvironmentBrowser = _context.getVimClient().getMoRefProp(_mor, "environmentBrowser"); VirtualMachineConfigOption vmConfigOption = _context.getService().queryConfigOption(vmEnvironmentBrowser, null, null); List<GuestOsDescriptor> guestDescriptors = vmConfigOption.getGuestOSDescriptor(); for (GuestOsDescriptor descriptor : guestDescriptors) { if (guestId != null && guestId.equalsIgnoreCase(descriptor.getId())) { guestOsDescriptor = descriptor; break; } } return guestOsDescriptor; }
public boolean isMemoryHotAddSupported(String guestOsId) throws Exception { boolean guestOsSupportsMemoryHotAdd = false; boolean virtualHardwareSupportsMemoryHotAdd = false; GuestOsDescriptor guestOsDescriptor; int virtualHardwareVersion; guestOsDescriptor = getGuestOsDescriptor(guestOsId); virtualHardwareVersion = getVirtualHardwareVersion(); // Check if guest operating system supports memory hotadd if (guestOsDescriptor.isSupportsMemoryHotAdd()) { guestOsSupportsMemoryHotAdd = true; } // Check if virtual machine is using hardware version 7 or later. if (virtualHardwareVersion >= 7) { virtualHardwareSupportsMemoryHotAdd = true; } return guestOsSupportsMemoryHotAdd && virtualHardwareSupportsMemoryHotAdd; }
@Override public String getRecommendedDiskController(String guestOsId) throws Exception { VirtualMachineConfigOption vmConfigOption = _context.getService().queryConfigOption(getEnvironmentBrowser(), null, null); GuestOsDescriptor guestOsDescriptor = null; String diskController = null; List<GuestOsDescriptor> guestDescriptors = vmConfigOption.getGuestOSDescriptor(); for (GuestOsDescriptor descriptor : guestDescriptors) { if (guestOsId != null && guestOsId.equalsIgnoreCase(descriptor.getId())) { guestOsDescriptor = descriptor; break; } } if (guestOsDescriptor != null) { diskController = VmwareHelper.getRecommendedDiskControllerFromDescriptor(guestOsDescriptor); s_logger.debug("Retrieved recommended disk controller for guest OS : " + guestOsId + " in cluster " + getHyperHostName() + " : " + diskController); return diskController; } else { String msg = "Unable to retrieve recommended disk controller for guest OS : " + guestOsId + " in cluster " + getHyperHostName(); s_logger.error(msg); throw new CloudRuntimeException(msg); } }
private static VirtualNetworkAdapterType TryGetNetworkAdapterType(GuestOsDescriptor guestOsInfo) { String ethernetCardType = guestOsInfo.getRecommendedEthernetCard(); if ((ethernetCardType == null || ethernetCardType.isEmpty()) && (guestOsInfo.getSupportedEthernetCard()!= null) && ((guestOsInfo.getSupportedEthernetCard().length > 0))) { ethernetCardType = guestOsInfo.getSupportedEthernetCard()[0]; } return GetNetworkAdapterTypeByApiType(ethernetCardType); }
public static <T> String getResponseStringFromCollection(Collection<T> collectionItems, String delimiter) { StringBuilder sb = new StringBuilder(); int index = 0; for (T item : collectionItems) { String itemName = item instanceof GuestOsDescriptor ? ((GuestOsDescriptor) item).getId() : (String) item; sb.append(itemName); if (index < collectionItems.size() - 1) { sb.append(InputUtils.getDefaultDelimiter(delimiter, COMMA_DELIMITER)); } index++; } return sb.toString(); }
public boolean isCpuHotAddSupported(String guestOsId) throws Exception { boolean guestOsSupportsCpuHotAdd = false; boolean virtualHardwareSupportsCpuHotAdd = false; GuestOsDescriptor guestOsDescriptor; int virtualHardwareVersion; int numCoresPerSocket; guestOsDescriptor = getGuestOsDescriptor(guestOsId); virtualHardwareVersion = getVirtualHardwareVersion(); // Check if guest operating system supports cpu hotadd if (guestOsDescriptor.isSupportsCpuHotAdd()) { guestOsSupportsCpuHotAdd = true; } // Check if virtual machine is using hardware version 8 or later. // If hardware version is 7, then only 1 core per socket is supported. Hot adding multi-core vcpus is not allowed if hardware version is 7. if (virtualHardwareVersion >= 8) { virtualHardwareSupportsCpuHotAdd = true; } else if (virtualHardwareVersion == 7) { // Check if virtual machine has only 1 core per socket. numCoresPerSocket = getCoresPerSocket(); if (numCoresPerSocket == 1) { virtualHardwareSupportsCpuHotAdd = true; } } return guestOsSupportsCpuHotAdd && virtualHardwareSupportsCpuHotAdd; }
public static String getRecommendedDiskControllerFromDescriptor(GuestOsDescriptor guestOsDescriptor) throws Exception { String recommendedController; recommendedController = guestOsDescriptor.getRecommendedDiskController(); // By-pass auto detected PVSCSI controller to use LsiLogic Parallel instead if (DiskControllerType.getType(recommendedController) == DiskControllerType.pvscsi) { recommendedController = DiskControllerType.lsilogic.toString(); } return recommendedController; }
private static VirtualNetworkAdapterType validateNicType(GuestOsDescriptor[] guestOsDescriptorList, String guestId, VirtualNetworkAdapterType adapterType) throws DeviceNotSupported { VirtualNetworkAdapterType result = adapterType; GuestOsDescriptor guestOsInfo = null; for (GuestOsDescriptor desc : guestOsDescriptorList) { if(desc.getId().equalsIgnoreCase(guestId)) { guestOsInfo = desc; break; } } if (adapterType == VirtualNetworkAdapterType.Unknown) { result = TryGetNetworkAdapterType(guestOsInfo); } else { if (guestOsInfo.getSupportedEthernetCard() != null) { boolean supported = false; List<String> supportedTypeList = new ArrayList<String>(); for(String supportedAdapterName : guestOsInfo.getSupportedEthernetCard()) { VirtualNetworkAdapterType supportedAdapterType = GetNetworkAdapterTypeByApiType(supportedAdapterName); supportedTypeList.add(supportedAdapterType.toString()); if (supportedAdapterType == adapterType) { supported = true; break; } } if (!supported) { DeviceNotSupported dns = new DeviceNotSupported(); dns.setDevice("Virtual NIC"); dns.setReason("The requested NIC is not supported in this OS."); throw dns; } } } return result; }
public String getRecommendedDiskController(String guestOsId) throws Exception { String recommendedController; GuestOsDescriptor guestOsDescriptor = getGuestOsDescriptor(guestOsId); recommendedController = VmwareHelper.getRecommendedDiskControllerFromDescriptor(guestOsDescriptor); return recommendedController; }