All posts by Vikas Shitole

About Vikas Shitole

Vikas Shitole is currently working at VMware as Senior Member of Technical Staff (MTS) where he primarily contribute to the VMware vCenter server team which is part of VMware’s R&D organisation. He has been vExpert since last 4 years in row (2014-2017)-title awarded by VMware for significant contribution to VMware community.

My first ever VMworld 2017 experience.

This year, it was the very first time I got an opportunity to be part of VMworld Europe, Barcelona & I thought it would be good to share my experience with you. I am sure you will enjoy reading it.

1] My experience as Tech-talk Speaker

I had couple of tech-talks as part of VMworld vBrownBag. This was the very first time I got an opportunity to deliver tech-talks outside India & that too at biggest conference to unknown audience (Customers, partners etc). Personally, it was really a thrilling & exciting experience for me. More exciting was, tech-talks were arranged in open VMVillage community area (I was assuming that they would be in closed hall/room) & tech-talks were being live streamed/recorded as well. Based on the interest and feedback received, I could say both talks were really well received.

Below are the youtube links to my tech talks. Please take a look and please provide your feedback if any

i) VMware Log Tuner (aka vLog Tuner or VLT):
(Project contributors: @chiragarora, @durgakarri & @vThinkBeyondVM (myself))

Youtube link:

ii) DRS Cluster Rules Manager:
(Project contributors: @durgakarri, Gururja Hegdal & Vikas Shitole)

Youtube link :

Take a look at all vBrownBag tech-talks

2] Here are some of the VMworld highlights:

As usual, general sessions by our leaders were awesome. It was truly amazing to be part of such huge community & buzz. Apart from general sessions, as per me, below are the highlights.
i) VMware cloud on AWS (VMC or VMW on AWS): As expected, VMC had a lot of coverage across quick talks and breakout sessions. For me, the most insightful breakout session on VMC was by Solution Architect from Amazon and Technical marketing director from VMware i.e. “Business value of VMware Cloud on AWS”. In addition to these sessions, I attended some more insightful breakout sessions on VMC as well as other VMware products.

Here are some of top sessions from VMworld Europe

Here are some of top sessions from VMworld US

William Lam has compiled very nice list of all breakout sessions available on youtube

ii). Hands on Labs: After attending couple of sessions on VMC, I was very much interested in how this works for customer in action. This is where VMC on AWS HOL helped. It was truly great experience playing with very slick HTML5 based VMC interface & configuring various VMC components.

Here are more learning resources on VMware cloud on AWS

For learning VMware products, please look at Hands on lab

iii) Solution Exchange: This is the place where all of our partner ecosystem display their solutions. I visited 6-7 booths out of many others. It was heartening to see how VMware partner ecosystem has developed solutions around VMware products.

iv) Meeting with people: After communicating with many VMware & vExperts community members over email, blogs & twitter for last 3-4 years, it was exciting to meet some of VMware as well as vExperts community personally.

Selfie with Katie Bradely, vExpert Community manager

v) Things I missed: There are couple of things I missed as my tech-talks were scheduled on back-to-back days. However, as VMworld schedule is such huge, multiple tracks at the same time, we cannot catch everything as well. Having said that, I think, I missed to be part of VMworld Hackthon organized by our very own champs “William Lam”(@lamw) & “Alan Renouf”(@alanrenouf). I heard it was really cool (However, I did personally meet both of them on the way & visited VMware {code } booth to know all the programs they run). Another thing I missed is getting signed copy of this great & most sought book “VMware vSphere 6.5 Host Resources Deep Dive” by “Frank Denneman (@FrankDenneman) & Niels Hagoort (@NHagoort)”. Of course, I missed some of live breakout sessions but I can listen to recorded ones.

Here is blog post by William on VMworld Hackathon

Know more about VMware {code }

vi) Exploring Barcelona: Since BCN vs IST difference is just 3+ hrs, jet lag was not an issue & even temperature was similar what we have now in BLR. I explored BCN on the way back from VMworld Venue to hotel (5.5 KM) by walk, it was very pleasant experience. Yes, food was the issue but fortunately, I got “Indian Bollywood restaurant” walk-able distance from my hotel. In addition, being in Barcelona, I could feel the craze about football (During Barcelona vs Juventus match), how people worship players like Messi (Similar to Cricket in India). I would have liked visiting some places there but could not manage during my short trip.


vi) Parties/goodies & VMware store:
There was exclusive vExpert party arranged by our digital marketing team. Our own vSphere team has awarded all vExpert a Swag Bag containing “Power Bank, Book, Pen, bottle & some cool stickers”. In addition, many partners were giving away lot of goodies such as T-shirts, stickers, hat, bags etc. As I visited some of booths, I did get some of them & who does not like goodies? In addition, I enjoyed looking into VMware related books & official merchandise at VMware store. It was heartening to see the book that I reviewed as technical reviewer i.e. vSphere Design essentials.

vii) Other interesting booths: There were some more exciting booths/lounge such as “meet the experts” & “vmware educational services”.

Overall, I had a great trip, met many people, and learned a few things. Clearly, VMworld is a great platform to interact with VMware people, customers & vExperts

VMworld 2017 session voting : Great opportunity to influence VMworld 2017 agenda

VMworld 2017 session voting is started couple of weeks back and if you ask me, this is great opportunity for us to influence what we would like to see at this mega event. I thought to just have one small post asking for your votes for some sessions we have submitted.

If you do not know what is VMworld: VMworld is a global conference for virtualization and cloud computing, hosted by VMware. It is the number-one event for enabling the digital enterprise. VMworld 2017 brings you innovation to accelerate your journey to a software-defined business—from mobile devices to the data center and the cloud. Every year VMware hosts this mega event both in US as well as Europe

This year, there are record 1300+ sessions submitted by VMware fraternity (VMware customers, partners, vExperts, Employees) on multiple areas such as Cloud Computing, End User Computing (EUC), Software Defined Datacenter (SDDC) and mobility management etc.

Below are the sessions we submitted. If you like these sessions,please make sure you vote before 13th April.

1. DRS Cluster Rules Manager :New configuration management approach [2175] (Breakout session: 60 min)

2. Quick talk on VMware Log Tuner (VLT) [2203] (Quick talk: 30 min)

3. Overview on DRS Cluster Rules Manager :New configuration management approach [2752] (Quick talk : 30 min):

Session 1 & 3 are about the fling that we recently released. i.e. Cluster Rules Manager . We would like to take the configuration management approach demonstrated by this fling to the several specialized use-cases from vCenter server.

Here are some of FAQs can help you on casting your valuable vote

Q: How do I cast my vote?
A: First, head over to the voting site: https://my.vmworld.com/scripts/catalog/uscatalog.jsp

Next:
1. Click on the each above link or Search for each sessions listed above, you can either search using session name or ID
2. To vote for a session, click on the star value (1-5 stars) on the Session ID to indicate your preference. off-course, we want 5 stars.
3. You’ll be prompted to log in (if not already logged in) to your VMworld account to have your vote recorded. (If you don’t have a VMworld account, you can set one up for free: https://www.vmworld.com/myvmworld-update!input.jspa)
4. Colored stars confirms that you have successfully voted.

Note: As per me, it is great to open VMworld account using our official email id.

Q:How many sessions can I vote on?
A:You can vote on as many sessions as you’d like. However, you may not vote multiple times for the same session.

Q: How does my vote impact the VMworld 2017 agenda?
A: Your vote will be considered by the VMware Content Team as they make decisions about 2017 session content. In addition, the VMworld 2017 program reserves space on the agenda for “customer choice” sessions that receive particularly high ratings. Tell a friend to vote, and you might see your favorite session on the agenda this August or September.

Q: Who can participate in session voting?
A: Session voting is open to everyone. You will need to log in to your vmworld.com account to participate. If you do not have a vmworld.com account, you can set one up for free. : https://www.vmworld.com/myvmworld-update!input.jspa

Complete VMworld 2017 Session voting FAQs

Some of useful VMware PowerCLI scripts added into VMware Sample Exchange

Recently while working on couple of customer cases, I had to write some useful vSphere PowerCLI scripts. I had submitted these scripts on VMware Sample Exchange, I thought to share on blog as well. If you haven’t still explored VMware Sample Exchange , please have your “My VMware” account created (Mandatory to have My VMware account to contribute or request) and enjoy the single pane of glass for VMware API samples across any product, any programming language and any platform (including CLIs). You can browse already existing samples as well as request new API sample that you are looking for. This is really cool site for learning VMware APIs, it is a must book-mark if you ask me. Here is the VMTN Sample Exchange community for more details.

Here we go for the PowerCLI scripts that I am talking about.

Below are the use-cases these script will help you on.

1. Report on vSphere compute cluster usage/capacity data on CPU, Memory and Storage.
2. Report on DRS VM-VM affinity rules associated with each VMs in the cluster.
3. Solution 1 : Report on VMs with “multi-writer” flag enabled.
4. Solution 2: Report on VMs with “multi-writer” flag enabled.

1. Report on vSphere compute cluster usage/capacity data on CPU, Memory and Storage. Sample exchange script location

< # .SYNOPSIS Getting Cluster usage/capacity data on CPU, Memory and Storage .NOTES Author: Vikas Shitole .NOTES Site: www.vThinkBeyondVM.com .NOTES Reference: http://vthinkbeyondvm.com/category/powercli/ .NOTES Please add the vCenter server IP/credentails as per your environment #>

Connect-VIServer -Server 10.92.166.82 -User Administrator@vsphere.local -Password xyz!23

$report = @()

Write-host "Report Generation is in Progress..."

foreach ($cluster in Get-Cluster ){

$row = '' | select ClusterName,CpuCapacity , CpuUsed, MemCapacity,MemUsed ,StorageCapacity,StorageUsed

$cluster = Get-Cluster -Name $clusterName
$cluster_view = Get-View ($cluster)
$resourceSummary=$cluster_view.GetResourceUsage()
$row.ClusterName =$cluster_view.Name
$row.CpuCapacity =$resourceSummary.CpuCapacityMHz
$row.CpuUsed =$resourceSummary.CpuUsedMHz
$row.MemCapacity =$resourceSummary.MemCapacityMB
$row.MemUsed =$resourceSummary.MemUsedMB
$row.StorageCapacity =$resourceSummary.StorageCapacityMB
$row.StorageUsed =$resourceSummary.StorageUsedMB

$report += $row
}
$report | Sort ClusterName | Export-Csv -Path "D:Clusterstats.csv" #Please change the CSV file location

Write-host "Report Generation is completed, please chekc the CSV file"

2. Report on DRS VM-VM affinity rules associated with each VMs in the cluster. Sample Exchange script location

< # .SYNOPSIS Getting DRS VM-VM affinity rules associated with each VMs in the cluster. .NOTES Author: Vikas Shitole .NOTES Site: www.vThinkBeyondVM.com .NOTES Reference: http://vthinkbeyondvm.com/category/powercli/ .NOTES Please add the vCenter server IP/credetails as per your environment #>

Connect-VIServer -Server 10.192.x.y -User Administrator@vsphere.local -Password xyz!23

$clusterName = "BLR" #Your cluster name
$cluster = Get-Cluster -Name $clusterName
$vms = Get-View ($cluster| Get-VM)
$cluster_view = Get-View ($cluster)

$report = @()

Write-host "Report Generation is in Progress..."

foreach ($vm in $vms ){

$row = '' | select VMName, Rules
$rules=$cluster_view.FindRulesForVm($vm.MoRef)
$ruleNameArray=" "
#There can be more than one rule assciated with single VM
foreach($rule in $rules){
$ruleNameArray+=$rule.Name
$ruleNameArray+=","
}
$row.VMName =$vm.Name
$row.Rules = $ruleNameArray
$report += $row
}
$report | Sort Name | Export-Csv -Path "D:VMsRules.csv" #Please change the CSV file location

Write-host "Report Generation is completed, please chekc the CSV file"

3. Solution 1 : Report on VMs with “multi-writer” flag enabled. Sample exchange script location

< # .SYNOPSIS: This script first downloads all the VMX files (per host/cluster/datacenter/VC)at specified file location .Once downloaded, it will scan each VMX file one by one to get "multi-writer" entry inside VMX .Finally it will list all matching VMX file names into specified file location. .As it downloads all the VMX files, it is going to take more time, that should be fine. .It is all right to download the VMX file when VM is up and running. .If name of the VM is changed, VMX file can be different from VM display name (visible from inventory). .There are 2 file locations you need to specify. 1. Directory where VMX file will be downloaded 2. Output file. .NOTES Author: Vikas Shitole .NOTES Site: www.vThinkBeyondVM.com .NOTES Reference: http://vthinkbeyondvm.com/category/powercli/ and https://communities.vmware.com/message/2269363#2269363 .NOTES Please add the vCenter server IP/credetails as per your environment .NOTES Alternatively you can use this script where API properties are used. https://github.com/vThinkBeyondVM/vThinkBVM-scripts/blob/master/Powershell-PowerCLI/VMMultiWriterReport.ps1 #>

Write-host "Connecting to vCenter server.."
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false -DisplayDeprecationWarnings:$false -Scope User
Connect-VIServer -Server 10.192.67.143 -User administrator@vsphere.local -Password Admin!23

$tgtFolder = "C:\Temp\VMX\" #Create this directory as per your environment
#$tgtString = 'scsi0:0.sharing="multi-writer"'
$tgtString = '"multi-writer"'
foreach ($vm in Get-VM ){

Get-VM -Name $vm.get_Name() | %{
$dsName,$vmxPath = $_.ExtensionData.Config.Files.VmPathName.Split()
$dsName = $dsName.Trim('[]')
$ds = Get-Datastore -Name $dsName
New-PSDrive -Location $ds -Name DS -PSProvider VimDatastore -Root "\" | Out-Null
Copy-DatastoreItem -Item "DS:$vmxPath" -Destination $tgtFolder
Remove-PSDrive -Name DS -Confirm:$false
}

}
Get-ChildItem -Path $tgtFolder -Filter "*.vmx" | Where {Get-Content -Path $_.FullName | Select-String -Pattern $tgtString} | Select Name | Out-File C:\test1.txt
Write-host "Execution is done... please check the file with all VMX file names."

# Below cmdlet can help to scan VMs per Datacenter/Datastore/Host/Cluster. Please modify the script as required.

#$myDatacenter = Get-Datacenter -Name "MyDatacenter"
#Get-VM -Location $myDatacenter

#$myDatastore = Get-Datastore -Name "MyDatastore"
#Get-VM -Datastore $myDatastore

#$myHost=Get-VMHost -Name "HostName"
#Get-VM -Location $myHost

#$myCluster=Get-Cluster -Name "ClusterName"
#Get-VM -Location $myCluster

4. Solution 2 : Report on VMs with “multi-writer” flag enabled. Sample Exchange script location

< # .SYNOPSIS: This script connects to the vCenter Server and prepares a report on All VMs with at-least one disk enabled with "Multi-Writer" sharing. .Report will be generated as CSV file with "VM Name". This can be modified to add some more columns as needed .VC IP/UserName/Password are hardcoded below, please change them as per your environment .By default this script scans all the VMs/VMDK in the vCenter Server. It can be easily twicked to scan VM per cluster or host or datacenter .NOTES Author: Vikas Shitole .NOTES Site: www.vThinkBeyondVM.com .NOTES Reference: http://vthinkbeyondvm.com/category/powercli/ .NOTES Please add the vCenter server IP/credetails as per your environment Alternate solution by scanning VMX file is here: https://github.com/vThinkBeyondVM/vThinkBVM-scripts/blob/master/Powershell-PowerCLI/VMMultiWriterReport2.ps1 #>

Write-host "Connecting to vCenter server.."
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false -DisplayDeprecationWarnings:$false -Scope User
Connect-VIServer -Server 10.192.x.y -User administrator@vsphere.local -Password xyz@123

$report = @()
Write-host "Report Generation is in Progress..."

foreach ($vm in Get-VM ){
$view = Get-View $vm
$settings=Get-AdvancedSetting -Entity $vm
if ($view.config.hardware.Device.Backing.sharing -eq "sharingMultiWriter" -or $settings.value -eq "multi-writer"){
$row = '' | select Name
$row.Name = $vm.Name
$report += $row
}

}
$report | Sort Name | Export-Csv -Path "D:MultiWriter.csv" #Please change the CSV file location

Write-host "Report is generated successfully, please check the CSV file at specified location"

#If you want to generate report per Datacenter/Datastore/Host/Cluster, modify script using below code.

#$myDatacenter = Get-Datacenter -Name "MyDatacenter"
#Get-VM -Location $myDatacenter

#$myDatastore = Get-Datastore -Name "MyDatastore"
#Get-VM -Datastore $myDatastore

#$myHost=Get-VMHost -Name "HostName"
#Get-VM -Location $myHost

#$myCluster=Get-Cluster -Name "ClusterName"
#Get-VM -Location $myCluster

Great vSphere API ever: Part -I : placevm() API which places the VM on best possible host and datastore

This is the vSphere API personally I was waiting for since long days, I believe this is one of the powerful vSphere APIs ever. The API I am talking about is introduced as part of vSphere 6.0 i.e. placevm(). Here is the API reference for the same.

Why this API is so powerful?
-Basically this API helps to place the VM on appropriate host and datastore. Placing the VM can be as part of creating the VM, relocating the VM, cloning the VM or re-configuring the existing VM.
-How does this API achieves the best host from CPU and Memory perspective and datastore from storage perspective? As per API reference, this API can be invoked to ask DRS (Distributed resource scheduler) for a set of recommendations for placing a virtual machine and its virtual disks into a DRS cluster.
-This API offers so much flexibility that, from storage perspective, it can take input as set of datastores of our choice as well as set of SDRS (Storage DRS) PODs, we can even specify one particular datastore of our choice. From compute perspective, it takes set of hosts or particular host as input. How cool is that when DRS is involved and SDRS POD(s)?
-It also gives us flexibility on not to specify any hosts as well as datastores, in that case, it automatically picks all the hosts inside the DRS cluster and all the datastores connected to hosts inside the cluster.
– Another beauty of this API is, it works perfectly with SPBM (Storage Policy Based Management) as well as across vCenter server. is not it something great capability into single API?

Lets learn now how to use this API in real time. For the sake simplicity I have divided this post into 2 parts.

Part I: How to relocate a Powered ON VM from a DRS enabled cluster to another DRS enabled cluster (One SDRS POD as input) within single vCenter
Part II: How to relocate a Powered ON VM from a DRS enabled cluster to another DRS enabled cluster (Multiple SDRS PODs as input) across vCenter.

Below is the placeVM API sample that achieves the Part I where we invoke placeVM API to get the set of recommendations for VM (cpu, mem, storage) and then we invoke RelocateVM API to apply one of the first recommendations.

Same sample is available on my git hub repository as well as on VMware Sample exchange

//:: # Author: Vikas Shitole
//:: # Website: www.vThinkBeyondVM.com
//:: # Product/Feature: vCenter Server/DRS
//:: # Reference:
//:: # Description: Tutorial: PlaceVM API: Live relocate a VM from one DRS cluster to another DRS cluster (in a Datacenter or across Datacenter)
//:: # How cool is it when DRS takes care of placement from cpu/mem perspective and at the same time SDRS take care of storage placement
//::# How to run this sample: http://vthinkbeyondvm.com/getting-started-with-yavi-java-opensource-java-sdk-for-vmware-vsphere-step-by-step-guide-for-beginners/

package com.vmware.yavijava;

import java.net.MalformedURLException;
import java.net.URL;
import com.vmware.vim25.ClusterAction;
import com.vmware.vim25.ClusterRecommendation;
import com.vmware.vim25.ManagedObjectReference;
import com.vmware.vim25.PlacementAction;
import com.vmware.vim25.PlacementResult;
import com.vmware.vim25.PlacementSpec;
import com.vmware.vim25.VirtualMachineMovePriority;
import com.vmware.vim25.VirtualMachineRelocateSpec;
import com.vmware.vim25.mo.ClusterComputeResource;
import com.vmware.vim25.StoragePlacementSpecPlacementType;
import com.vmware.vim25.mo.Datacenter;
import com.vmware.vim25.mo.Datastore;
import com.vmware.vim25.mo.Folder;
import com.vmware.vim25.mo.HostSystem;
import com.vmware.vim25.mo.InventoryNavigator;
import com.vmware.vim25.mo.ManagedEntity;
import com.vmware.vim25.mo.ResourcePool;
import com.vmware.vim25.mo.ServiceInstance;
import com.vmware.vim25.mo.StoragePod;
import com.vmware.vim25.mo.VirtualMachine;

public class PlaceVMRelocate {

public static void main(String[] args) throws Exception {
if(args.length!=3)
{
System.out.println("Usage: PlaceVMRelocate url username password");
System.exit(-1);
}

URL url = null;
try
{
url = new URL(args[0]);
} catch ( MalformedURLException urlE)
{
System.out.println("The URL provided is NOT valid. Please check it...");
System.exit(-1);
}
String username = args[1];
String password = args[2];
String SourceClusterName = "Cluster1"; //Source cluster Name, It is not required to have DRS enabled
String DestinationClusterName="Cluster2"; //Destination cluster with DRS enabled
String SDRSClusterName1="POD_1"; //SDRS POD
String VMTobeRelocated="VM2"; //VM Name to be relocated to other cluster
ManagedEntity[] hosts=null;

// Initialize the system, set up web services
ServiceInstance si = new ServiceInstance(url, username,
password, true);
if(si==null){
System.out.println("ServiceInstance Returned NULL, please check your vCenter is up and running ");
}
Folder rootFolder = si.getRootFolder();
ManagedObjectReference folder=rootFolder.getMOR();
StoragePod pod1=null;

//Getting datacenter object
Datacenter dc=(Datacenter) new InventoryNavigator(rootFolder)
.searchManagedEntity("Datacenter", "vcqaDC");

//Getting SDRS POD object
pod1=(StoragePod) new InventoryNavigator(rootFolder)
.searchManagedEntity("StoragePod", SDRSClusterName1);
ManagedObjectReference podMor1=pod1.getMOR();
ManagedObjectReference[] pods={podMor1};

//Getting source cluster object, It is NOT needed to enable DRS on source cluster
ClusterComputeResource cluster1 = null;
cluster1 = (ClusterComputeResource) new InventoryNavigator(rootFolder)
.searchManagedEntity("ClusterComputeResource", SourceClusterName);

//Getting VM object to be relocated
VirtualMachine vm=null;
vm=(VirtualMachine) new InventoryNavigator(cluster1)
.searchManagedEntity("VirtualMachine", VMTobeRelocated);
ManagedObjectReference vmMor=vm.getMOR();

//Getting destination cluster object, DRS must be enabled on the destination cluster
ClusterComputeResource cluster2 = null;
cluster2 = (ClusterComputeResource) new InventoryNavigator(rootFolder)
.searchManagedEntity("ClusterComputeResource", DestinationClusterName);
ManagedObjectReference cluster2Mor=cluster2.getMOR();

//Getting all the host objects from destination cluster.
hosts = new InventoryNavigator(cluster2).searchManagedEntities("HostSystem");
System.out.println("Number of hosts in the destination cluster::" + hosts.length);
ManagedObjectReference[] hostMors=new ManagedObjectReference[hosts.length];
int i=0;
for(ManagedEntity hostMor: hosts){
hostMors[i]=hostMor.getMOR();
i++;
}

//Building placement Spec to be sent to PlaceVM API
PlacementSpec placeSpec=new PlacementSpec();
placeSpec.setPlacementType(StoragePlacementSpecPlacementType.relocate.name());
placeSpec.setPriority(VirtualMachineMovePriority.highPriority);
// placeSpec.setDatastores(dss); //We can pass array of datastores of choice as well
placeSpec.setStoragePods(pods); // Destination storage SDRS POD (s)
placeSpec.setVm(vmMor); //VM to be relocated
placeSpec.setHosts(hostMors); //Destination DRS cluster hosts/ We can keep this unset as well
placeSpec.setKey("xvMotion placement");
VirtualMachineRelocateSpec vmrelocateSpec=new VirtualMachineRelocateSpec();
vmrelocateSpec.setPool(cluster2.getResourcePool().getMOR()); //Destination cluster root resource pool
vmrelocateSpec.setFolder(dc.getVmFolder().getMOR()); //Destination Datacenter Folder
placeSpec.setRelocateSpec(vmrelocateSpec);
PlacementResult placeRes= cluster2.placeVm(placeSpec);
System.out.println("PlaceVM() API is called");

//Getting all the recommendations generated by placeVM API
ClusterRecommendation[] clusterRec=placeRes.getRecommendations();
ClusterAction[] action= clusterRec[0].action;
VirtualMachineRelocateSpec vmrelocateSpecNew=null;
vmrelocateSpecNew=((PlacementAction) action[0]).getRelocateSpec();
vm.relocateVM_Task(vmrelocateSpecNew, VirtualMachineMovePriority.highPriority);

si.getServerConnection().logout();
}

}

Notes:
– For the sake of simplicity I have hardcoded some variables, you can change as per your environment
– We can leverage this sample either within a single vCenter datacenter or across vCenter datacenters.
– All the required documentation is added inside the sample itself. Source cluster need not to be DRS enabled.
-Same Sample can used not only for relocate ops but also clone, create and reconfigure VM Ops.

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

Important tutorials to start with: Part I & Part II

Configure and Audit Latency Sensitivity enabled VMs on vSphere using vSphere API

Recently I had an opportunity to work on “Latency sensitivity feature” which was introduced in vSphere 5.5 release. This feature is one of the reasons why mission critical VMs can be run on vSphere infrastructure or vSphere enabled clouds. In this blog post, my focus is on sharing how we can configure and audit latency sensitivity enabled VMs using vSphere Java SDK. Before looking into Java SDK scripts, lets understand what is this feature in brief. Latency sensitivity feature can be enabled per VM level (From vSphere web client >> Manage >> VM options >> Latency sensitivity set to high), this feature enables vSphere admin to allocate exclusive access to physical resources for the VM, reserving 100% vCPU time ensures that exclusive PCPU access to the VM. Once vCPU time is reserved (in MHz), this features requires to reserve 100% of the VM memory. 100% memory reservation ensures memory availability for the VM, in other words, memory will not be reclaimed (in case of memory contention) from the VM as it is 100% reserved. Overall, this feature enables vSphere Admin to bypass/tune the virtualization layer and have exclusive access to the hosts physical resources. For more details on this feature I highly recommend to read this official whitepaper

So now we understood that, in order to properly configure latency sensitive VMs, admin not only needs to enable this feature but also reserve 100% of vCPU time in Mhz and 100% memory. Setting memory reservation equal to VMs configured memory is straight-forward but what about allocating vCPU time (in Mhz)? How to set proper vCPU reservation? Lets consider one example: Lets say ESXi host’s PCPU speed is 2.5 Ghz (2500 Mhz) per core. Now if your VM has 2 vCPU configured, vCPU reservation must be 2*2500=5000 Mhz i.e. Number of vCPUs*PCPU speed per core. Similarly we need to follow for any number of vCPU configured per VM. There is one more interesting point i.e. vSphere DRS interop with Latency sensitivity enabled VMs. When such VM is there inside vSphere DRS enabled cluster, one VM-Host soft rule gets created internally(not visible from Web client) with such VM and the host on which this VM is currently residing. As rule is soft, if needed (in case of imbalanced cluster) DRS can violate this rule and migrate this VM to another host. As soon as DRS migrates this VM to another host, earlier rule gets deleted automatically and new rule gets created with new host. You may ask why is this rule gets created internally. Purpose is to avoid vMotion (by DRS) of such latency sensitive VM as much as possible as vMotion can lead to performance impact though its low. (Pass-through with latency sensitive VMs can be leveraged as well, this is explained very well in above pointed white paper)

Now lets take a look at Java SDK scripts. There are 2 Java SDK scripts, one is to configure LS VM and another is for auditing all the LS enabled VMs.

1. Script to configure latency sensitivity feature on the VM

Same script can be found on VMware’s sample exchange or on my git hub account here


//:: # Author: Vikas Shitole
//:: # Website: www.vThinkBeyondVM.com
//:: # Product/Feature: vCenter Server/Latency Sensitivity of the VM(Exclusive pCPU-vCPU affinity)
//:: # Description: Script to configure latency sensitivity feature on the VM and getting list of VMs where LS is configured.
//:# How to run this sample: http://vthinkbeyondvm.com/getting-started-with-yavi-java-opensource-java-sdk-for-vmware-vsphere-step-by-step-guide-for-beginners/
//:# Reference: http://www.vmware.com/files/pdf/techpaper/latency-sensitive-perf-vsphere55.pdf

package com.vmware.yavijava;

import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import com.vmware.vim25.InvalidProperty;
import com.vmware.vim25.LatencySensitivity;
import com.vmware.vim25.LatencySensitivitySensitivityLevel;
import com.vmware.vim25.ResourceAllocationInfo;
import com.vmware.vim25.RuntimeFault;
import com.vmware.vim25.TaskInfoState;
import com.vmware.vim25.VirtualHardware;
import com.vmware.vim25.VirtualMachineConfigSpec;
import com.vmware.vim25.mo.Folder;
import com.vmware.vim25.mo.HostSystem;
import com.vmware.vim25.mo.InventoryNavigator;
import com.vmware.vim25.mo.ManagedEntity;
import com.vmware.vim25.mo.ServiceInstance;
import com.vmware.vim25.mo.Task;
import com.vmware.vim25.mo.VirtualMachine;
import com.vmware.vim25.mo.util.MorUtil;

public class ConfigLatencySensitivity {

public static void main(String[] args) throws InvalidProperty,
RuntimeFault, RemoteException, MalformedURLException {

if(args.length!=5)
{
System.out.println("Usage: Java ConfigLatencySensitivity vCurl username password hostname/IP VMName");
System.exit(-1);
}

URL url = null;
try
{
url = new URL(args[0]);
} catch ( MalformedURLException urlE)
{
System.out.println("The URL provided is NOT valid. Please check it.");
System.exit(-1);
}

ServiceInstance si = new ServiceInstance(new URL(args[0]), args[1],
args[2], true); // Pass 3 argument as vCenterIP/username/password

String VMHost=args[3]; //Host on which VM is resided
String VMToBeConfigured=args[4]; //VM name to be configured.

Folder rootFolder = si.getRootFolder();
VirtualMachine vm1 = (VirtualMachine) new InventoryNavigator(rootFolder)
.searchManagedEntity("VirtualMachine", VMToBeConfigured);

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

//Check how many Mhz CPU can be reserved per vCPU of the VM
int cpuMhz=host.getSummary().getHardware().getCpuMhz();
System.out.println("cpuMHz that can be reserved per vCPU::"+cpuMhz);

//Get RAM and vCPU configured to VM while creating that VM
VirtualHardware vHw=vm1.getConfig().getHardware();
int vmMem=vHw.getMemoryMB();
System.out.println("RAM of the VM " +vm1.getName()+" ::"+vmMem);
int vCpu=vHw.getNumCPU();
System.out.println("Number of vCPUs configured on VM "+vm1.getName()+ " are::"+ vCpu);

VirtualMachineConfigSpec vmSpec=new VirtualMachineConfigSpec();

//Set the latency sensitive level flag to "high"
LatencySensitivity ls=new LatencySensitivity();
ls.setLevel(LatencySensitivitySensitivityLevel.high);
vmSpec.setLatencySensitivity(ls);

// It is highly recommended to reserve the CPU in Mhz equal to Multiples of vCPU
ResourceAllocationInfo cpuAlloc=new ResourceAllocationInfo();
cpuAlloc.setReservation((long) (vCpu*cpuMhz));
vmSpec.setCpuAllocation(cpuAlloc);

//It is highly recommended to reserve the memory equal to RAM of the VM
ResourceAllocationInfo memAlloc=new ResourceAllocationInfo();
memAlloc.setReservation((long) vmMem);
vmSpec.setMemoryAllocation(memAlloc);

//Reconfigure the VM and check reconfigure task status
Task task=vm1.reconfigVM_Task(vmSpec);
System.out.println("Reconfigure Task started ......");

//Wait till task is either queued or running, that will help us to verify whether task is successful or not
while(task.getTaskInfo().getState().equals(TaskInfoState.queued)||task.getTaskInfo().getState().equals(TaskInfoState.running) ){
System.out.println(task.getTaskInfo().getState());
}
if(task.getTaskInfo().getState().equals(TaskInfoState.success))
{
System.out.println("Latency sensitive feature is enabled on the VM "+vm1.getName()+" successfully");
}else{

System.out.println("Latency sensitive feature is NOT enabled on the VM "+vm1.getName()+" successfully");
}

//List of VMs with latency sensitivity enabled will be printed for reference.
System.out.println("==============================================================");
System.out.println("List of VMs where Latency sensitivity feature is enabled");
System.out.println("==============================================================");
ManagedEntity[] vms = new InventoryNavigator(rootFolder).searchManagedEntities("VirtualMachine");
for(ManagedEntity vm:vms){
VirtualMachine vmMo = (VirtualMachine) MorUtil
.createExactManagedEntity(si.getServerConnection(), vm.getMOR());
if(vmMo.getConfig().getLatencySensitivity().getLevel().equals(LatencySensitivitySensitivityLevel.high)){

System.out.println(vmMo.getName());
}
}

si.getServerConnection().logout();
}

}

2. Script to audit Latency sensitivity feature configuration on all the VMs in a vCenter Server.

Same script can be found on VMware’s sample exchange or on my git hub repo here

//:: # Author: Vikas Shitole
//:: # Website: www.vThinkBeyondVM.com
//:: # Product/Feature: vCenter Server/Latency Sensitivity of the VM(Exclusive pCPU-vCPU affinity)
//:: # Description: Script to audit Latency sensitivity feature configuration on all the VMs in a vCenter Server.
//:# How to run this sample: http://vthinkbeyondvm.com/getting-started-with-yavi-java-opensource-java-sdk-for-vmware-vsphere-step-by-step-guide-for-beginners/
//:# Reference: http://www.vmware.com/files/pdf/techpaper/latency-sensitive-perf-vsphere55.pdf

package com.vmware.yavijava;

import java.util.HashMap;
import java.util.Map;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import com.vmware.vim25.InvalidProperty;
import com.vmware.vim25.LatencySensitivitySensitivityLevel;
import com.vmware.vim25.RuntimeFault;
import com.vmware.vim25.VirtualHardware;
import com.vmware.vim25.VirtualMachineConfigInfo;
import com.vmware.vim25.mo.Folder;
import com.vmware.vim25.mo.HostSystem;
import com.vmware.vim25.mo.InventoryNavigator;
import com.vmware.vim25.mo.ManagedEntity;
import com.vmware.vim25.mo.ServiceInstance;
import com.vmware.vim25.mo.VirtualMachine;
import com.vmware.vim25.mo.util.MorUtil;

public class AuditLatencySensitivityConfig {

public static void main(String[] args) throws InvalidProperty,
RuntimeFault, RemoteException, MalformedURLException {

if(args.length!=3)
{
System.out.println("Usage: Java AuditLatencySensitivityConfig vCurl username password ");
System.exit(-1);
}

URL url = null;
try
{
url = new URL(args[0]);
} catch ( MalformedURLException urlE)
{
System.out.println("The URL provided is NOT valid. Please check it.");
System.exit(-1);
}
String username = args[1]; //vCenter username
String password = args[2]; //vCenter password

// Initialize the system, set up web services

ServiceInstance si = new ServiceInstance(url, username,
password, true); // Pass 3 argument as vCenter URL/username/password

Folder rootFolder = si.getRootFolder();
System.out.println("===========================================================================================");
System.out.println("Auditing configuration of Latency Sensitivity Enabled VMs");
System.out.println("Audit criteria:");

System.out.println("1. VM with LS level set to high should have CPU reservation in multiples of vCPU configured");
System.out.println("2. VM with LS level set to high should have memory reservation equal to VM RAM");
System.out.println("===========================================================================================");

//Maps to store VMs with LS configured and mis-configured
Map lsConfiguredVms=new HashMap();
Map
lsMisConfiguredVms=new HashMap();

//Getting all the hosts available in vCenter Server inventory
ManagedEntity[] hosts = new InventoryNavigator(rootFolder).searchManagedEntities("HostSystem");

//Iterating through 1 host at a time as follows
for(ManagedEntity host1 :hosts){

HostSystem host = (HostSystem) MorUtil
.createExactManagedEntity(si.getServerConnection(), host1.getMOR());

//Check how many Mhz CPU can be reserved per vCPU wrt specified host
int cpuMhz=host.getSummary().getHardware().getCpuMhz();

//Getting all the VMs available on the host
ManagedEntity[] vms = new InventoryNavigator(host).searchManagedEntities("VirtualMachine");
if(vms!=null){
//Iterating through each and very VMs available on perticular host
for(ManagedEntity vm:vms){
VirtualMachine vmMo = (VirtualMachine) MorUtil
.createExactManagedEntity(si.getServerConnection(), vm.getMOR());

//Check whether latency sensitivity property set on the hosts or not
if(vmMo.getConfig().getLatencySensitivity().getLevel().equals(LatencySensitivitySensitivityLevel.high)){
VirtualHardware vHw=vmMo.getConfig().getHardware();
int vmMem=vHw.getMemoryMB(); //RAM of the VM
int vCpu=vHw.getNumCPU(); //vCPUs configured to the VM
VirtualMachineConfigInfo vmConfigInfo=vmMo.getConfig();
long cpuReservation=vmConfigInfo.getCpuAllocation().getReservation(); //CPU reservation on the VM
long memReservation=vmConfigInfo.getMemoryAllocation().getReservation(); //Memory reservation on the VM

//Compare mem/cpu reservation wrt configured memory/vCPUs on the host
if((cpuReservation==(vCpu*cpuMhz))&&(memReservation==vmMem)){
lsConfiguredVms.put(vmMo.getName(),host.getName());
}else{
lsMisConfiguredVms.put(vmMo.getName(),host.getName());
}
}
}
}else{
System.out.println("NO VMs available on the specified host");
}
}
System.out.println("VM list where Latency sensitivity is configured properly");
System.out.println("-------------------------------------------------------------");
for (Map.Entry< String , String> lsConfiguredVm : lsConfiguredVms.entrySet()) {
System.out.println("[" + lsConfiguredVm.getKey() + "::" + lsConfiguredVm.getValue()
+ "]");
}
System.out.println("\n VM list where Latency sensitivity is NOT configured properly");
System.out.println("-------------------------------------------------------------");
for (Map.Entry< String , String> lsMisConfiguredVm : lsMisConfiguredVms.entrySet()) {
System.out.println("[" + lsMisConfiguredVm.getKey() + "::" + lsMisConfiguredVm.getValue()
+ "]");
}
si.getServerConnection().logout();
}
}

Let me know if you need any help on this. If you have still not setup your YAVI JAVA Eclipse environment:Getting started tutorial Important tutorials to start with: Part I & Part II