WilliamLam.com

  • About
    • About
    • Privacy
  • VMware Cloud Foundation
  • VKS
  • Homelab
    • Resources
    • Nested Virtualization
  • VMware Nostalgia
  • Apple
You are here: Home / VSAN / VMware VSAN APIs

VMware VSAN APIs

02.11.2014 by William Lam // 15 Comments

For customers who are currently evaluating VMware VSAN, the vSphere Web Client is the primary interface for managing and configuring VSAN. However, these exact same VSAN operations can also be accessed programmatically from an Automation perspective. Given that I had spent quite a bit of time playing with VSAN in the lab and exploring some of its APIs, I thought it might be useful to share some of the common VSAN operations mapped to their respective APIs.

There are two main categories of operations that you should be aware of when working with VSAN:

  • VSAN specific operations
  • VM Storage Policy operations

VSAN Operations

The VSAN specific operations are available as part of the vSphere 5.5 API and the list below are the supported operations:

Enable/Disable VSAN on a vSphere Cluster (automatic claiming):

  • Use the ReconfigureComputeResource_Task() and set spec->vsanConfig->enabled to either true or false & spec->vsanConfig->defaultConfig->autoClaimStorage to true

Manual Disk Claiming for an ESXi host:

  • Each ESXi host provides a vsanSystem manager at configManager->vsanSystem which provides the following methods for disk management
    • AddDisks_Task()
    • InitializeDisks_Task()
    • QueryDisksForVsan()
    • QueryHostStatus()
    • RemoveDisk_Task()
    • RemoveDiskMapping_Task()
    • UpdateVsan_Task()

Enable VSAN traffic type for a VMkernel interface

  • Use the ReconfigureComputeResource_Task() and set spec->vsanHostConfigSpec->HostSystem to the ESXi host you wish to configure and  spec->vsanHostConfigSpec->networkInfo->port->device to the specific VMkernel interface you wish to enable VSAN traffic type on

Internal VSAN manager for accessing low level CMMDS (Clustering Monitoring, Membership and Directory Services), object & disk management APIs:

  • Each ESXi host provides a vsanInternalSystem manager at configManager->vsanInternalSystem which provides the following methods for working with the lower level system of VSAN
    • QueryCmmds()
    • QueryObjectsOnPhysicalVsanDisk()
    • QueryPhysicalVsanDisks()
    • QueryVsanObjects()

Change the VM Storage Policy for a Virtual Machine Home OR Virtual Machine Home and Virtual Disk:

  • Use the ReconfigVM_Task() and set spec->vmProfile to the VM Storage Policy ID

Change the VM Storage Policy for Virtual Machine Virtual Disk:

  • Use the ReconfigVM_Task() and set spec->deviceChange->device to the specif Virtual Disk to be reconfigured and set  spec->deviceChange->vmProfile to the VM Storage Policy ID

Enter Maintenance Mode for an ESXi host in a VSAN Cluster:

  • Use the EnterMaintenanceMode_Task() and set spec->
    maintenanceSpec->vsanMode->objectAction to the specific data accessibility mode defined here

Create and Delete directories on a VSAN Datastore:

  • Use the DatastoreNamespaceManager which provides the following two methods
    • CreateDirectory()
    • DeleteDirectory()

SPBM

For VM Storage Policies, VSAN leverages the SPBM (Storage Policy Based Management) framework which allows administrators to create policies that define specific storage capabilities such as performance and reliability that can then be applied to a Virtual Machine. The SPBM API is exposed as a separate API endpoint in vCenter Server and will be required if you wish to create additional VM Storage Policy leveraging VSAN storage capabilities.

Query list of available VM Storage Profiles defined:

  • Use PbmQueryProfile()

Create VM Storage Policy:

  • Use PbmCreate()

Delete VM Storage Policy:

  • Use PbmDelete()

Check VM Storage Policy Compliance:

  • Use PbmCheckCompliance()

Given a Virtual Machine Home or Virtual Disk, provide associated VM Storage Profile:

  • Use PbmQueryAssociatedEntity()

Given a VM Storage Profile, provide the associated Virtual Machine Home or Virtual Disk:

PbmQueryAssociatedEntity
  • Use PbmQueryAssociatedProfiles()
PbmQueryAssociatedProfiles

Hopefully this provides a good overview of some of the common VSAN / SPBM operations and their associated API methods. If I have some spare cycles, I may create some sample scripts leveraging some of these API methods. In the meantime, you can check out these RVC (vSphere SDK for Ruby) modules leveraging both VSAN and SPBM APIs here and here.

Additional Resources:

  • If you wish to evaluate VSAN and its associated APIs, please sign up for the public beta here.
  • Sign up for a special VSAN event here
  • VM Storage Policy APIs aka Storage Profile APIs will be available in vSphere 5.5
  • SPBM (Storage Policy Based Management) MOB in vSphere 5.5

More from my site

  • Exploring VSAN APIs Part 6 – Modifying Virtual Machine VM Storage Policy
  • How to upgrade to the latest VSAN Beta Refresh of RVC on Windows?
  • Extending VSAN capabilities in the vSphere Web Client using vCO
  • How to run the VSAN Observer in "collection" mode in the background?
  • VSAN Flash/MD capacity reporting

Categories // VSAN, vSphere 5.5 Tags // rvc, spbm, VSAN, vSphere 5.5, vSphere API

Comments

  1. *protectedCW says

    03/12/2014 at 10:03 pm

    Hi William,
    I tried several time to apply the storage policy to vm by calling reconfigVm_task in mob, however, i failed everytime but the task return shows "success", i grabbed the uuid of the policy i set and construct the mob body like

    1bb9e360-d568-457d-8141-4707278a6463 => ( uuid of the policy i got from spbm )

    any idea?

    Reply
  2. *protectedCW says

    03/12/2014 at 10:35 pm

    it hides the tags
    ''
    'third-change'
    ''
    '1bb9e360-d568-457d-8141-4707278a6463'
    ''
    ''
    ''

    Reply
  3. *protectedCW says

    03/12/2014 at 10:37 pm

    last time
    spec
    vmProfile
    profileId 1bb9e360-d568-457d-8141-4707278a6463 /profileId
    /vmProfile
    /spec

    Reply
    • William Lam says

      03/13/2014 at 3:39 am

      vmProfile is an array and its of type VirtualMachineDefinedProfileSpec so it looks like your request is not correct. Also note, this will only change the VM Home but not the underlying disks. I will have an example in the coming days on how to change VM Storage Policy, stay tuned

      Reply
      • *protectedCW says

        03/13/2014 at 4:12 am

        Thanks for replying!

        I checked out VirtualMachineDefinedProfileSpec

        public class VirtualMachineDefinedProfileSpec
        extends VirtualMachineProfileSpec
        {

        @XmlElement(required = true)
        protected String profileId;
        protected VirtualMachineProfileRawData profileData;
        ...

        I've specified the profileId, and in this file: bora/vim/vmodl/vim/vm/DefinedProfileSpec.java

        i found the profileData is optional, so I can't figure out why I've messed up the request, could you point that out?

        thanks!

        Reply
      • *protectedCW says

        03/13/2014 at 7:09 pm

        i've figured it out, it should be looks like:

        \
        \
        \1bb9e360-d568-457d-8141-4707278a6463\
        \
        \

        Reply
        • William Lam says

          03/14/2014 at 4:38 am

          Glad to hear you got it working. I will also be posting some sample code relating to this topic next week.

          Reply
  4. *protectedaj203355 says

    09/17/2014 at 8:54 pm

    Do you know a way for a vCenter server to be replaced with a new vCenter build in an existing VSAN cluster? I get UUID mismatch anytime I try and add preexisting VSAN hosts contributing storage to the new vCenter. I was told by VMware I'dbe able to jjust disconnect hosts and add them to new vCenter VSAN cluster but I still get UUID mismatch errors. Thoughts?

    Reply
    • lamw says

      09/17/2014 at 11:08 pm

      I assume your workflow is create a new VSAN Cluster in the new VC, disconnect all hosts in the old VC and then add one host at a time to the new VC? That should work as I've done this before as well. If you try to add all them, then you'll see the error but if you add one at a time, it works

      Reply
  5. *protectedPushpa says

    12/09/2014 at 10:04 am

    Hi William,

    I am using ReconfigureComputeResource_Task() for enabling the vsan traffic for the vmkernel interface. I am able to set the host system and the vmkernel interface, if we execute this task it's returning as success but if we see in vSphere it's still showing as disabled for the particular vnic.

    PFB code.

    ClusterConfigSpecEx clusterConfigSpecEx = new ClusterConfigSpecEx();
    VsanHostConfigInfo[] hostSpecarr=new VsanHostConfigInfo[1];
    VsanHostConfigInfo hostSpec=new VsanHostConfigInfo();
    hostSpec.setHostSystem(host.getMOR());
    VsanHostConfigInfoNetworkInfoPortConfig pConfig=new VsanHostConfigInfoNetworkInfoPortConfig();
    pConfig.setDevice(device);
    List configList=new ArrayList();
    configList.add(pConfig);
    hostSpec.setEnabled(true);
    VsanHostConfigInfoNetworkInfoPortConfig[] vsanHostConfigSpec=configList.toArray(new VsanHostConfigInfoNetworkInfoPortConfig[configList.size()]);

    VsanHostConfigInfoNetworkInfo vnetifo = new VsanHostConfigInfoNetworkInfo();
    vnetifo.setPort(vsanHostConfigSpec);
    hostSpec.setNetworkInfo(vnetifo);
    hostSpecarr[0]=hostSpec;
    clusterConfigSpecEx.setVsanHostConfigSpec(hostSpecarr);
    Task task=ccr.reconfigureComputeResource_Task(clusterConfigSpecEx, true);

    Please help me on this.

    Reply
  6. *protectedJay Jahns says

    08/31/2015 at 3:21 am

    There's actually a better way to update the VMK if it already exists.

    There's a task called UpdateVsan_Task located in host->configManager->vsanSystem.

    The only thing needed is a bit of port info associated with the device name (i.e. vmk0 or vmk1 or vmk2), and then execution of the task. After that, reconfiguring the compute resource should not be needed.

    I'm doing this via pyVmomi / VConnector and Ansible.

    Works just fine. We have our Auto Deploy set to statefully install the host outside of the VSAN enabled cluster, and then Ansible puts the host into maintenance mode, applies the change, and moves it to the cluster.

    From there, the cluster assumes auto claim and such items.

    No fuss.

    Reply

Trackbacks

  1. Welcome to vSphere-land! » VSAN Links says:
    03/01/2014 at 2:06 am

    […] a VSAN Cluster with PowerCLI (Virtu-Al) vdq – A useful little VSAN utility (Virtually Ghetto) VMware VSAN APIs (Virtually Ghetto) Restoring VSAN VM Storage Policies without vCenter Part 1: Using cmmds-tool […]

    Reply
  2. Exploring VSAN APIs Part 1 – Enable VSAN Cluster | virtuallyGhetto says:
    03/04/2014 at 3:35 pm

    […] couple of weeks back I had provided an overview on some the most common VSAN operations and the specific vSphere APIs that were required to perform […]

    Reply
  3. Consolidated list of all Virtual SAN (VSAN) deep dive resources. | says:
    04/09/2014 at 1:26 am

    […] VMware VSAN APIs (William Lam) […]

    Reply
  4. Exploring VSAN APIs Part 9 – VSAN Component count | virtuallyGhetto says:
    04/09/2014 at 3:57 pm

    […] last topic that I would like to explore before concluding my VSAN API blog series are some of the advanced VSAN disk statistics that are available for either troubleshooting or […]

    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