Tag Archives: vSphere API

Editing Storage DRS VM overrides : Java vSphere SDK and PowerCLI script

Recently I had an opportunity to work on one of customers requirement with respect to Storage DRS. Their requirement was to edit/remove Storage DRS “VM overrides” settings using vSphere API. As part of this exercise, I had written scripts both in PowerCLI as well as using vSphere Java SDK. I thought it is good to share with you as well. Before discussing about these scripts, let us first understand what exactly is Storage DRS VM overrides?

When user selects Storage DRS cluster (SDRS POD) as a storage for a VM, Storage DRS takes care of placing that VM on right datastore among all the datastores inside Storage DRS cluster. Once SDRS places that VM, all the default SDRS cluster level configuration gets applied on that VM such as ‘Storage DRS automation level’, ‘Keeps VMDK together’ etc. “VM overrides” settings comes to into picture if user wants to override some of Storage DRS cluster level settings. Ex. SDRS cluster level settings for “Automation level” is “Manual” and now for particular VM, user wants to have it as “Fully Automated” or user wants to disable SDRS on particular VM or user just wants to disable default affinity rule “Keeps VMDK together” for specific VM. This can be achieved using SDRS VM overrides settings. Let us look at some of vSphere web client screenshot on how to do it.

Above screenshot shows how to traverse to the “VM overrides” workflow using web client. You could see, currently there is NO VM for which SDRS settings are overridden. You can click on add button in order to override SDRS settings for specific VM as shown below.

Apart from this, there is another reason VM can get listed under “VM orderride” section i.e. When user is creating a VM and user wants to place that VM on a particular datastore among datastores in SDRS cluster instead of relaying on SDRS itself for initial placement, it does mean that user would like to take control of this VM , hence SDRS gets disabled on such VM and gets listed under “VM override” section. Take a look at below screenshot to understand the same.

You could see in above screenshot that if user wants to place the VM on a particular datastore from SDRS cluster instead of relaying on SDRS, we can select specific datastore only when we select checkbox for disabling SDRS. Once VM creation is completed, you could see that VM gets listed under “VM overrides” section as shown below.

Now that we understood, what is VM overrides? and how to configure it? Please take a look at scripts for editing/removing these Storage DRS VM overrides. Below are script locations.

1. Java SDK script on my github repo and on VMware Sample Exchange

2. PowerCLI equivalent on my github repo and on VMware Sample Exchange

If you have still not setup your YAVI JAVA Eclipse environment:Getting started tutorial

Important tutorials to start with: Part I & Part II

If you want to understand Storage DRS, take a look at this whitepaper

Let me know if you have any comments.

vSphere 6.0 cool APIs to mark local host HDD to SSD, SSD to HDD: Sample API script

Recently I wanted to test vFRC (vSphere Flash Read Cache) feature interop with vSphere DRS and vSphere HA. I was figuring out ways to emulate my hosts local HDDs as SSD as I did not have real SSDs in my lab. There are couple of ways I used to fake/emulate local HDD as SSD earlier but this time I found other cool way to automate this quickly by using readily available API. The API that I am talking about is markAsSSD(). This API got introduced in vSphere 6.0. It is important to know why this API is made officially available. The reason this API primarily introduced is: Some time SSDs behind some controllers might not be recognized as SSD correctly. Other use cases for this API can be used to test VMware vSAN (just playing around), vFRC, flash host cache, interop testing etc. Of course, performance of real SSD is incomparable with fake SSD.

Below is the complete code sample which can help you quickly to Mark the local Lun of the host as SSD..

//:: # Author: Vikas Shitole
//:: # Website: www.vThinkBeyondVM.com
//:: # Product/Feature: vCenter Server/Storage
//:: # Description: Mark the local Lun of the host as SSD for testing purpose.

package com.vmware.yavijava;
import java.net.MalformedURLException;
import java.net.URL;
import com.vmware.vim25.ScsiLun;
import com.vmware.vim25.mo.Folder;
import com.vmware.vim25.mo.HostStorageSystem;
import com.vmware.vim25.mo.HostSystem;
import com.vmware.vim25.mo.InventoryNavigator;
import com.vmware.vim25.mo.ServiceInstance;
import com.vmware.vim25.mo.VirtualMachine;

public class MarkAsSSD {

public static void main(String[] args) throws Exception {
System.out.println("Usage: MarkAsSSD url username password hostip/fqdn");

URL url = null;
url = new URL(args[0]);
} catch ( MalformedURLException urlE)
System.out.println("The URL provided is NOT valid. Please check it.");
String username = args[1]; //vCenter username
String password = args[2]; //vCenter password
String hostname = args[3]; // host IP on which local HDD is available
String LunDisplayName="Local VMware Disk (mpx.vmhba1:C0:T2:L0)"; //Add the Display name of the lun that can be seen from VI client or NGC
// Initialize the system, set up web services
ServiceInstance si = new ServiceInstance(url, username,
password, true);

Folder rootFolder = si.getRootFolder();
HostSystem host = null;

host = (HostSystem) new InventoryNavigator(rootFolder)
.searchManagedEntity("HostSystem", hostname);

if (host == null) {
System.out.println("Host not found on vCenter");

HostStorageSystem hhostsystem = host.getHostStorageSystem();
ScsiLun[] scsilun = hhostsystem.getStorageDeviceInfo().getScsiLun();
boolean flag = false;
for (ScsiLun lun : scsilun) {
System.out.println("Display Name"+lun.getDisplayName());
if (lun.getDisplayName().equals(
LunDisplayName)) {
flag = true;
// hhostsystem.markAsNonSsd_Task(lun.getUuid());


if (flag) {
System.out.println("LUN is marked as SSD successfully");

System.out.println("LUN is NOT marked as SSD, plz check if local lun is in use");




– For the sake of simplicity, I have hard-coded LUN display name, you can change it based on your environment.
– You can scale the same code to mark all the local HDDs to SSDs in all the hosts across datacenter or multiple datacenter.
– I would like you to have your attention on other new useful/handy related vSphere 6.0 APIs such as “MarkAsNonSSD” , “MarkAsLocal”, “MarkAsNonLocal“. Same sample can be leveraged to automate these related APIs.

If you have still not setup your YAVI JAVA Eclipse environment:Getting started tutorial

Important tutorials to start with: Part I & Part II