WilliamLam.com

  • About
    • About
    • Privacy
  • VMware Cloud Foundation
  • VKS
  • Homelab
    • Resources
    • Nested Virtualization
  • VMware Nostalgia
  • Apple
You are here: Home / VSAN / Exploring VSAN APIs Part 6 – Modifying Virtual Machine VM Storage Policy

Exploring VSAN APIs Part 6 – Modifying Virtual Machine VM Storage Policy

03.20.2014 by William Lam // 6 Comments

One of the biggest benefit of VSAN is the ability to specify granular storage policies on a per Virtual Machine basis. These storage policies is managed through VMware's Storage Policy Based Management system and is automatically enforced by VSAN to ensure compliance. A VM Storage Policy can be assigned during the initial deployment of a Virtual Machine or it can be modified afterwards, for example if the Virtual Machine's SLA's has changed because the workload has changed. From the vSphere Web Client, modifying a Virtual Machine's VM Storage Policy is simply selecting the VM Storage Policy and re-applying which is also available programmatically through the vSphere API.

Using the vSphere API method ReconfigVM_Task(), you will be able to modify the VM Storage Policy for the VM Home Namespace and/or individual Virtual Disks. To modify the VM Home Namespace, there is a property defined at the root of the Virtual Machine config spec called vmProfile which accepts the VM Storage Policy ID extracted from the SPBM API. To modify the VM Storage Policy for an individual Virtual Disk, you will need to set the profile property which is exposed on a Virtual Device with the VM Storage Policy ID. To demonstrate this functionality, I have created a sample vSphere SDK for Perl script called changeVMStoragePolicy.pl

Disclaimer:  These scripts are provided for informational and educational purposes only. It should be thoroughly tested before attempting to use in a production environment.

In my environment, I have a Virtual Machine called VM1 which has been defined with a VM Storage Policy called "Copper" as seen in screenshot below:

change-vm-storage-policy-0
Let's say I want to change the Virtual Machine's VM Storage Policy to another policy called "Aluminum", I first need to extract the VM Policy ID from SPBM API and then pass it into the script like the following:

./changeVMStoragePolicy.pl --server vcenter55-1.primp-industries.com --username root --vmname VM1 --profileid cd6908b2-0704-4733-ad9b-a9a8f200ab0a

change-vm-storage-policy-1
Once the Virtual Machine has been reconfigured, we can then take a look in our vSphere Web Client and we can see the VM Storage Policy has now been changed and VSAN will automatically enforce these new requirements.

change-vm-storage-policy-2
If you wish to assign a VM Storage Policy as part of a new Virtual Machine creation, you just need to set the vmProfile and profile properties which is similar to a reconfiguration operation.

  1. Exploring VSAN APIs Part 1 – Enable VSAN Cluster
  2. Exploring VSAN APIs Part 2 – Query available SSDs
  3. Exploring VSAN APIs Part 3 – Enable VSAN Traffic Type
  4. Exploring VSAN APIs Part 4 – VSAN Disk Mappings
  5. Exploring VSAN APIs Part 5 – VSAN Host Status
  6. Exploring VSAN APIs Part 6 – Modifying Virtual Machine VM Storage Policy
  7. Exploring VSAN APIs Part 7 – VSAN Datastore Folder Management
  8. Exploring VSAN APIs Part 8 – Maintenance Mode
  9. Exploring VSAN APIs Part 9 – VSAN Component count
  10. Exploring VSAN APIs Part 10 – VSAN Disk Health

More from my site

  • VMware VSAN APIs
  • How to upgrade to the latest VSAN Beta Refresh of RVC on Windows?
  • SPBM (Storage Policy Based Management) MOB in vSphere 5.5
  • Restoring VSAN VM Storage Policy without vCenter Part 2: Using vSphere API
  • Restoring VSAN VM Storage Policies without vCenter Part 1: Using cmmds-tool

Categories // VSAN, vSphere 5.5 Tags // spbm, vm storage policy, vm storage profile, VSAN, vSphere 5.5, vSphere API

Comments

  1. *protectedMike Lamb says

    06/30/2014 at 8:06 pm

    William,
    Thanks for all your posts on the vSphere APIs!
    I have read these posts on the VM storage policies.
    http://www.virtuallyghetto.com/2013/11/spbm-storage-policy-based-management.html
    http://www.virtuallyghetto.com/2013/09/vm-storage-policy-apis-aka-storage.html

    Setup the following
    1. Deployed a 3 node VSAN using your template.
    http://www.virtuallyghetto.com/2014/04/ovf-template-for-creating-nested-esxi-3-or-32-node-vsan-cluster.html

    2. Created a storage policy with a rule set of just a single tag.
    3. Tagged the vsanDatastore.
    4. Created a VM with the vSanDatastore and associated the policy.

    From this post I see how to set policy information when calling ReconfigVM_Task but how would I just query the current VM policy ID using the vSphere API so that can be used to lookup the policy details in the policy API? I don't see any objects off of the VM MOR, Datastore MOR or Virtual Disk MOR that has a policyID.

    Reply
    • William Lam says

      07/01/2014 at 2:19 am

      Hi Mike,

      You would need to use the SPBM API to perform that operation, this is not available in the vSphere API

      Reply
  2. *protectedRajeev Ravi says

    03/02/2015 at 11:49 pm

    Thanks!Can you provide a JAVA implementation for modifying the policy for virtual disks?

    Reply
  3. *protectedAtoka Sema says

    05/02/2015 at 5:58 am

    Hi,

    Very helpful article. Thank you!!!

    Is there a way to list all the VM Storage Policies using vSphere API?

    Thanks.

    Reply
  4. William Lam says

    05/02/2015 at 1:46 pm

    Hi Atoka,

    You've seemed to have answered you own question already 🙂 by posting over in http://www.virtuallyghetto.com/2013/09/vm-storage-policy-apis-aka-storage.html As I've mentioned, you'll need to use the combination of the two APIs, as they're different endpoints. If you just want to list them or perform general operations on them, you'll need to use the VM Storage Policy API which is NOT part of the vSphere API. Once you're ready to assign, then you'll use the vSphere API.

    An alternative to that would be to look at using PowerCLI which includes VM Storage Policy cmdlets and with their abstraction, it'll feel like a single interface but again both APIs are different

    Reply
  5. *protectedsensoft1988 says

    04/11/2017 at 2:08 am

    Hi

    Using JAVA implementation I edited the Storage Profile rule set and saved it. which make my VM Compliance status as out of date, but not able to find the API call for the Reapply VM Storage Policy( 3rd icon which will enable when the vm Compliance status as out of date)

    Is there is any way to reapply the VM storage policy to all out of date entry.

    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...