Java 类com.vmware.vim25.SharesLevel 实例源码

项目:photon-model    文件:TestVSphereOvfProvisionTaskBase.java   
private DiskService.DiskState buildBootDiskWithCustomProperties(String cloudConfig,
        Map<String, String> customProperties) throws Throwable {
    HashMap<String, String> diskCustomProperties = new HashMap<>();

    VirtualDiskType diskProvisionType = customProperties.get(PROVISION_TYPE) != null ?
            VirtualDiskType.fromValue(customProperties.get(PROVISION_TYPE)) : null;

    if (diskProvisionType == null) {
        diskProvisionType = VirtualDiskType.THIN;
    }

    diskCustomProperties.put(DISK_MODE_PERSISTENT, "true");
    diskCustomProperties.put(PROVISION_TYPE, diskProvisionType.value());
    diskCustomProperties.put(SHARES_LEVEL, SharesLevel.HIGH.value());
    diskCustomProperties.put(LIMIT_IOPS, "100");

    DiskService.DiskState res = buildBootDisk(cloudConfig);
    res.customProperties = diskCustomProperties;

    return res;
}
项目:vijava    文件:VmAllocateResource.java   
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;
}
项目:photon-model    文件:ClientUtils.java   
/**
 * 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;
}
项目:photon-model    文件:TestVSphereLibraryProvisionTaskBase.java   
private HashMap<String, String> buildDiskCustomProperties() {
    HashMap<String, String> customProperties = new HashMap<>();

    customProperties.put(PROVISION_TYPE, VirtualDiskType.THIN.value());
    customProperties.put(SHARES_LEVEL, SharesLevel.CUSTOM.value());
    customProperties.put(SHARES, "3000");
    customProperties.put(LIMIT_IOPS, "50");
    customProperties.put(DISK_MODE_INDEPENDENT, "true");

    return customProperties;
}
项目:photon-model    文件:TestVSphereCloneTaskBase.java   
protected void verifyDiskProperties(ComputeService.ComputeState vm, GetMoRef get)
        throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    VirtualDisk vd = fetchVirtualDisk(vm, get);
    assertEquals(SharesLevel.HIGH.value(), vd.getStorageIOAllocation().getShares()
            .getLevel().value());
    int shares = 2000;
    assertEquals(shares, vd.getStorageIOAllocation().getShares().getShares());
    Long limitIops = 100L;
    assertEquals(limitIops, vd.getStorageIOAllocation().getLimit());
    VirtualDiskFlatVer2BackingInfo backing = (VirtualDiskFlatVer2BackingInfo) vd.getBacking();
    assertTrue(backing.isThinProvisioned());
}
项目:photon-model    文件:TestVSphereCloneTaskBase.java   
private HashMap<String, String> buildCustomPropertiesForCloneBoot(boolean isPersistent) {
    HashMap<String, String> customProperties = new HashMap<>();

    customProperties.put(DISK_MODE_INDEPENDENT, "true");
    customProperties.put(DISK_MODE_PERSISTENT, String.valueOf(isPersistent));
    customProperties.put(PROVISION_TYPE, VirtualDiskType.THICK.value());
    customProperties.put(SHARES_LEVEL, SharesLevel.NORMAL.value());
    customProperties.put(LIMIT_IOPS, "50");

    return customProperties;
}
项目:photon-model    文件:BaseVSphereAdapterTest.java   
protected HashMap<String, String> buildCustomProperties() {
    HashMap<String, String> customProperties = new HashMap<>();

    customProperties.put(DISK_MODE_PERSISTENT, "true");
    customProperties.put(PROVISION_TYPE, VirtualDiskType.THIN.value());
    customProperties.put(SHARES_LEVEL, SharesLevel.HIGH.value());
    customProperties.put(LIMIT_IOPS, "100");

    return customProperties;
}
项目:photon-model    文件:TestVSphereLinkedCloneProvisionTask.java   
private HashMap<String, String> buildDiskCustomProperties() {
    HashMap<String, String> customProperties = new HashMap<>();

    customProperties.put(PROVISION_TYPE, VirtualDiskType.THIN.value());
    customProperties.put(SHARES_LEVEL, SharesLevel.CUSTOM.value());
    customProperties.put(SHARES, "3000");
    customProperties.put(LIMIT_IOPS, "50");
    customProperties.put(DISK_MODE_INDEPENDENT, "true");

    return customProperties;
}
项目:cs-actions    文件:VmUtils.java   
<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;
}
项目:cs-actions    文件:VmUtils.java   
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);
    }
}
项目:photon-model    文件:TestVSphereLibraryProvisionTaskBase.java   
protected void verifyDiskProperties(ComputeService.ComputeState vm, GetMoRef get)
        throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    VirtualDisk vd = fetchVirtualDisk(vm, get);
    assertEquals(SharesLevel.CUSTOM.value(), vd.getStorageIOAllocation().getShares().getLevel().value());
    Long limitIops = 50L;
    assertEquals(limitIops, vd.getStorageIOAllocation().getLimit());
    VirtualDiskFlatVer2BackingInfo backing = (VirtualDiskFlatVer2BackingInfo) vd.getBacking();
    assertTrue(backing.isThinProvisioned());
}
项目:vijava    文件:DrsVmShares.java   
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.");
}