diff options
author | Daniel P. Berrange <berrange@redhat.com> | 2013-11-22 14:36:37 +0000 |
---|---|---|
committer | Daniel P. Berrange <berrange@redhat.com> | 2013-11-22 14:44:45 +0000 |
commit | 3d9e3178c4d2e18425ba6df23f27ee7b1da07453 (patch) | |
tree | e9f7ce2c8481adda52bf489263403a30e01772f3 /examples/topology.py | |
parent | d163eef08210826d17cff668ec78e8cb769e57d9 (diff) | |
download | libvirt-python-v8-3d9e3178c4d2e18425ba6df23f27ee7b1da07453.tar.gz libvirt-python-v8-3d9e3178c4d2e18425ba6df23f27ee7b1da07453.tar.xz libvirt-python-v8-3d9e3178c4d2e18425ba6df23f27ee7b1da07453.zip |
Move python example programs into python/examples/ subdirectory
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Diffstat (limited to 'examples/topology.py')
-rwxr-xr-x | examples/topology.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/examples/topology.py b/examples/topology.py new file mode 100755 index 0000000..62effe3 --- /dev/null +++ b/examples/topology.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python +# 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 |