All posts by Vikas Shitole

About Vikas Shitole

Vikas Shitole is a Senior Tech Lead at VMware by Broadcom, VCF division, India, where he leads system test efforts—including scale, stress, and resiliency testing—and drives product quality across VMware Cloud Foundation (VCF), Broadcom’s flagship private cloud platform. He is an AI and Kubernetes enthusiast, and is passionate about VMware customers and automation around vSphere and VCF. Vikas has been honoured as a vExpert for 13 consecutive years (2014–2026) for his sustained technical contributions and community leadership. He is the author of two VMware Flings, holds multiple industry certifications including VCF admin 9.0, and is one of the top contributors to the VMware API Sample Exchange, where his automation scripts have been downloaded over 50,000 times. Vikas has shared his expertise as a speaker at international conferences such as VMworld Europe and VMworld USA, and was selected as an official VMworld 2018 blogger. He also served as lead technical reviewer for the Packt-published books vSphere Design and VMware Virtual SAN Essentials. Beyond tech, Vikas is a dedicated cricketer, cycling enthusiast, and a lifelong learner in fitness and nutrition, with the personal goal of completing an Ironman 70.3

How to get Datastore Summary for all data-stores connected to a ESXi host using vSphere API

This post is motivated by this VMTN thread , also I wanted to start with small tutorials on vSphere APIs using JAVA, I thought lets start with answering this query which can cover tutorial on DatastoreSummary data object as well. I hope you have already setup your eclipse environment by referring my  Getting started  blog post. Here we go.

Query on VMTN was: How to get datastore type connected to ESXi programmatically using vSphere APIs. As datastore type is part of DatastoreSummary data object, lets see how to get datastore summary (Datastore Name, Datastore Type, Datastore Capacity, Datastore free capacity etc.)

DatastoreSummary Data Object Description:

Datastore Summary Data object description

Complete code :

[java]
package com.vmware.vim25.mo.Samples.cluster;
import java.net.URL;
import com.vmware.vim25.mo.Datastore;
import com.vmware.vim25.mo.Folder;
import com.vmware.vim25.mo.HostDatastoreBrowser;
import com.vmware.vim25.mo.HostSystem;
import com.vmware.vim25.mo.InventoryNavigator;
import com.vmware.vim25.mo.ServiceInstance;

public class DatastoreSummary {
public static void main(String[] args) throws Exception {
if (args.length != 3) {
System.out.println("Usage: java SearchDatastore "
+ "username password");
return;
}

/*
* you need to pass 3 parameters
* 1. https://ESXi_IP/sdk
* 2. username
* 3. password
*/
ServiceInstance si = new ServiceInstance(new URL(args[0]), args[1],
args[2], true);
String hostname = "XYZ.vmware.com"; //Pass the FQDN i.e. DNS name of the ESXi host, ESXi host IP will not work
Folder rootFolder = si.getRootFolder();
HostSystem host = null;

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

if (host == null) {
System.out.println("Host not found");
si.getServerConnection().logout();
return;
}

HostDatastoreBrowser hdb = host.getDatastoreBrowser();

System.out.println("Datastore Summary connected to ESXi host");
System.out.println();
Datastore[] ds = hdb.getDatastores();

for (int i = 0; ds != null && i < ds.length; i++) {
System.out.println("DatastoreName:" + ds[i].getName() + " "
+ "DSType:" + ds[i].getSummary().getType() + " "
+ "TotalCapacity(in GB):"
+ (ds[i].getSummary().getCapacity()) / (1024 * 1024 * 1024)
+ " " + "FreeSpace (in GB): "
+ (ds[i].getSummary().getFreeSpace())
/ (1024 * 1024 * 1024) + " ");
System.out.println();

}
si.getServerConnection().logout();
}
}

[/java]

Program Output::


Datastore Summary connected to host

DatastoreName:Local Datastore DSType:VMFS TotalCapacity(in GB):131 FreeSpace (in GB): 130

DatastoreName:Shared DS_3 DSType:VMFS TotalCapacity(in GB):24 FreeSpace (in GB): 8

DatastoreName:Shared DS_1 DSType:VMFS TotalCapacity(in GB):49 FreeSpace (in GB): 8

DatastoreName:Shared DS_4 DSType:VMFS TotalCapacity(in GB):49 FreeSpace (in GB): 13

DatastoreName:Shared DS_2 DSType:VMFS TotalCapacity(in GB):49 FreeSpace (in GB): 15

Compare output with datastore summary from VI client
Datastore summary

You could see output is matching with screenshot from VI client, is not it cool?

Refer: vSphere API reference documentation I highly recommend you to spend some time on getting familiarize with vSPhere API reference.

Stay tuned for more specific/basic tutorials. please let me know if you want specific tutorial on vSphere API

VMware released Bash code injection Vulnerability Express Patches for vCenter Server Virtual Appliance

VMware has just released Express patches on Bash code injection Vulnerability aka “ShellShock” for most of the VMware products. However, this post is focused on express patches @vCenter Server Virtual Appliance.

Note:Please do read KBs referred below carefully  corresponding to each express patch release which addresses  bash vulnerability. Also note that Bash code injection vulnerability does NOT affect Windows based vCenter server.

Express patch is released on each release lines i.e. 5.0.x, 5.1.x, 5.5.x

If you are running vCenter Server Appliance 5.0.x, vCenter Server Appliance 5.0 U3b addresses Bash vulnerability:
KB:vCenter Server Appliance 5.0 U3b KB

Download from here:vCenter server appliance 5.0 U3b (Scroll down to 5.0 U3b)

If you are running vCenter Server Appliance 5.1.x, vCenter Server Appliance 5.1 U2b addresses Bash vulnerability:
KB:vCenter Server Appliance 5.1 U2b KB

Download from here:vCenter Server Appliance 5.1 u2b (Scroll down to 5.1 U2b)

If you are running vCenter Server Appliance 5.5.x, vCenter Server Appliance 5.5 U2b addresses Bash vulnerability:
KB: vCenter Server Appliance 5.5 U2a KB

Download from here:vCenter Server Appliance 5.5 U2a (Scroll down to 5.5 U2a)

VMware KB on Bash bug assessment :VMware KB on Bash Code Injection Assessment

VMware Security Advisory on Bash bug :VMware Security Advisory (Here you can also get patch details @ other VMware products)

How to quickly reproduce this bug (before applying the patch):

1. Login /SSH to the vCenter server virtual appliance  through Putty.

2. Run this bash script :”env x='() { :;}; echo vulnerable’ bash -c “echo this is test”. It should display output as follows :

Repro

You could see both “vulnerable & “this is test” are displayed as output.

How to quickly verify this bug (after applying the patch):

1.  Login /SSH to the vCenter server virtual appliance  through Putty.

2. Run same bash script :”env x='() { :;}; echo vulnerable’ bash -c “echo this is test”.It should display output as follows :Verification

You could see only “this is test” is displayed as output.  “vulnerable” should not be displayed with patch.

Learn more about Bash code injection:The Bash bug Explained

 

 

Crucial fixes on Storage DRS in VMware vCenter Server 5.5 U2 : Part-I

There are a couple of crucial bug fixes on Storage DRS (Storage Distributed Resource Scheduler) in vCenter Server 5.5 U2. I thought it is worth to have article on the same. Here we go on first fix.

Issue is as follows:

1. When Virtual Machine level backup is in progress, by design, backup vendors leverage 2 important VDDK( Virtual Disk Development Kit)  APIs in order to inform vCenter  managed host  about backup is in progress.

2. PrepareForAccess() VDDK API is used to disable storage vMotion operation on the VM to be backed & EndAccess() VDDK API is used to enable storage vMotion operation once the backup is over. Refer: VDDK APIs to disable_Enable storage vMotion

3. When VM is NOT managed by SDRS or when SDRS is disabled on VM to be backed, there was not any issue and vCenter was working as expected on disabling and enabling storage vMotion when VM level backup is in progress.

4. BUT when VM is managed by SDRS cluster & even though backup solution was successfully invoking PrepareForAccess() VDDK API to disable storage vMotion, SDRS was not honoring the disabled storage vMotion and it was automatically starting storage vMotion may be based on space/IO load , affinity rule constraints or Maintenance mode operations. Due to this, backup in progress for that VM was getting failed and orphaned virtual machine disks (VMDKs) were getting created in virtual machine folder. Note that SDRS will automatically apply the storage vMotion recommendations when set at Fully Automated mode.

5. Even manual storage vMotion was allowed for the VM to be backed up from VI client “Migrate” Option and Web client “Move to” Option. This was also leading to same issue.

Resolution :

When VM is managed by SDRS cluster, below are the scenarios in which VM can be storage vMotion to other datastore in SDRS cluster.

1. Manual storage migration scenario.

2. Enter SDRS maintenance mode scenario.

3. Scenario around initial placement.

4. All run time placement scenarios.

5. All scenarios around SDRS affinity/anti-affinity rules.

With the fix, in any of above scenarios , SDRS & you are NOT allowed to storage vMotion VM from a datastore to other datastore (inside or outside SDRS cluster) when backup is in progress. Now apart from backup, even though storage vMotion is disabled for some other purpose, SDRS& you are not allowed to storage vMotion the VM.

My testing:

Note: Instead of using actual backup solution, I directly used above specified VDDK APIs to disable/enable storage vMotion on the input VM as same APIs are being used by backup solutions.

  • I tested this fix and I could see fix is working perfectly fine with NO any issue. Here is where (refer below screen shot) you can verify whether storage vMotion is disabled or not using MOB i.e. Managed Object Browser. (Refer:How to navigate MOB)

Disabled method from MOB

“vim.VirtualMachine.relocate” method is leveraged by storage vMotion.

  •   I tried putting datastore where VM is placed in maintenance mode (from SDRS cluster), I was not allowed to put DS in maintenance mode as expected. (Refer: below screenshot) SDRS maintenance mode
  • I added one more VMDK to the VM and created SDRS VMDK anti-affinity rule on VM which is being backed up. Ideally in order to satisfy  SDRS VMDK anti-affinity rule, one of VMDKs SDRS should storage vMotion to other datastore in SDRS cluster but SDRS throws fault as expected (refer: below screenshot)VMDK _Anti_affinity
  • I tried manual storage vMotion of the VM to be backed up but my attempt failed as expected. (Refer: below screenshot)Manual Migration

 

If you want to avoid such issue in your environment, you will have to upgrade to vCenter server 5.5 U2 . Download :vCenter 5.5 U2

Great News for VMware users: vSphere 5.5 U2 C# client can edit VMs with Virtual HW Version 10

Since the vSphere 5.5 got released, all VMware users were facing one major pain point i.e. Editing VM settings for VMs with HW version 10 using C# client. This was one of the hot topics on VMTN community as well. Feedback from VMware users was really spot on & it forced VMware to seriously take this issue forward.  Yesterday vSphere 5.5 Update 2 got released & this pain point is addressed in vSphere 5.5 Update 2 C# client. (aka VI/Desktop/Thick client)

With older C# client when you try to edit VM with HW version 10 using VI client, it was prompting to use web client & was blocking users to manage VMs using VI client.

Now with vSphere 55 U2 VI client, when you try to edit VM with HW version 10 (Right click VM >> Edit settings), it shows below warning message

Edit settings_1

Above message shows that you only can edit features up to HW version 8 & to edit all new features you will have to use web client or you will have to edit new features by using vSphere APIs (VI Java, PowerCLI etc.).

I just tried editing memory, cpu, network & disks as shown in below screenshot. It worked fine for me.Edit seetings_2

What are the pain points addressed by vSphere 5.5 U2 C# Client?

1. You can edit basic functionality of the HW version 10 VM using latest VI client  if vCenter server itself is down. When vCenter is down, web client would be down too.

2.  There are many customers with small VMware environment those do not want to spend additional cost on vCenter licenses just for web client. Now with this fix, they can use latest HW version & edit basic functionality of the VM as well using VI client by directly connecting to the ESXi host.

In order to leverage this VI client functionally immediately, you just need to upgrade older C# client to latest, you need not to upgrade all vCenter components immediately. You can plan upgrading other vCenter components as per your company policy/schedule.

Not sure whether new features will be supported on VI client in future releases, hope for the best BUT at the moment, I liked step in right direction by VMware on this issue. I am really happy, are you ?

Download latest C# client from here:vSphere 55 U2 C# Client

Getting started with vSphere API using VI Java

Recently I got introduced to VMware Infrastructure (aka vSphere) Java & I should say “VI Java is an incredible open source project  I have ever come across”. I am really humbled with the impact that Steve Jin’s contribution to the VMware community. I am sure this open source project is asset for thousands of VMware customers & partners. In the purview of the same, VI Java project inspired me to add “vSphere API” section in my blog. Under this section you can expect small utilities to manage your VMware environment which will be useful specially to most of the VMware administrators. Here we go with first post under “vSphere API” section. I am going to share how I got started with VI Java application development. i.e. Step by step tutorial on getting started with vSphere API using Java.

Update: VI Java project has now YAVI JAVA, please start using this guide to get started with YAVI JAVA instead of below steps. Since it supports vSphere 5.5 as well as vSphere 6.0 SDK, it is recommended to use YAVI JAVA. All the automation written using VI JAVA will work fine on YAVI JAVA.

1. Goto VI java website Here. Click on “Download” tab on the top as shown in below screenshot.

VIJAVA_website_home_Page_1

2. Click on the latest release as shown below. 

Download_2Note: For future releases Zip file name would be different. Just you need to download latest one

3.  Extract the downloaded file at any location of your choice.Extract ZIP_file

4. You should see below jar files inside extracted Zip file.

EXtracted_2files_4

5. Now it is time to install Eclipse. Download eclipse from “https://www.eclipse.org/downloads” as shown below .Please make sure you have JDK/JRE 1.6 or higher

Eclipse download6. Create java project as shown below .

Create_Project_1Create_Project_2

Project_Create_3

Create_project_4

7. Configure the 2 jars files that were extracted above in step 5 as follows.

Create_project_5

Create_project_6

Create_project_7

Create_Project_8

8. Create first java program “HelloVM.java” as follows: Download source code from here:HelloVM.java. (Source code originally written by Steve Jin). Add this source code in java class created below.

Create_project_9

Create_Project_10

 9. You need to modify source code with vCenter IP, vCenter username & vCenter password as shown in below screenshot.

Create_project_1210. Run your first VI Java program as follows.

Create_project_13

Create_project_14

Great! Finally you got started with VI SDK and executed first VI SDK program. Stay tuned for more meaningful programs to manage your VMware environment.