Putting a VSAN host into maintenance mode using PowerCLI

I had a a question at a recent VMUG on using CLI to perform some VSAN operations. Specifically the question was around putting hosts into maintenance mode and the default behavior.

Although at this time there is not cmdlet that allows this it is possible. Hopefully this little PowerCLI script will help you. There are a number of ways you could request the required input such as host name and object action but i’ll leave that up to your imagination.

$vmhost= Get-VMHost ghetto-vsan2.vmware.local
$spec = new-object VMware.Vim.HostMaintenanceSpec
$spec.VsanMode = new-object VMware.Vim.VsanHostDecommissionMode
$spec.VsanMode.ObjectAction = “ensureObjectAccessibility”
$vmhost.ExtensionData.EnterMaintenanceMode(0, $false, $spec)

Note: Use either “ensureObjectAccessibility”, “evacuateAllData” or “NoAction”

Before I run the script let’s draw attention to guest2 which has at least on component residing on ghetto-vsan2.vmware.local

evac2.JPG

We can also see the host now entering maintenance mode. Due to my choice of  ensuring all object availability these components are being migrated to other nodes in the cluster.

evac1

Once all the components have been successfully migrated and the objects are compliant the host will be in maintenance mode.

You should note that the policy you have set for each object/VM and the maintenance mode action you chose will determine how many hosts in the cluster you will need during a maintenance window. 3 hosts is not enough to sustain object availability when one node is undergoing maintenance, due to VSAN’s default requirement for 2 copies of data on different nodes and one witness component on another.

For more on this explanation I’d suggest reading this http://www.yellow-bricks.com/2013/10/24/4-minimum-number-hosts-vsan-ask/