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/4609821 to your computer and use it in GitHub Desktop.
Save amadorpahim/4609821 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
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 = []
for proc in cells.getElementsByTagName('cpu'):
soc_id = proc.getAttribute('socket_id')
sib_id = proc.getAttribute('siblings')
socketIds.extend(soc_id)
siblingsIds.extend([sib_id])
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