basic python script with libvirt
#!/usr/bin/python -u
import libvirt
import sys
import os
if not os.access("/proc/xen", os.R_OK):
print 'System is not running a Xen kernel'
sys.exit(1)
conn = libvirt.openReadOnly(None)
if conn == None:
print 'Failed to open connection to the hypervisor'
sys.exit(1)
# print conn
for id in conn.listDomainsID():
dom0 = conn.lookupByID(id)
print "Dom %s State %s" % ( dom0.name(), dom0.info()[0])
Some example :
python# ./script1.py
Please choose :
1) Show VPS
2) test 2
1
Domain Domain-0 ID 0 State 1 OS linux (Active Domain)
Domain zenvps2 ID 3 State 2 OS linux (Active Domain)
Domain zenvps ID 4 State 2 OS linux (Active Domain)
#!/usr/bin/python -u
import libvirt
import sys
import os
if not os.access("/proc/xen", os.R_OK):
print 'System is not running a Xen kernel'
sys.exit(1)
conn = libvirt.openReadOnly(None)
if conn == None:
print 'Failed to open connection to the hypervisor'
sys.exit(1)
# print conn
for id in conn.listDomainsID():
dom0 = conn.lookupByID(id)
print "Dom %s State %s" % ( dom0.name(), dom0.info()[0])
Some example :
python# ./script1.py
Please choose :
1) Show VPS
2) test 2
1
Domain Domain-0 ID 0 State 1 OS linux (Active Domain)
Domain zenvps2 ID 3 State 2 OS linux (Active Domain)
Domain zenvps ID 4 State 2 OS linux (Active Domain)
Comments