Advanced

Using PowerCLI for Intra-VM Affinity rules in Storage DRS

AlanFeb2012_thumb
Posted by
Alan Renouf
Technical Marketing

Recently Frank Denneman posted an excellent article on Storage DRS and particularly the impact of Intra-VM affinity rules on storage DRS, if you are using Storage DRS or thinking about implementing it or even just like to keep up with the latest vSphere 5 features I strongly suggest reading his article here.

You may have noticed some PowerCLI code on his post which explains how to disable the Intra-VM affinity rule for each Datastore Cluster, I wanted to expand on this a little, as Frank mentioned, there is currently no GUI setting for this feature so we need to rely on the CLIs to help change this.

Below you will find a number of examples on how to use a function called Set-DatastoreClusterDefaultIntraVmAffinity which was created to ease you in enabling and disabling this feature, with the below code we can also list each Datastore Cluster and see if this feature is indeed Enabled or Disabled currently.

Examples

In PowerCLI 5.0 we introduced a new Cmdlet called Get-DatastoreCluster, this can be used to list the Datastore Clusters which currently exist in your vSphere Environment, using this cmdlet we can easily add our hash-table which displays the current Intra-VM Affinity setting:

The code is listed below for you to be able to copy and paste:

Get-DatastoreCluster | Select Name, @{N="DefaultIntraVmAffinity";E={($_ | Get-View).PodStorageDRSEntry.StorageDRSConfig.PodConfig.DefaultIntraVmAffinity}}

SNAGHTML36f26e2

Once listed we can use a PowerShell Advanced Function to disable or enable this setting, the function is listed below for you to copy and paste as needed:

function Set-DatastoreClusterDefaultIntraVmAffinity{
    param(
        [CmdletBinding()]
        [parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true)]
        [PSObject]$DSC,
        [Switch]$Enabled
     )

      process{
        $SRMan = Get-View StorageResourceManager
        if($DSC.GetType().Name -eq "string"){
          $DSC = Get-DatastoreCluster -Name $DSC | Get-View
        }
        elseif($DSC.GetType().Name -eq "DatastoreClusterImpl"){
          $DSC = Get-DatastoreCluster -Name $DSC.Name | Get-View
        }
            $spec = New-Object VMware.Vim.StorageDrsConfigSpec
            $spec.podConfigSpec = New-Object VMware.Vim.StorageDrsPodConfigSpec
            $spec.podConfigSpec.DefaultIntraVmAffinity = $Enabled
            $SRMan.ConfigureStorageDrsForPod($DSC.MoRef, $spec, $true)
    }
}

Once this function has been run we can easily use it to firstly disable the feature:

SNAGHTML372e782

And also, if needed we can re-enable this feature by using the same function:

SNAGHTML373846d

Hopefully this shows you that sometimes we don’t have to wait for features and settings to arrive in the GUI before we can use them, sometimes we can rely on the CLIs to help us out.