WilliamLam.com

  • About
    • About
    • Privacy
  • VMware Cloud Foundation
  • VKS
  • Homelab
    • Resources
    • Nested Virtualization
  • VMware Nostalgia
  • Apple
You are here: Home / Automation / Quick Tip - Automating allowed and not allowed Datastores for use with vSphere Cluster Services (vCLS)

Quick Tip - Automating allowed and not allowed Datastores for use with vSphere Cluster Services (vCLS)

01.25.2023 by William Lam // 5 Comments

One of the recent features of the vSphere Cluster Services (vCLS) is the ability configure the vSphere Datastores that vCLS is allowed to use to provision the required service VMs, which can be on a vSphere Cluster under Configure->vSphere Cluster Services->Datastores as shown in the screenshot below.


In addition to the vSphere UI, you can also programmatically update this configuration using the vSphere API and with tools like PowerCLI as one of the interfaces to the API.

While responding to a user with a code example, I came to learn that managing the datastore options for vCLS is actually much richer when using the vSphere API. In addition to specifying the list of allowed datastores, you can also specify the list of datastores that are NOT allowed which might be easier to filter out or you can even specify the vSphere Tag category as a way to automatically indicate all datastores that can be used by vCLS. The vCLS datastore configuration is stored as part of the vSphere Cluster under SystemVMsConfigSpec, which you can see the three different options.

To demonstrate the original use case, the following PowerCLI snippet can be used to update a vSphere Cluster with the desired list of datastores that you want vCLS to use.

$clusterName = "Supermicro-Cluster"
$allowedVCLSDatastores = @("sm-vsanDatastore")

$cluster = Get-Cluster $clusterName

$allowedDatastores = @()
foreach ($datastoreName in $allowedVCLSDatastores) {
    $datastoreMoRefId = (Get-Datastore $datastoreName).ExtensionData.MoRef

    $tmp = New-Object VMware.Vim.ClusterDatastoreUpdateSpec
    $tmp.datastore = $datastoreMoRefId
    $allowedDatastores+=$tmp
}

$systemConfigSpec = New-Object VMware.Vim.ClusterSystemVMsConfigSpec
$systemConfigSpec.allowedDatastores = $allowedDatastores

$spec = New-Object VMware.Vim.ClusterConfigSpecEx
$spec.systemVMsConfig = $systemConfigSpec

$task = $cluster.ExtensionData.ReconfigureComputeResource_Task($spec, "modify")
$task1 = Get-Task -Id ("Task-$($task.value)")
$task1 | Wait-Task

Once the operation has completed, you can check via he vSphere UI or via vSphere API that you now have updated the datastore allowed list by running the following command:

(Get-Cluster $clusterName).ExtensionData.ConfigurationEx.SystemVMsConfig


I will leave it to reader as a learning exercise to explore the other two vCLS datastore configuration options including using vSphere Tag category or list of datastores that vCLS is not allowed to use.

More from my site

  • Quick Tip - vCenter Server Advanced Settings Reference
  • Downgrading new VMware vSphere Foundation (VVF) or VMware Cloud Foundation (VCF) licenses to 7.x
  • Updating handshakeTimeoutMs setting for ESXi 7.x & 8.x using configstorecli
  • Identifying vSphere with Tanzu Managed VMs
  • Quick Tip - New remote version of ESXCLI 8.x

Categories // Automation, PowerCLI, vSphere 7.0, vSphere 8.0 Tags // vCLS, vSphere 7.0, vSphere 8.0

Comments

  1. *protectedJeff Creek says

    01/25/2023 at 1:00 pm

    Nice article.
    Typo - ' . . . datastore options for vLCS is actually much richer when using the vSphere API. '

    Reply
    • William Lam says

      01/25/2023 at 1:51 pm

      Thanks for catch Jeff. Just fixed

      Reply
  2. *protectedAnthony Furr says

    02/22/2023 at 5:36 pm

    I am in need of adding this to our ESXi host config automation. To leverage these namespaces, what version of PowerCLI do I need to be running?

    Reply
  3. *protectedRaf says

    03/13/2023 at 1:36 am

    Hello William,
    It seems this is not persistent across Vcenter reboot ....
    I did TagCategory Exclusions which worked flawlessly but this config disappear after a Vcenter reboot (VCSA 7.0U3J).

    I've just opened case 23414462603 at GSS ...

    Reply
  4. *protectedPeter Anderson says

    02/26/2024 at 11:29 am

    When I use this code or the code from code capture it always results in the vCLS continually redeploying. In the GUI it looks fine. If I delete it from the GUI and then add the vSAN datastore it works fine.

    Reply

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

  • Programmatically accessing the Broadcom Compatibility Guide (BCG) 05/06/2025
  • Quick Tip - Validating Broadcom Download Token  05/01/2025
  • Supported chipsets for the USB Network Native Driver for ESXi Fling 04/23/2025
  • vCenter Identity Federation with Authelia 04/16/2025
  • vCenter Server Identity Federation with Kanidm 04/10/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...