vmwareesxiaffinitygovmomi

Set CPU affinity for specific VM on VMware ESXI using govc CLI


I have shell scripts that I use to programmatically configure my virtual machines (VMs) on my VMware ESXi host. I use the "govc" command-line-interface (CLI) which provides a suite of commands to configure my VMs that run on my ESXI (i.e., powering on, setting ram, etc...)

I am trying now to set the CPU affinity for some of my virtual machines (i.e., VM #2 should use CPUs 9-16 whereas VM#1 should use CPU 2-8). However, I cannot find any govc command to do this programmatically, though I can very clearly see how to do this within the ESXI web-based GUI:

Enter image description here

I reference the govc API for commands here, but again, I could not find anything. The CPU affinity should be set for a specific VM, and there should be an argument of CPU numbers separated by comma or with hyphen (-) for a range, I would imagine:

govc usage

How can I fix this problem with VMware ESXi and govc?


Solution

  • As Kyle Ruddy stated, it couldn't be done via govc, but it can be done by finding your .VMX file for your respective VM on the ESXi datastore and simply add this line to your .vmx file.

    sched.cpu.affinity = 1,2,3,4,5 // Values are separated by commas
    

    You can double check your ESXi, by selecting the VM and going into its settings and you will see the CPU Scheduled Affinity Range that you set via the VMX file.

    Of course , if you have a lot of CPUs, you can have some script (Bash, etc.) with a for loop populate the comma-delimited CPU values.