Skip to content

Instantly share code, notes, and snippets.

@amadorpahim
Last active December 11, 2015 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amadorpahim/4610095 to your computer and use it in GitHub Desktop.
Save amadorpahim/4610095 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# Amador Pahim <apahim@redhat.com>
# Jan 12 2013
import libvirt
from xml.dom import minidom
#c = libvirt.open("qemu:///system")
#caps = minidom.parseString(c.getCapabilities())
caps = minidom.parse("capabilities.xml")
host = caps.getElementsByTagName('host')[0]
cells = host.getElementsByTagName('cells')[0]
total_cpus = cells.getElementsByTagName('cpu').length
socketIds = []
siblingsIds = []
socketIds = [ proc.getAttribute('socket_id')
for proc in cells.getElementsByTagName('cpu')
if proc.getAttribute('socket_id') not in socketIds ]
siblingsIds = [ proc.getAttribute('siblings')
for proc in cells.getElementsByTagName('cpu')
if proc.getAttribute('siblings') not in siblingsIds ]
print "Sockets:",len(set(socketIds))
print "Cores:",len(set(siblingsIds))
print "Threads:",total_cpus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment