WilliamLam.com

  • About
    • About
    • Privacy
  • VMware Cloud Foundation
  • VKS
  • Homelab
    • Hardware Options
    • Hardware Reviews
    • Lab Deployment Scripts
    • Nested Virtualization
    • Homelab Podcasts
  • VMware Nostalgia
  • Apple
You are here: Home / Automation / Automating the vSAN Data Migration Pre-check using vSAN API

Automating the vSAN Data Migration Pre-check using vSAN API

06.04.2025 by William Lam // Leave a Comment

I was chatting with a customer yesterday on various automation topics and one of the questions was about automating the vSAN Data Migration Pre-Check capablitity, which is available in the vSphere UI under vSAN Cluster->Monitor->vSAN->Data Migration Pre-check as shown in the screenshot below.


The specific vSAN API that you will need to use is both the VsanPerformResourceCheck to perform the operation and then VsanGetResourceCheckStatus to retrieve the results as the operation can take some time depending on the size of your environment.

Here is a quick snippet of using PowerCLI to invoke the vSAN API:

$vsanClusterName = "vsan-stretched"
$esxiHostName = "esx01.williamlam.local"
$vsanDataMigration = "ensureObjectAccessibility"

# Get vSAN Resource Check System view to access VsanPerformResourceCheck API
$rcs = Get-VsanView VsanResourceCheckSystem-vsan-cluster-resource-check-system

# Retrieve vSAN Cluster Managed Object Reference (MoRef)
$moref = (Get-Cluster $vsanClusterName).ExtensionData.MoRef

# Retrieve the vSAN UUID for particular ESXi host to check
$esxVsanUuid = ((Get-VMHost $esxiHostName).ExtensionData.Runtime.VsanRuntimeInfo.MembershipList | where {$_.Hostname -eq $esxiHostName}).NodeUuid

# Construct Resource Check Spec
$vsanMode = New-Object VMware.Vim.VsanHostDecommissionMode
$vsanMode.ObjectAction = $vsanDataMigration

$maintSpec = New-Object VMware.Vim.HostMaintenanceSpec
$maintSpec.VsanMode = $vsanMode

$spec = New-Object VMware.Vsan.Views.VsanResourceCheckSpec
$spec.Operation = "EnterMaintenanceMode"
$spec.Entities = @($esxVsanUuid )
$spec.MaintenanceSpec = $maintSpec

# Invoke VsanPerformResourceCheck API and wait for async task to finish
$task = $rcs.VsanPerformResourceCheck($spec, $moref)
$task1 = Get-Task -Id ("Task-$($task.value)")
$task1 | Wait-Task

# Retrieve VsanPerformResourceCheck results
($rcs.VsanGetResourceCheckStatus($spec,$moref)).Result

Here is an example output and you can see the various properties mapping back to what you see in the vSphere UI, including the overall pre-check status:


While the customer came to same conclusion that the two vSAN APIs should allow them to automate the data migration pre-check function, they were confused as to why they were not finding the specific string "The host can enter maintenance mode." that is displayed shown next to the green icon.

While I have not used this specific vSAN API, it was pretty easy to invoke as you can see from the example above and during the call, I had a hypothesis that since the customer was attempting to string match from the vSphere UI, that the string itself may not actually be returned from the underlying API but from a specific localization file.

After looking around in the vCenter Server Appliance (VCSA), I was able to confirm my assumption and quickly found the string to be stored in /usr/lib/vmware-vpx/vsan-health/ui-plugins/vsan-ui-repa/locales/VsanUi.properties


This is something I have seen in the past and when the customer mentioned a specific string, I figured this might have been the reason since we do translate various parts of our UI to various locales. For this particular customer, they just wanted to ensure that after they run the pre-check that the results is "green", which they can key off of the status property, as highlighted in the screenshot above to safely proceed with placing an vSAN host into maintenance mode.

More from my site

  • Programmatically accessing the Broadcom Compatibility Guide (BCG)
  • Enable TRIM/UNMAP from Nested vSAN OSA/ESA to physical vSAN OSA
  • Enhancements to VMware Cloud Foundation (VCF) & vSphere Automated Lab Deployment Scripts
  • Quick Tip - Retrieving vSAN usage & overhead information using vSAN API
  • Quick Tip - vSAN ESA Cluster Health Check returns Error message: Expecting value: line 1 column 1 (char 0)

Categories // Automation, VSAN Tags // VSAN

Thanks for the comment!Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Search

Thank Author

Author

William is Distinguished Platform Engineering Architect in the VMware Cloud Foundation (VCF) Division at Broadcom. His primary focus is helping customers and partners build, run and operate a modern Private Cloud using the VMware Cloud Foundation (VCF) platform.

Connect

  • Bluesky
  • Email
  • GitHub
  • LinkedIn
  • Mastodon
  • Reddit
  • RSS
  • Twitter
  • Vimeo

Recent

  • Automating the vSAN Data Migration Pre-check using vSAN API 06/04/2025
  • VCF 9.0 Hardware Considerations 05/30/2025
  • VMware Flings is now available in Free Downloads of Broadcom Support Portal (BSP) 05/19/2025
  • VMUG Connect 2025 - Minimal VMware Cloud Foundation (VCF) 5.x in a Box  05/15/2025
  • Programmatically accessing the Broadcom Compatibility Guide (BCG) 05/06/2025

Advertisment

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy

Copyright WilliamLam.com © 2025

 

Loading Comments...