0 0

Ask Rick: QoS and VMware Tags

Is there a way to use VMware tags to set VMstore quality of service (QoS)?

Emad Younis asked me this the other day. Here's my answer, which includes a script.

One of my favorite Tintri OS features is per-VM QoS. In a previous blog, I discussed how to use TGC Service Groups to set QoS. In this post, I will look at using VMware VM tags to set QoS on VMstore.

Custom VMware tags were introduced in vCenter Server 5.1. Tags can be categorized and added to any inventoried objects in your VMware environment. In PowerCLI 5.5R1, cmdlets were introduced for working with tags. For more information, check out "Using Tags with PowerCLI" and "Tagging Objects in the vSphere Web Client".

This script also uses a configuration file which maps a VMware tag to minimum and maximum storage QoS values. An example configuration file, StorageServiceConfig.txt, is provided here:

#name  min IOPs Max IOPs
#----  ------- -------
gold   1000    1500
silver 500     1000
bronze 100     500

From the above example, the format is: tag name, minimum IOPs, and maximum storage IOPs separated by spaces or tabs. The tag name must start in first character of the line. Beginning the line with "#" makes the line a comment. I used a text file; however, you are free to use a comma separated file or a database.

Most of the examples I code are in Python, but this time I used PowerShell because of the ease of connecting to vCenter and obtaining the VMware tags. The first part of the script reads the configuration file and parses it into storage service objects. I'm not going to discuss the file code here, because I want to discuss the crux of the script.

After a connection to the Tintri VMstore is successful, all the VMs that use the specified VMstore for storage are obtained.

# Connect to the Tintri server.
# Password will be requested in a Windows pop-up.$conn = Connect-TintriServer -Server $tintriServer -UserName $user
if (!$conn)
{
    Throw "Connection Error"
}

$myHost = $conn.ApplianceHostName
Write-Verbose "Connected to $myHost."

$vms = Get-TintriVM
if (!$vms)
{
    Disconnect-TintriServer -TintriServer $conn
    Throw "No VMs"
}

For each VM, the VM name, the vCenter that is managing the VM, and the minimum and maximum IOPs are collected.

    $vms | ForEach-Object -Process {
        $vmName = $($_.Vmware.Name)
        $vCenterName = $($_.Vmware.VcenterName)
        $minIOPs = $($_.QosConfig.MinNormalizedIops)
        $maxIOPs = $($_.QosConfig.MaxNormalizedIops)

Next the code checks if there is a connection to the vCenter or not. If there is no connection, then one is made utilizing the Connect-vCenter function. In Connect-vCenter, the PowerCLI cmdlet Connect-VIServer, is used to connect to the vCenter.

Function Connect-vCenter {
    param(
        [String]$vCenterName,
        [String]$vCenterUser
        )

    Write-Host"Attempting $vCenterName with$vCenterUser"
    $vc_conn = Connect-VIServer -Server $vCenterName -User $vCenterUser
    if (!$vc_conn) {
        Write-Error"Couldn't connect to vCenter $vCenterName."
        Exit
    }
    Write-Verbose"Connected to vCenter $vCenterName as user $vCenterUser."
    return $vc_conn
}

The vCenter connection is saved for future use. With the vCenter connection, the tag value is obtained.

$tagName = $(Get-TagAssignment -Server $vc_conn -Category Storage-QOS -Entity $vmName).Tag.Name

The Category parameter specifies the category of the tag; and in this case, the category is "Storage-QOS". In this example, only one tag is in the "StorageQOS" category. The Entity can be any vCenter object, but our case, it is the VM's name. So the Get-TagAssigment cmdlet returns the tag information associated with the VM entity in the Storage-QOS category. Finally, to obtain the tag name, you have to reference .Tag.Name.

If there is no tag, the QoS is cleared. If there is a tag and the tag matches a storage service name, then the QoS is set to the minimum and maximum IOP values in the storage service, else nothing is done. Note that the QoS values are only set if there is a difference between the storage service IOP values and the current VM's IOP values.

        if (!$tagName)
        {
            Write-Host"No tag name, clear QoS"
            if ($minIOPs -ne 0 -or $maxIOPs -ne 0)
            {
                Write-Host"Setting to infinity and beyond."Set-TintriVMQOS -VM $_ -ClearMinNormalizedIops -ClearMaxNormalizedIops
            }
        }
        elseif (!$ss[$tagName])
        {
            Write-ErrorNo storage service named $tagName."
        }
        elseif ($ss[$tagName].MinIOPs -ne $minIOPs -or $ss[$tagName].MaxIOPs -ne $maxIOPs)
        {
           Write-Host"Setting VM $vmName to ($ss[$tagName].MinIOPs, $ss[$tagName].MaxIOPs)"Set-TintriVMQOS -VM $_ -MaxNormalizedIops $ss[$tagName].MaxIOPs -MinNormalizedIops $ss[$tagName].MinIOPs

After all the VMs have been processed, the connections are closed to all the vCenters and the VMstore.

This code is located at QoSFromVmwareTag.ps1 on the Tintri GitHub site.

Enjoy tagging for IOPs,

- Rick -

Temporary_css