Query vRAM

After the Cloud Infrastructure Launch Forum event from July 12th 2011, it seemed that the new licensing model attracted more blog posts and tweets than the 140 new features in vSphere 5.

As one could imagine, one of the most heard questions was, what will I need to pay in the new licensing model. As a pro-active measure, I decided to write a short script that would tell me what vRAM entitlement my current vSphere 4 licenses would offer me.

Update August 4th 2011 08:30: VMware updated the vRAM calculation specifications. See the VMware vSphere™ 5.0 Licensing, Pricing and Packaging White Paper.

Update July 13th 2011 14:45: Apparently you have a vRAM pool per license type. I updated the script.

The script

function Get-vRAMInfo{
  $memoryCapMB = 96 * 1KB
  $vRAMtab = @{
    "esxEssentials"=32;
    "esxEssentialsPlus"=32;
    "esxFull"=32;
    "esxAdvanced"=32;
    "esxEnterprise"=64;
    "esxEnterprisePlus"=96
  }

  $licMgr = Get-View LicenseManager
  $licAssignMgr = Get-View $licMgr.LicenseAssignmentManager

  $totals = @{}

  Get-VMHost | %{
    $lic = $licAssignMgr.QueryAssignedLicenses($_.Extensiondata.MoRef.Value)
    $licType = $lic[0].AssignedLicense.EditionKey
    $totalvRAM = ($vRAMtab[$licType] * $_.Extensiondata.Hardware.CpuInfo.NumCpuPackages)

    $VMs = Get-VM -Location $_
    $vmRAMConfigured = ($VMs | `
    Select -Property @{N="CappedMemoryMB";
      E={if($_.MemoryMB -lt $memoryCapMB){$_.MemoryMB}else{$memoryCapMB}}} | `
      Measure-Object -Property CappedMemoryMB -Sum).Sum/1KB
    $vmRAMUsed = ($VMs | where {$_.PowerState -eq "PoweredOn"} | `
      Select -Property @{N="CappedMemoryMB";
      E={if($_.MemoryMB -lt $memoryCapMB){$_.MemoryMB}else{$memoryCapMB}}} | `
      Measure-Object -Property CappedMemoryMB -Sum).Sum/1KB

    if($totals.ContainsKey($licType)){
      $totals[$licType].vRAMEntitled += $totalvRAM
      $totals[$licType].vRAMConfigured += $vmRAMConfigured
      $totals[$licType].vRAMUsed += $vmRAMUsed
    }
    else{
      $totals[$licType] = New-Object PSObject -Property @{
        vCenter = $defaultVIServer.Name
        LicenseType = $lic[0].AssignedLicense.Name
        vRAMEntitled = $totalvRAM
        vRAMConfigured = $vmRAMConfigured
        vRAMUsed = $vmRAMUsed
      }
    }
  }
  $totals.GetEnumerator() | %{
    New-Object PSObject -Property @{
      vCenter = $_.Value.vCenter
      LicenseType = $_.Value.LicenseType
      vRAMEntitled = $_.Value.vRAMEntitled
      vRAMConfigured = [Math]::Round($_.Value.vRAMConfigured,1)
      vRAMUsed = [Math]::Round($_.Value.vRAMUsed,1)
    }
  }
}

Annotations

Line 3-7:  The vRAM entitlement per type of license is stored in a hash tab.

Line 6: The script doesn’t take into account that the Advanced licenses will be converted to Enterprise.

Line 16: Note, the current version of the script only uses allocated licenses to calculate your vRAM entitlement. If you happen to have unallocated licenses, they will currently not be reflected in your vRAM entitlement.

Line 17: The script uses the QueryAssignedLicenses method. Unfortunately this only works for vSphere 4.1 and higher.

Line 22: Calculate the amount of configured RAM for the guests. This will give the potential maximum vRAM you could need.

Line 23: Calculate the amount of RAM used by powered on guests

Sample run

Just call the function: Get-vRAMInfo.

It will produce something like this.

If your vRAMUsed amount turns out to be higher than your vRAMEntitled amount, you will have to acquire extra licenses.

In my test environment I don’t need additional licenses :lol:

60 thoughts on “Query vRAM

  1. Pingback: EnterpriseAdmins.org » Blog Archive » PowerCLI vCheck 5.47 – Additional RAM checks

  2. I’m admitted new to Powershell. I’m having a bit of trouble with this function. I’ve connected to my vcenter(v4.1), I’ve sourced the Powershell script, but I am receiving several errors.

    Get-View : Cannot validate argument on parameter ‘Id’. The argument is null or
    empty. Supply an argument that is not null or empty and then try the command ag
    ain.
    At C:\cdns\bin\Get-vRamInfo.ps1:13 char:27
    + $licAssignMgr = Get-View <<<< $licMgr.LicenseAssignmentManager
    + CategoryInfo : InvalidData: (:) [Get-View], ParameterBindingVal
    idationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutom
    ation.Commands.DotNetInterop.GetVIView

    You cannot call a method on a null-valued expression.
    At C:\cdns\bin\Get-vRamInfo.ps1:18 char:47
    + $lic = $licAssignMgr.QueryAssignedLicenses <<<< ($_.Extensiondata.MoRef.V
    alue)
    + CategoryInfo : InvalidOperation: (QueryAssignedLicenses:String)
    [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    Cannot index into a null array.
    At C:\cdns\bin\Get-vRamInfo.ps1:19 char:21
    + $licType = $lic[ <<<< 0].AssignedLicense.EditionKey
    + CategoryInfo : InvalidOperation: (0:Int32) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

    I'm sure I'm missing something.

    • @Korey, let’s start from the beginning.
      Did you connect to the vCenter before running the script ?

      Connect-VIServer -Server MyVC

  3. I’ve just installed the PowerCLI (VMware-PowerCLI-4.1.1-332441). Unfortunately when I run your script nothing at all is happening. Any ideas?

    • @Aaron, are you running this against a vSphere 4.1 installation ?
      Unfortunately the script will not work for pre-4.1 versions.

  4. Pingback: Update on VMware vSphere 5 licensing

  5. Pingback: Mise à jour du licensing de VMware vSphere 5

  6. Pingback: Third Quarter 2011 Meeting – Followup « Triad VMUG

  7. Pingback: How to Save With New vSphere 5 Licensing Model | DoubleCloud.org

  8. Pingback: ???? ?????? ????? ?? vSphere 5.0, ??? ????? vRAM | ????

  9. Pingback: VMnerds blog » les modes de licence vSphere 5

  10. Pingback: Licensing: Pools and Architecture Changes? | The Virtualization Practice

  11. Hi Luc,
    very good job!
    I’d only like the script to take into account not only the currently assigned CPU licenses, but also the unassigned ones, because they would also add up to the vRAM entitlements with vSphere 5.
    - Andreas

  12. Pingback: Welcome to vSphere-land! » vSphere 5 Links

  13. Thanks for making this available. A quick upgrade to our PowerCLI and it worked perfectly.

    Thankfully no new licenses needed for us at this stage.

  14. Well,

    I guess currently we are about 106 pCPU – with 1928 GB of vRam. By upgrading our licenses we are at 5088 GB of Entitled vRAM (All ent + shop). We planned on migrating/consolidating our clusters to only 42 CPU’s total which would put us right at 2016 if we did it after migrating. This means we would have to purchase more licenses for future capacity. But if we upgraded all our licenses (which wont happen) we wouldn’t have to worry about a thing. So in the long run it doesn’t really affect shops and there is also not a lot of information on prior vsphere 4 updating cost. I am under the impressions we negotiated our licenses to vSphere 4 prior but just have completed the upgrade. Either way we are going to have to be more tactical to not put ourselves in a bind.

  15. I would love to post mine to show how much this licensing model is going to screw us over but obviously we aren’t all 4.1 like some people ;). I already had a colleague say to me on the phone “I have to budget for 40 more licenses for our p2v for the rest of our environment is going to have to wait, we weren’t scaling out, we were scaling up” – Sadly, for some folks they are going to look else where especially in businesses where low cost is important like logistics. I will post mine but I am sure ours will probably fall into the vmware sweet spot – lol.

  16. too bad its just for 4.1 – that kind of sucks imo.

    We have a very diverse environment even some host on 3.5 still. Anyways, I am sure we wont be paying more but this def changes the name of the game for us because we gage on capacity not vRAM.

  17. For some reason I my vSphere 4 Standard licenses are reporting as the edition type “esxFull” instead of esxStandard

    To fix I added the follow line to the $vRAMtab array:
    “esxFull”=24;

    Without that line my vRAMEntitled amount for vSphere Standard was not displaying a value.

    • @OfficeGlen, thanks for the info. I updated the table.
      As you can imagine I don’t have all the license types present in my test environment :-)

      If some of the other licensekeys are not correct, please let me know!

  18. Thanks for writing this

    Seems to imply you can make more efficient use of your entitlement by ratcheting down the unused memory allocation per VM
    (Therefore a script to show the most overallocated VMs in terms of memory would logically be next!?)

    • @John, did you run the script against a pre-4.1 vCenter ?
      For pre-4.1 the current script will not work due to the differences in the LicenseManager methods in the API.

  19. Pingback: vSphere 5 Licensing “Evolution” | A Sys Admin Blog

  20. Pingback: Links for your vSphere 5 Appetit « Sudrsn's Blog

    • That’s the reason, pre 4.1 the vSphere License Manager is different.
      The call the script makes to collect the license information will not return anything.
      Let me check if I can script pre 4.1 support for the script.

    • The current script only will work for vSphere 4.1 and higher. The reason is that the QueryAssignedLicenses method doesn’t work for earlier vSphere versions :-(

  21. @LucD
    I’m getting the same results as Benjamin. I’ve ran connect-viserver and I’m using snapin version:
    VMWare vSphere PowerCLI 4.1 U1 build 332441

    Ideas?

    • @Andy, in our environment we are covered, no need to acquire extra licenses.
      But as it was mentioned in other fora and tweets, it all depends (size of your VMs, type of licenses you currently have, your VM density per processor…).
      I’m sure the last word about this hasn’t been said yet :-)

  22. Are you using only the powercli snap-in? I run this and no output at all, just returns to the command line.

    • @Benjamin, the script only uses the (latest) PowerCLI snapin.
      And you have to have made the connection to the vCenter before calling the function.

      Connect-VIServer -Server myVC

  23. Pingback: VMware vSphere 5 Licensing: My Thoughts | Dan Hayward

  24. Hi Luc and Hugo,

    Great scripts. But since you’re querying the VMs anyway, maybe also query how much RAM on average they really use. So it will tell me that the VM I gave 6GB only uses 4GB. And that I can save 2GB on that VM.

    Gabrie

    • Thanks Duncan, that is indeed a good idea and would provide some actual input to the theoretical discussion that is going on since yesterday.

  25. “Increasing the Pooled vRAM Capacity
    If necessary, the easiest way to expand pooled vRAM capacity
    is to add more vSphere CPU licenses of the same edition to
    the vRAM pool. Alternatively, customers can upgrade all CPU
    licenses in the vRAM pool to a vSphere edition with a higher
    base vRAM entitlement.”

    I do not see where it says one way or another if you are able to have multiple vRAM pools on the same vCenter server or Linked vCenter Servers. They imply that if you have a vCenter server or linked vCenter servers they work as a single vRAM pool/entitlement. But also give indication based on management of pools that it is vCenter server specific.

    It does seem reasonable however that you could have multiple vCenter servers at different licensing levels.

    “As long as the total consumed
    vRAM across all virtual machines managed by a VMware vCenter
    instance or multiple linked VMware vCenter instances is less or
    equal to the total available vRAM, vSphere is correctly licensed.”

    In conclusion I’d say it goes as follows:
    1. Each vCenter server has one level of licensing and that vCenter server has it’s own vRAM pool.
    2. If you have multiple vCenter servers linked then you can share memory between the vRAM pools to come up with your total vRAM entitlement.
    3. You can add a license on any of your linked vCenter servers to increase your overall vRAM entitlement but my gut tells me that could let people cheat on feature differences between versions.

    If this is the case then management of this will be a nightmare without some really good tools.

    • @Josh, that was my interpretation as well at first, but the majority of the commenters seem to agree that there is a vRAM pool per license type.
      Perhaps VMware will release a clarification statement in the coming hours/days.

  26. @LucD
    Hi Luc … The other folks are correct – check the last paragraph on Page 7 of the PDF:
    “Note that all hosts in a vRAM pool must be licensed with the same vSphere edition or, in other terms, vRAM entitlements are pooled by vSphere Edition. It is possible to manage mixed environments of hosts licensed with different vSphere Editions from the same
    vCenter, however this will create multiple vRAM pools. vRAM capacity can only be shared among servers licensed with the same vSphere Edition.”

    • Rob/Mark/Dan/Didier, thanks for the confirmation.
      I updated the script, it now returns the vRAM pool information per license type.
      At least I learned something today :-)

  27. @LucD

    Hello again :)

    It’s in the Q&A bit at the end, as well as other places:

    Q: What is the available pooled vRAM capacity of my environment?
    A: Available pooled vRAM is equal to the sum total of vRAM entitlements for all vSphere licenses of a single edition, managed by a single instance of VMware vCenter Server or by multiple instances of VMware vCenter Server in Linked Mode.

    Dan

  28. Pingback: VMware vSphere 5 licensing: the opinions and math | UP2V

  29. @LucD

    Hey Luc,
    Licenses have to be of the same type, you can’t pool “standard” with “enterprise plus” from what I’ve read.
    Also, it appears vRAMused should not exceed vRAMEntitled rather than vRAMConfigured as the licensing documents say that “when a VM is powered on, the vRAM configured counts against the vRAM entitlement”…

    Dan

    • @Dan, thanks for the vRAMUsed remark. That was indeed a typo in the last paragraph. It’s corrected.
      On the vRAM pooling principle, I’m not sure that you can’t mix license types in the calculation of the vRAM pool. I have reread the white paper, but can’t find where it says this explicitely. Please correct me if I’m wrong, this is new for all of us I assume ;-)

    • Lol. Giving the number of required licenses is indeed a great feature, but I deliberately left that out, because I think that the pooled vRAM concept, offers the possibility to acquire extra licenses to increase the total vRAM, not necessarily of the same type.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>