Home > Blogs > VMware PowerCLI Blog


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.

This entry was posted in Advanced on by .
Alan Renouf

About Alan Renouf

Alan Renouf is a Product Line Manager at VMware focusing on API's, SDK's and CLI's, He is responsible for providing the architects and operators of private and public cloud infrastructure with the toolkits/frameworks and command-line interfaces they require to build a fully automated software-defined datacenter. Alan is a frequent blogger at http://blogs.vmware.com/PowerCLI a book author and has a personal blog at http://virtu-al.net. You can follow Alan on twitter as @alanrenouf.

3 thoughts on “Using PowerCLI for Intra-VM Affinity rules in Storage DRS

  1. Www.best-Safari.org

    What’s up to every one, since I am genuinely eager of reading this
    website’s post to be updated daily. It contains nice stuff.

    Alsso visit my homepage – crocodile creek balliuto south africa (http://Www.best-Safari.org)

    Reply
  2. Buy Real YouTube Likes

    Thamk you for another fantastic article. The place else may anybody
    get that kind of information in such an ideal methoid of writing?

    I’ve a presentation subsequent week, and I’m at the look foor such information.

    Reply
  3. Pingback: Why a South African Safari Isnt Just for the Wild at Heart | afghanbest.com

Leave a Reply

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

*