static ResourceAllocationInfo getShares(String val) throws Exception { ResourceAllocationInfo raInfo = new ResourceAllocationInfo(); SharesInfo sharesInfo = new SharesInfo(); if("high".equalsIgnoreCase(val)) { sharesInfo.setLevel(SharesLevel.high); } else if("normal".equalsIgnoreCase(val)) { sharesInfo.setLevel(SharesLevel.normal); } else if("low".equalsIgnoreCase(val)) { sharesInfo.setLevel(SharesLevel.low); } else { sharesInfo.setLevel(SharesLevel.custom); sharesInfo.setShares(Integer.parseInt(val)); } raInfo.setShares(sharesInfo); return raInfo; }
/** * Constructs storage IO allocation if this is not already dictated by the storage policy that * is chosen. */ public static StorageIOAllocationInfo getStorageIOAllocationInfo( DiskService.DiskStateExpanded diskState) throws NumberFormatException { if (diskState.customProperties != null) { String sharesLevel = diskState.customProperties.get(SHARES_LEVEL); // If the value is null or wrong value sent by the caller for SharesLevel then don't // set anything on the API for this. Hence default to null. if (sharesLevel != null) { try { StorageIOAllocationInfo allocationInfo = new StorageIOAllocationInfo(); SharesInfo sharesInfo = new SharesInfo(); sharesInfo.setLevel(SharesLevel.fromValue(sharesLevel)); if (sharesInfo.getLevel() == SharesLevel.CUSTOM) { // Set shares value String sharesVal = diskState.customProperties.get(SHARES); if (sharesVal == null || sharesVal.isEmpty()) { // Reset to normal as nothing is specified for the shares sharesInfo.setLevel(SharesLevel.NORMAL); } else { sharesInfo.setShares(Integer.parseInt(sharesVal)); } } allocationInfo.setShares(sharesInfo); String limitIops = diskState.customProperties.get(LIMIT_IOPS); if (limitIops != null && !limitIops.isEmpty()) { allocationInfo.setLimit(Long.parseLong(limitIops)); } return allocationInfo; } catch (Exception e) { logger.warn("Ignoring the storage IO allocation customization values due to {}", e.getMessage()); return null; } } } return null; }
<T> SharesInfo getSharesInfo(T value) throws Exception { SharesInfo sharesInfo = new SharesInfo(); if (InputUtils.isInt((String) value)) { sharesInfo.setLevel(SharesLevel.CUSTOM); sharesInfo.setShares(Integer.parseInt((String) value)); } else { setSharesInfoLevel((String) value, sharesInfo); } return sharesInfo; }
private void setSharesInfoLevel(String value, SharesInfo sharesInfo) throws Exception { String level = Level.getValue(value); if (SharesLevel.HIGH.toString().equalsIgnoreCase(level)) { sharesInfo.setLevel(SharesLevel.HIGH); } else if (SharesLevel.NORMAL.toString().equalsIgnoreCase(level)) { sharesInfo.setLevel(SharesLevel.NORMAL); } else { sharesInfo.setLevel(SharesLevel.LOW); } }
public static void main(String[] args) throws Exception { if(args.length!=3) { System.out.println("Usage: DrsVmShares url username password"); System.exit(-1); } URL url = null; try { url = new URL(args[0]); } catch ( MalformedURLException urlE) { System.out.println("The URL provided is NOT valid. Please check it."); System.exit(-1); } String username = args[1]; String password = args[2]; String vm1_oid = "vm-26"; // The reference ID for VM 1 String vm2_oid = "vm-28"; // The reference ID for VM 2 // initialize the system, set up web services ServiceInstance si = new ServiceInstance(url, username, password, true); // create a new VirtualMachineConfigSpec for VM1 VirtualMachineConfigSpec vmcs1 = new VirtualMachineConfigSpec(); ResourceAllocationInfo rai1 = new ResourceAllocationInfo(); SharesInfo si1 = new SharesInfo(); si1.setLevel(SharesLevel.custom); si1.setShares(1333); rai1.setShares(si1); vmcs1.setCpuAllocation(rai1); // do the same for VM2 VirtualMachineConfigSpec vmcs2 = new VirtualMachineConfigSpec(); ResourceAllocationInfo rai2 = new ResourceAllocationInfo(); SharesInfo si2 = new SharesInfo(); si2.setLevel(SharesLevel.high); rai2.setShares(si2); vmcs2.setCpuAllocation(rai2); ManagedObjectReference vm1_mor = createMOR("VirtualMachine", vm1_oid); ManagedObjectReference vm2_mor = createMOR("VirtualMachine", vm2_oid); VirtualMachine vm1 = (VirtualMachine) MorUtil.createExactManagedEntity(si.getServerConnection(), vm1_mor); VirtualMachine vm2 = (VirtualMachine) MorUtil.createExactManagedEntity(si.getServerConnection(), vm2_mor); // make a web service call to set the configuration. vm1.reconfigVM_Task(vmcs1); vm2.reconfigVM_Task(vmcs2); // log out from web service si.getServerConnection().logout(); System.out.println("Done with setting VM CPU shares."); }