python: fix fd leak in generator.py
[libvirt-python/ericb.git] / tests / node.py
blobf199fc3c93d0b617995d18b40a24f368ecef06b0
1 #!/usr/bin/python -u
2 import libvirt
3 import sys
4 import os
6 if not os.access("/proc/xen", os.R_OK):
7 print 'System is not running a Xen kernel'
8 sys.exit(1)
10 conn = libvirt.openReadOnly(None)
11 if conn == None:
12 print 'Failed to open connection to the hypervisor'
13 sys.exit(1)
15 try:
16 (model, memory, cpus, mhz, nodes, socket, cores, threads) = conn.getInfo()
17 except:
18 print 'Failed to extract the current node information'
19 sys.exit(1)
21 print "Xen running on %d %s processors at %d MHz, %d MBytes of memory" % (
22 cpus, model, mhz, memory)
24 if cpus > nodes * socket * cores * threads:
25 print "Erroneous CPU information"
26 sys.exit(1)
28 if cpus < nodes * socket * cores * threads:
29 print "Strange, running in degrated mode, some CPU are not available"
31 del conn
32 print "OK"
34 sys.exit(0)