1
0
mirror of https://gitlab.com/libvirt/libvirt-python.git synced 2025-07-10 00:59:41 +03:00
Files
libvirt-python/examples/topology.py
Daniel P. Berrangé b22e4f2441 Drop support for python 2
python2 will be end of life by the time of the next
libvirt release. All our supported build targets, including
CentOS7, have a python3 build available.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-12-04 12:14:51 +00:00

46 lines
1.3 KiB
Python
Executable File

#!/usr/bin/env python3
# Parse topology information from the capabilities XML and use
# them to calculate host topology
#
# Authors:
# Amador Pahim <apahim@redhat.com>
# Peter Krempa <pkrempa@redhat.com>
import libvirt
import sys
from xml.dom import minidom
try:
conn = libvirt.openReadOnly(None)
except libvirt.libvirtError:
print('Failed to connect to the hypervisor')
sys.exit(1)
try:
capsXML = conn.getCapabilities()
except libvirt.libvirtError:
print('Failed to request capabilities')
sys.exit(1)
caps = minidom.parseString(capsXML)
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("Host topology")
print("NUMA nodes:", cells.getAttribute('num'))
print(" Sockets:", len(set(socketIds)))
print(" Cores:", len(set(siblingsIds)))
print(" Threads:", total_cpus)