VMware Cloud Community
Onthax
Contributor
Contributor
Jump to solution

changing vm storage drs automation level

As per http://communities.vmware.com/message/2172311#2172311

I'm using LucD's method, to extract a list of vm's that have vm's turned on

function Get-StoragePod{
<#
.SYNOPSIS  Find a DatastoreCluster
.DESCRIPTION The function will return a StoragePod object.
  This is the server-side object used by vSphere for a  DatastoreCluster.
.NOTES  Author:  Luc Dekens
.PARAMETER Name  The name of the DatastoreCluster
.EXAMPLE
  PS> Get-StoragePod
.EXAMPLE
  PS> Get-StoragePod -Name "SDC*"
#>
  param(
  [CmdletBinding()]
  [parameter(Position = 0, ValueFromPipeline = $true)]
  [string]$Name = "*"  )
  begin{
   function Get-StoragePodInternal{
     param(
     [CmdletBinding()]
     [parameter(Mandatory = $true,ValueFromPipeline = $true)]
     [VMware.Vim.Folder]$Folder     )
     $Folder.ChildEntity | %{
       if($_.Type -eq "StoragePod"){
         Get-View -Id $_       }
       elseif($_.Type -eq "Folder"){
         Get-View -Id $_ | Get-StoragePodInternal
       }
     }
    }
  }
  process{
    Get-Folder -Name datastore | %{
      Get-StoragePodInternal -Folder $_.ExtensionData
    } | where {$_.Name -like $Name}
  }
}
$dsc = Get-StoragePod -Name $datastorecluster
$vmlist = $dsc.PodStorageDrsEntry.StorageDrsConfig.VmConfig | where {$_.Enabled -notmatch "False"} | Select @{N="VM";E={(Get-View $_.VM).Name}},Enabled,IntraVmAffinity | where {$_.VM -like "*_replica"}

This successfully gets a list of vm's that have sdrs enabled that shouldnt.

I'm struggling with how to disable sdrs.  I'm new to powershell

from what i can gather i need to update dsc.podstoragedrsentry.storagedrsconfig.vmconfig.enabled to False.

but i'm unsure how to do this, or could point me in the right direction?

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You will have to use the ConfigureStorageDrsForPod_Task method to change the settings for SDRS.

In the StorageDrsConfigSpec object you can disable this.

Combined with your Where-clause this could be something like this

$storMgr = Get-View StorageResourceManager

$pod
= Get-DatastoreCluster -Name $datastorecluster
$spec
= New-Object VMware.Vim.StorageDrsConfigSpec $pod.ExtensionData.PodStorageDrsEntry.StorageDrsConfig.VmConfig | where {(Get-View $_.VM | Select -ExpandProperty Name) -like "*_replica"} | %{   $entry = New-Object VMware.Vim.StorageDrsVmConfigSpec
  $entry.Operation = "edit"
  $entry.Info = $_
 
$entry.Info.Enabled = $false
  $spec.vmConfigSpec += $entry
} $storMgr.ConfigureStorageDrsForPod($pod.ExtensionData.MoRef,$spec,$true)

Note that the Get-DatastoreCluster cmdlet can be used to replace my function


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
22 Replies
LucD
Leadership
Leadership
Jump to solution

You will have to use the ConfigureStorageDrsForPod_Task method to change the settings for SDRS.

In the StorageDrsConfigSpec object you can disable this.

Combined with your Where-clause this could be something like this

$storMgr = Get-View StorageResourceManager

$pod
= Get-DatastoreCluster -Name $datastorecluster
$spec
= New-Object VMware.Vim.StorageDrsConfigSpec $pod.ExtensionData.PodStorageDrsEntry.StorageDrsConfig.VmConfig | where {(Get-View $_.VM | Select -ExpandProperty Name) -like "*_replica"} | %{   $entry = New-Object VMware.Vim.StorageDrsVmConfigSpec
  $entry.Operation = "edit"
  $entry.Info = $_
 
$entry.Info.Enabled = $false
  $spec.vmConfigSpec += $entry
} $storMgr.ConfigureStorageDrsForPod($pod.ExtensionData.MoRef,$spec,$true)

Note that the Get-DatastoreCluster cmdlet can be used to replace my function


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Onthax
Contributor
Contributor
Jump to solution

Cheers Mate!

That's just what i needed, need to learn a bit more powershell to fully follow how to replicate how you did this but thanks :^)

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

As a matter of fact this is PowerShell/PowerCLI using one the SDK API to change the settings.

Not all vSphere API are available through PowerCLI cmdlets, but it is quite easy to call the SDK API directly from within PowerCLI/PowerShell.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Onthax
Contributor
Contributor
Jump to solution

This script seemed to be working as expected, but recently I noticed that New VM's that are added to the datastore cluster won't appear when you run $pod.ExtensionData.PodStorageDrsEntry.StorageDrsConfig.VmConfig

I haven't been able to get them detected and working, Does anyone know if there is anything that needs to be done after adding a vm to have it appear from powercli when looking at members of a SDRS cluster?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I suspect that the new information is not present.

Remember that the objects you get in PowerCLI are read-only copies.

You can force a refresh with

$pod.ExtensionData.UpdateViewData()

Does that help ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Onthax
Contributor
Contributor
Jump to solution

Thanks for the quick response LucD

No luck,

Ran $pod.ExtensionData.UpdateViewData() then  $pod.ExtensionData.PodStorageDrsEntry.StorageDrsConfig.VmConfig

the new VM won't show in powercli, however shows fine in GUI

Any idea on how often it refreshes?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The PowerCLI object does not refresh, unless you do an UpdateViewData.

Did you try fetching the datastorecluster object again

$pod = Get-DatastoreCluster -Name $datastorecluster


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Cruckman4
Contributor
Contributor
Jump to solution

I'm having the same problem where newly added VMs to the datastore cluster failed to show up in ~StorageDrsConfig.VmConfig.  One way I've found to get them to show up is to enable/disable storage DRS from vSphere Client on the datastore cluster.  For some reason, after doing that from the vSphere GUI, the VMs show up then in ~StorageDrsConfig.VmConfig.  I tried using Set-DatastoreCluster to change the sdrsautomationlevel to manual / disabled, but no luck in getting the VMs to show up.  So far, only after editing the datastore cluster settings from vSphere client.  Not sure if it might be an issue with the vCenter Server not passing the information along or what.  I'd be curious to know what versions you're using.  I'm using ESXi 5.1U1, vCenter Server 5.1U1, and PowerCLI 5.1 release 1.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The changes you make in vCenter are not automatically done in your PowerCLI variables.

You will have to get the object again, or refresh the ExtensionData property with the UpdateViewData method.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Cruckman4
Contributor
Contributor
Jump to solution

Sorry, forgot to mention that I re-fetched the datastore cluster object after adding VMs to it, and also after changing the sdrsautomationlevel with Set-DatastoreCluster. Unfortunately, it still had nothing in ~.StorageDrsConfig.VmConfig.  Only after making the changes in vCenter and getting the object again after making the changes did the VMs finally show up in ~.StorageDrsConfig.VmConfig.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The ExtensionData property is handled a bit differently, compared to regular PowerShell variables and their properties.

Did you also try with the UpdateViewData method as I suggested ?

It might be a caching problem.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Cruckman4
Contributor
Contributor
Jump to solution

Yeah, I tried that too to no avail Smiley Sad

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I'll check if I can reproduce that


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Onthax
Contributor
Contributor
Jump to solution

Hi LucD

I tried $pod.ExtensionData.PodStorageDrsEntry.StorageDrsConfig.VmConfig

then

$pod.ExtensionData.UpdateViewData()

then

$pod = Get-DatastoreCluster -Name $datastorecluster

The VM still doesnt appear when I do a $pod.ExtensionData.PodStorageDrsEntry.StorageDrsConfig.VmConfig

VM was added more than a week ago, so it doesnt seem to be an internal refresh timer.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I did some more tests, and I can confirm the behavior you are seeing.

When a new VM is created on the datastorecluster it is not automatically added to the VmConfig array as a StorageDrsVmConfigInfo entry.

The fact that you see it in the vSphere client is due to the defaults (see for example the description of the enabled property).

I'm not sure if this is intentional or a "feature".

My guess is that this is intentional, as long as you don't divert from the defaults, there is no need to create an entry.

Perhaps some SDRS wizard can shine his light on this ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Onthax
Contributor
Contributor
Jump to solution

Just checking tho, there is no way to update this from the VM side?

Reply
0 Kudos
rajan2a
Contributor
Contributor
Jump to solution

Hi!

I am getting below errors while running this script, though sometimes it do the changes in VM SDRS automation but throwing this error.

Exception calling "ConfigureStorageDrsForPod" with "3" argument(s): "The object has already been deleted or has not been completely created"

At line:1 char:1

+ $storMgr.ConfigureStorageDrsForPod($pod.ExtensionData.MoRef,$spec,$true)

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : VimException

Reply
0 Kudos
jesse_gardner
Enthusiast
Enthusiast
Jump to solution

Hi rajan.  I am getting the same errors occasionally though, as you say, sometimes the rule gets correctly created.  Have you found any workaround or root cause?

Reply
0 Kudos
cans
Contributor
Contributor
Jump to solution

Hi,

Sorry to update this thread, but I need to put all my automation level to 'default'.

When VM are in Default mode, seems that everything is empty, example:

Vm              : VirtualMachine-vm-13297
Enabled         :
Behavior        :
IntraVmAffinity :

IntraVmAntiAffinity :

LinkedView      :
DynamicType     :
DynamicProperty :

So I Try to do the same thing with a StorageDrsVmConfigSpec:

$storMgr = Get-View StorageResourceManager

$spec = New-Object VMware.Vim.StorageDrsConfigSpec

$dsc = Get-Datastorecluster DS1

$dsc.ExtensionData.PodStorageDrsEntry.StorageDrsConfig.VmConfig |%{

$entry = New-Object VMware.Vim.StorageDrsVmConfigSpec

$entry.Operation = "edit"

$entry.Info = $_

$entry.Info.Enabled = ""

$entry.Info.Behavior = ""

$entry.Info.IntraVMAffinity = ""

$spec.vmConfigSpec += $entry

}

$storMgr.ConfigureStorageDrsForPod($dsc.ExtensionData.MoRef,$spec,$true)

But ... no luck:

Exception calling "ConfigureStorageDrsForPod" with "3" argument(s): "A specified parameter was not correct.

spec"


Any idea ? 🙂

Reply
0 Kudos