UberGeek1
Enthusiast
Enthusiast

Create and Configure StorageDRS Cluster Completely in Code

So I'm racking my brain on this one.  I'm trying to create the StorageDRS cluster and perform all of the config via code, and because not everything is in CmdLets yet, I still have to use ConfigSpecs and StorageResourceManager.  So what I'm fighting is I keep running into this error everytime I try to perform the ConfigureStorageDrsForPod action:

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

I will put the code at the bottom, but I can confirm that the Datastore Cluster does in fact exist and that this code does something because I can see the reconfigure event in vCenter, but sure trying to figure out where the failure is here.

For reference, $dCenter is set to a valid Datacenter object in my vCenter.

$dscName = "$($dCenter.Name)_DSC1"
$dsc = New-DatastoreCluster -Name $dscName -Location $dCenter
$dsc = $dsc | Set-DatastoreCluster -SdrsAutomationLevel FullyAutomated

$SRMan = Get-View StorageResourceManager

$spec = New-Object VMware.Vim.StorageDrsConfigSpec
$spec.PodConfigSpec = New-Object VMware.Vim.StorageDrsPodConfigSpec
$lbSpec = New-Object VMware.Vim.StorageDrsSpaceLoadBalanceConfig
$ioSpec = new-object VMware.Vim.StorageDrsIoLoadBalanceConfig

$spec.PodConfigSpec.DefaultIntraVmAffinity = $true
$spec.PodConfigSpec.LoadBalanceInterval = 480
$spec.PodConfigSpec.Enabled = $true
       
$lbSpec.MinSpaceUtilizationDifference = 10
$lbSpec.SpaceUtilizationThreshold = 89

$spec.PodConfigSpec.SpaceLoadBalanceConfig = $lbSpec

$ioSpec.IoLatencyThreshold = 10
$ioSpec.IoLoadImbalanceThreshold = 10
$ioSpec.ReservablePercentThreshold = 60
$ioSpec.ReservableThresholdMode = "automated"

$spec.PodConfigSpec.IoLoadBalanceConfig = $ioSpec
$spec.PodConfigSpec.IoLoadBalanceEnabled = $true

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

Sincerely, Jody L. Whitlock
Tags (1)
Reply
0 Kudos