Tag Archives: EVC

vSphere 6.7: What is per-VM EVC and How to configure & manage it using pyVmomi?

Enhanced vMotion Compatibility (EVC) is without a doubt has been one of the famous vSphere features. As you know already,  EVC is a cluster level feature, which makes it possible to have vMotion across different generations of CPU within the cluster.  vSphere 6.7 has taken EVC to the next level.  This latest release has introduced one of cool features around EVC i.e. per-VM EVC.  Recently I got an opportunity to explore this cool feature and I thought to share my learning with you. In this blog post, I will take a through below items around per-VM EVC.

  • What is per-VM EVC?
  • Notes on per-VM EVC
  • per-VM EVC UI workflow
  • Configuring per-VM EVC using pyVmomi
  • Playing around featureMask using pyVmomi
  • Disabling per-VM EVC using pyVmomi
What is per-VM EVC?

As name indicates, per -VM EVC can be enabled on individual VM. Great thing about per VM EVC is that, it not only works on VMs inside the cluster but also VMs outside of the cluster.  Unlike cluster level EVC, this feature enables vMotion across clusters, standalone hosts, cross vCenters & hybrid clouds such as VMware cloud on AWS (from on-prem vCenter). How cool is that?

Notes on per-VM EVC
  • User needs to have vSphere 6.7
  • VM hardware version must be vmx-14
  • User must powered off the VM before configuring per-VM EVC
  • If user is enabling per -VM EVC on a VM, which is inside EVC enabled cluster, EVC mode on the VM should be equal or lower than that of EVC mode configured on cluster.
  • If  user wants to enable this feature from UI, only vSphere H5 client  supports it and not the flex based client.
  • per-VM EVC works fine with vSphere DRS
  • If user clones per-VM EVC configured VM, it will retain per-VM EVC configuration on cloned VM.
  • If underlying host does not support EVC mode configured on VM, VM can not power ON
  • User can enable per-VM EVC on a VM though VM is already part of a EVC enabled cluster.
per-VM EVC UI workflow

If you ask me, it is pretty easy to configure per-VM EVC from vSphere H5 client (flex client does not support). User just needs to click on the VM >> Configure >> VMware EVC >>Edit >> Configure EVC mode of your choice (of course EVC mode supported by underlying host/Cluster). Please take a look at below H5 client screenshots.

Per VM EVC UI configuration workflow

I configured “Intel ivy-bridge” EVC mode and below is how it looks like post configuration.

per VM EVC UI post configuration
Configuring per-VM EVC using pyVmomi

vSphere 6.7 has exposed a vSphere API to configure per-VM EVC i.e. ApplyEvcModeVM_Task(). We need to pass right “featureMask” to this API in order to configure appropriate EVC mode on the VM. Note that every EVC mode defines its own set of featureMask. Ex. intel-sandybridge EVC mode will have corresponding set of featureMask, so is for intel-ivybridge and so on..

Since we need to pass “featureMask” for particular EVC mode, first important thing user needs to get hold of is right EVC mode. Once we get hold of right EVC mode, we need to get corresponding  “featureMask”.  In our case, lets configure per-VM EVC on a VM residing  on a standalone host.  As I said, first we need to find max EVC mode supported on the host. This can be easily found using the script I discussed in my blog post here (Refer section on “Getting max EVCMode key“). It can be quickly found from vSphere web client or H5 client host summary as well. In my case, my host “max EVCMode”was “intel-haswell”. It does mean that I can enable per-VM EVC with featureMask for either “intel-haswell” EVC mode or lower EVCMode such as “intel-ivybridge” , “intel-sandybridge” etc.  I chose to enable per-VM EVC on “intel-ivybridge” EVC mode.

Now that we have finalized EVC mode i.e. intel-ivybridge, we now need to get hold of corresponding “featureMask”. Please take a look at below code snippet.

si= SmartConnect(host=args.host, user=args.user, pwd=args.password, sslContext=s)
supported_evc_mode=si.capability.supportedEVCMode
for evc_mode in supported_evc_mode:
	if(evc_mode.key == "intel-ivybridge"):
		ivy_mask=evc_mode.featureMask
		break

If you take a look above snippet, it is fairly easy to get featuremask for particular EVC Mode.

putting it together

This script is available on my github-repo here

 
# Author: Vikas Shitole
# Website: www.vThinkBeyondVM.com
# Product: vCenter server/ per-VM EVC (Enhanced Compatibility Mode)
# Description: Script to get enbale/disable per-VM EVC on VM
# Reference: 
# How to setup pyVmomi environment?:
# On linux:  http://vthinkbeyondvm.com/how-did-i-get-started-with-the-vsphere-python-sdk-pyvmomi-on-ubuntu-distro/
# On windows: http://vthinkbeyondvm.com/getting-started-with-pyvmomi-on-windows-supports-vsphere-6-7/


from pyVim.connect import SmartConnect
import ssl
from pyVmomi import vim
import atexit
import sys
import argparse
import getpass
 
 
def get_args():
    """ Get arguments from CLI """
    parser = argparse.ArgumentParser(
        description='Arguments for talking to vCenter')

    parser.add_argument('-s', '--host',
                        required=True,
                        action='store',
                        help='vSpehre service to connect to')

    parser.add_argument('-o', '--port',
                        type=int,
                        default=443,
                        action='store',
                        help='Port to connect on')

    parser.add_argument('-u', '--user',
                        required=True,
                        action='store',
                        help='Username to use')

    parser.add_argument('-p', '--password',
                        required=False,
                        action='store',
                        help='Password to use')

    parser.add_argument('-v', '--vmname',
                        required=True,
                        action='store',
                        default=None,
                        help='Name of the VM to be configured per VM EVC')	

    args = parser.parse_args()

    if not args.password:
        args.password = getpass.getpass(
            prompt='Enter vCenter password:')

    return args
 
 # Below method helps us to get MOR of the object (vim type) that we passed.
def get_obj(content, vimtype, name):
 obj = None
 container = content.viewManager.CreateContainerView(content.rootFolder, vimtype, True)
 for c in container.view:
  if name and c.name == name:
   obj = c
   break
 container.Destroy()
 return obj
 
 
args = get_args() 
s=ssl.SSLContext(ssl.PROTOCOL_SSLv23) # For VC 6.5/6.0 s=ssl.SSLContext(ssl.PROTOCOL_TLSv1)
s.verify_mode=ssl.CERT_NONE
 
si= SmartConnect(host=args.host, user=args.user, pwd=args.password, sslContext=s)
content=si.content
vm= get_obj(content, [vim.VirtualMachine],args.vmname)

if(vm and vm.capability.perVmEvcSupported):
        print ("VM available in vCenter server and it supports perVm EVC, thats good")
else:
        print ("VM either NOT found or perVMEvc is NOT supported on the VM")
        quit()

supported_evc_mode=si.capability.supportedEVCMode
for evc_mode in supported_evc_mode:
	if(evc_mode.key == "intel-ivybridge"):
		ivy_mask=evc_mode.featureMask
		break
	 
vm.ApplyEvcModeVM_Task(ivy_mask,True)
print ("ApplyEvcModeVM_Task() API is invoked, check out your H5 client")

Line #80: This confirms whether VM found or not and it also confirms whether VM supports per-VM EVC or not.
#86-90: It is about getting right featureMask corresponding to particular EVC Mode.
#92: Finally we called the API “ApplyEvcModeVM_Task()”

How to run this script
“python perVMEVCNew.py -s 10.161.81.159 -u Administrator@vsphere.local -v DRSPerVMEVC”, user needs to enter vCenter password. Below is how it looks like.

I looked into vSphere H5 client and this is how it looks like. isn’t it cool?

Playing with featureMask

In line #86, we learned how to get hold of featureMask. is it the only way we can get featureMask and pass it to this API? Answer is NO. There are multiple ways. However, I recommend to follow the way I did on line #86 above.
Sometime you may want to configure per-VM EVC with the same featureMask as that of EVC enabled cluster.  This can be handy specially for the VMs those are outside of the EVC cluster. In such case, you can simply copy the featureMask from EVC cluster and pass it to the per-VM EVC API. Let us take look at below code snippet.

#Cluster object
cluster = get_obj(content,[vim.ClusterComputeResource], args.cluster)

if(cluster):
        print ("Cluster available in vCenter server, thats good")
else:
        print ("Cluster is NOT available in vCenter server, please enter correct name")
        quit()
		
evc_cluster_manager=cluster.EvcManager()

evc_state=evc_cluster_manager.evcState
current_evcmode_key= evc_state.currentEVCModeKey

if(current_evcmode_key):
        print ("Current EVC Mode::"+current_evcmode_key)
else:
        print ("EVC is NOT enabled on the cluster")
        quit()
features_masked = evc_state.featureMask

Above EVC API property I had already discussed in my post on cluster level EVC APIs here (Refer: section #4 : Exploring EVC Cluster state). Here is the complete script, where featureMask is copied from EVC cluster. In addition, you can also choose to copy the featureMask from already per-VM EVC configured VM but if you do not document it properly, it can lead to confusion in future, hence it is always better to follow one way consistently to avoid any issues in future.

Disabling per-VM EVC

If you ask me, it is pretty easy. We just need to invoke the same API but without any featureMask as follows


vm.ApplyEvcModeVM_Task(None,True)

Some useful resources on EVC

1. Part-1: Managing EVC using pyVmomi
2. Part 2: Managing EVC using pyVmomi
3. Tutorial on getting started pyVmomi  on linux
4. Tutorial on getting started pyVmomi on Windows

I hope you enjoyed this post, let me know if you have any questions/doubts.

Tutorial: How to manage Enhanced vMotion Compatibility (EVC) using vSphere Python SDK pyVmomi? Part-I

As part of recent security issues i.e. Spectre & Meltdown, I got an opportunity to play around  one of famous vSphere features i.e. Enhanced vMotion Compatibility (EVC) and  I thought this is the right time to explore EVC vSphere APIs . I see that EVC APIs are made public as part of vSphere 6.0 release though feature itself was introduced in vSphere 4.0. Since there is lot to learn about EVC vSphere APIs, I thought it is better to divide this topic in 2 parts. These parts will be kind of tutorial on EVC APIs and at the same time, we will touch upon EVC functionality as well. Before we start exploring EVC APIs, it is important that you understand what EVC is all about & why one needs to enable it on cluster? For quick learning, I think, no better resource than this EVC FAQ KB. In short, EVC makes it possible to mix different generations of CPU servers inside a cluster, which enables vMotion across these servers. Once EVC is enabled on vSphere cluster level, it ensures that all the servers across different CPU generation exposes same cpuid bits to its virtual machines.

When it comes to EVC APIs, ClusterEVCManager is the major managed object, which exposes 4 important methods as follows.

  •  ConfigureEvcMode_Task()
  •  DisableEvcMode_Task()
  • CheckConfigureEvcMode_Task()
  • CheckAddHostEvc_Task()

1. Getting max EVCMode key

Before we look into above methods, we need to get max EVCMode supported by each ESXi host to be added into EVC enabled cluster. Let us take a look at simple pyVmomi script for the same.

Below script is available on my github repo getMaxEVCMode.py

#Script to get Max EVC Mode supported on all the hosts in the cluster

from pyVim.connect import SmartConnect, Disconnect
from pyVmomi import vim
import atexit
import ssl
import sys

s=ssl.SSLContext(ssl.PROTOCOL_TLSv1)
s.verify_mode=ssl.CERT_NONE
si= SmartConnect(host="10.160.50.60", user="Administrator@vsphere.local", pwd="VMware#12",sslContext=s)
content=si.content

# Your cluster name
cluster_name="vThinkBVMCluster"

# Below method helps us to get MOR of the object (vim type) that we passed.
def get_obj(content, vimtype, name):
        obj = None
        container = content.viewManager.CreateContainerView(content.rootFolder, vimtype, True)
        for c in container.view:
                if name:
                        if c.name == name:
                                obj = c
                                break
                        else:
                                obj = None
        return obj

#Cluster object
cluster = get_obj(content,[vim.ClusterComputeResource],cluster_name)
print "ClusterName::"+cluster.name

# Get all the hosts available inside cluster
hosts = cluster.host

#Iterate through each host to get MaxEVC mode supported on the host
for host in hosts:

        host_max_evcmode = host.summary.maxEVCModeKey

        if host_max_evcmode == None:
                print host.name+" does not support EVC"
        else:
                print host.name+"::"+host_max_evcmode

#Disconnect the vCenter server session.
atexit.register(Disconnect, si)

Above script takes cluster name as input, get all the hosts inside the cluster and iterate through each host in order to get max EVCMode required to enable the EVC on right mode. Line #37 is what gets us “maxEVCModeKey”. Let us take look at how output looks like

Output :
vmware@localhost:~$ python getMaxEVCModeonHost.py
ClusterName::vThinkBVMCluster
10.160.20.30::intel-broadwell
10.160.20.31::intel-sandybridge
vmware@localhost:~$

You could see, there are 2 hosts inside the cluster and their max EVCMode keys are intel-broadwell and intel-sandybridge respectively. We need to choose right max EVCMode key to enable EVC on the cluster.

You may be wondering, can EVC modes supported per host be viewed from vSphere web client? Yes, it is, please take a look at below screenshot.

2. Enable EVC on cluster

Now that we have got max EVC mode per host, let us take a look at EVC API responsible to enable EVC on the cluster. i.e. ConfigureEvcMode_Task(). This API require EVC mode to be passed as parameter.

To start with, we will pass max EVCMode as “intel-broadwell” and see what happens. Lets take a look at script below.

Below script is available on my github repo enableEVC.py

from pyVim.connect import SmartConnect, Disconnect
from pyVmomi import vim
import atexit
import ssl
import sys

#Script to enable/disable EVC on cluster

s=ssl.SSLContext(ssl.PROTOCOL_TLSv1)
s.verify_mode=ssl.CERT_NONE
si= SmartConnect(host="10.160.50.60", user="Administrator@vsphere.local", pwd="VMware#12",sslContext=s)
content=si.content

#Your cluster input
cluster_name="vThinkBVMCluster"

# Below method helps us to get MOR of the object (vim type) that we passed.
def get_obj(content, vimtype, name):
        obj = None
        container = content.viewManager.CreateContainerView(content.rootFolder, vimtype, True)
        for c in container.view:
                if name:
                        if c.name == name:
                                obj = c
                                break
                        else:
                                obj = None
        return obj

#Cluster object
cluster = get_obj(content,[vim.ClusterComputeResource],cluster_name)

# Major EVC cluster manager object
evc_cluster_manager=cluster.EvcManager()

print "ClusterName::"+cluster.name

# Configure EVC mode by passing EVCMode
task=evc_cluster_manager.ConfigureEvcMode_Task("intel-broadwell")

atexit.register(Disconnect, si)

Notice the line #40, where method is called to enable EVC. Right after executing above script, I looked into web client to see whether EVC is really enabled or not and below is what I observed.

Error displayed above is expected since we are enabling EVC on cluster with “intel-broadwell” EVCMode, which has additional cpuid bits (CPU feature set) those are NOT available on other host inside the cluster. Since “intel-broadwell” is latest intel CPU model, “intel-sandybridge” host does not have new features available. In other words, host with “intel-sandybridge” EVCMode has all the cpu features are available on “intel-broadwell” based host but not the vice-versa, hence we can only enable EVC on cluster with “intel-sandybridge or lower EVCMode.

Now before I execute above script with “intel-sandybridge” EVCMode, I powered on all the VMs available inside the cluster, once VMs are powered ON, I executed above script by editing EVCMode as “intel-sandybridge” on line #40. Since “intel-sandybridge” cpu feature set is available on “intel-broadwell”, you might be hoping that EVC will be successfully enabled on cluster. Let us take a look at web client screenshot.

You could see EVC is NOT enabled again. You might be wondering why is EVC not enabled even though EVCMode is right? As error states, since cluster has Powered-ON VMs those can potentially be using CPU features, which can not be available after enabling EVC on “intel-sandybridge” mode. Reason is EVC will mask additional CPU features (from broadwell host) to have same CPU features across all the hosts inside cluster. I hope you are following.

Now I powered-off and executed the script to enable EVC on “intel-sandybridge” mode. Let us take a look at below screenshot.

You can see EVC is enabled successfully, isn’t it cool?

Note: It is recommended to enable EVC on cluster with min of all hosts maxEVCMode key Ex. min (intel-sandybridge, intel-broadwell) = intel-sandybridge

3. Disabling EVC on cluster

Disabling EVC on cluster is fairly simple using DisableEvcMode_Task() , we have to just replace line #40 with below line.

task=evc_cluster_manager.DisableEvcMode_Task()

After making change as specified above, I confirmed from web client that EVC is successfully disabled. Please take a look at below screenshot.

EVC disabled

You can use Task object returned by ConfigureEvcMode_Task() & DisableEvcMode_Task() methods for tracking the task progress, any errors, state etc.

Now that you learned how to configure, enable & disable EVC on cluster, let us now learn how to know what cpu features are masked by EVC, what cpu features are available on each hosts inside EVC enabled cluster. If you ask me, again it is very simple.

4. Exploring EVC Cluster state

How to get current EVCMode enabled on cluster ? How to know whether EVC is disabled on cluster or not? How to get cpu features available & features masked on EVC cluster? All these questions are answered as part of below script.

Below script available on my github repo getEVCClusterState.py

from pyVim.connect import SmartConnect, Disconnect
from pyVmomi import vim
import atexit
import ssl
import sys
#Script to get Max EVC Mode supported on all the hosts in the cluster
s=ssl.SSLContext(ssl.PROTOCOL_TLSv1)
s.verify_mode=ssl.CERT_NONE
si= SmartConnect(host="10.160.50.60", user="Administrator@vsphere.local", pwd="VMware#12",sslContext=s)
content=si.content
cluster_name="vThinkBVMCluster"

# Below method helps us to get MOR of the object (vim type) that we passed.
def get_obj(content, vimtype, name):
        obj = None
        container = content.viewManager.CreateContainerView(content.rootFolder, vimtype, True)
        for c in container.view:
                if name:
                        if c.name == name:
                                obj = c
                                break
                        else:
                                obj = None
        return obj

#Cluster object
cluster = get_obj(content,[vim.ClusterComputeResource],cluster_name)
evc_cluster_manager=cluster.EvcManager()

evc_state=evc_cluster_manager.evcState
current_evcmode_key= evc_state.currentEVCModeKey

if(current_evcmode_key):
        print "Current EVC Mode::"+current_evcmode_key
else:
        print "EVC is NOT enabled on the cluster"
        quit()

feature_capabilities = evc_state.featureCapability

for capability in feature_capabilities:
        print "Feature Capability\n"
        print capability.featureName
        print capability.key
        print capability.value
        print "-------------"

features_masked = evc_state.featureMask

for mask in features_masked:
        print "Feature Masked\n"
        print mask.featureName
        print mask.key
        print mask.value
        print "-------------"
atexit.register(Disconnect, si)

That is all for Part-1, I hope you enjoyed.

Update : Part-2 is ready as well, where we will explore remaining EVC APIs i.e. CheckConfigureEvcMode_Task() & CheckAddHostEvc_Task().

For more learning, EVC official documentation is here