VMware Cloud Community
JimboJimmy84
Contributor
Contributor
Jump to solution

Automated VMware Affinity settings

Hello,

I have been scouring the internet to determine a way to pull CPU affinity settings on all running VMs for an ESXI host and relate that info to the inventory name. I would like to be able to pull this information in mass from a few hundred hosts and look for VMs that do not have these settings enabled or have them mis-configured.

At this point I would be satisfied with just grabbing the info so we have a list of hosts that need configurations corrected but doing this in a feasible way for 400+ hosts has proved to be quite the task. I am hoping someone knows a way to do this or can direct me. We have the ssh enabled for other automation tasks. We do not license for Essentials so this needs to be with any licensed features.

I have tried looking at vsphere-CLI but you need to have the path to the vm directory. Due to the way we deploy guests there is inconsistency with the naming structure on the folders where the vmdk and vmx files are stored so doing this in mass is not very effective.

I have tried simply opening an SSH connection and grep the .vmx files which gives me the current settings but I am not sure how to relate the .vmx file to the actual Inventory Guest. I could be able to go this route with something like Ansible or PSSH (which was my initial thought process) Also the shell does not have the --include option in grep which greatly slows down parsing through files because I cannot tell it to only look at .vmx files.

Needing this as the end result-

Affinity settings - Inventory Name of the Guest VM

Thoughts?

Thanks in advance

0 Kudos
1 Solution

Accepted Solutions
EddiePhoenix
Contributor
Contributor
Jump to solution

you can use powershell and power-cli

$vCenterName = "vcenter"

Connect-VIServer $vcenterName

$vms = Get-VM

$vms | sort name | %{"$($_.name) $((get-view $_.id).config.cpuaffinity.affinityset)"}

if you cant connect to vCenter you can have a list of host names instead of just vcenter:

$vCenterName = "host1,host2,host3"

R. Brian English, VCP5-DCV "Genius is 1% inspiration and 99% perspiration" - Thomas A. Edison

View solution in original post

0 Kudos
3 Replies
EddiePhoenix
Contributor
Contributor
Jump to solution

you can use powershell and power-cli

$vCenterName = "vcenter"

Connect-VIServer $vcenterName

$vms = Get-VM

$vms | sort name | %{"$($_.name) $((get-view $_.id).config.cpuaffinity.affinityset)"}

if you cant connect to vCenter you can have a list of host names instead of just vcenter:

$vCenterName = "host1,host2,host3"

R. Brian English, VCP5-DCV "Genius is 1% inspiration and 99% perspiration" - Thomas A. Edison
0 Kudos
JimboJimmy84
Contributor
Contributor
Jump to solution

Awesome. This was easy to install and get working. I am much closer to what I need. I have to brush up on powershell a bit to really use this tool more effectively (mostly bash and python scripting in house) but in the interim Is there a way to output the IP address of the host for each of guests as well?

Your help is much appreciated.

0 Kudos
EddiePhoenix
Contributor
Contributor
Jump to solution

no worries,

$vCenterName = "vcenter"

Connect-VIServer $vcenterName

$vms = Get-VM

$vms | sort name | %{"$($_.name) $((get-view $_.id).config.cpuaffinity.affinityset) $($_.VMHost.Name): $((Get-VMHostNetworkAdapter -VMHost $_.VMHost).IP | ?{$_ -ne ''}) "}

this will list all the IP addresses

or you can get a little more specfic by selecting the individual vmk

(Get-VMHostNetworkAdapter -VMHost $VMs[0].VMHost | ?{$_.Name -eq "vmk0"}).IP

R. Brian English, VCP5-DCV "Genius is 1% inspiration and 99% perspiration" - Thomas A. Edison
0 Kudos