This is python and libvirt related post, beware!!
Ok now I want to check from my script, let's say :
bash> xencheck.py nameofvps
So I want the script to check if the vps name is available and active. This is what I done :
#!/usr/bin/python -u
import libvirt
import sys
import os
def Startup():
if not os.access("/proc/xen", os.R_OK):
print "System is not running Xen kernel!"
sys.exit(1)
#connect to hypervisor
conn = libvirt.open("xen:///default")
if conn == None:
print 'Failed to connect to hypervisor'
sys.exit(1)
dom0 = conn.listDomainsID()
for id in dom0:
dom1 = conn.lookupByID(id)
if dom1.name() == sys.argv[1]:
print dom1.name()
#main function to execute
def main():
Startup()
if __name__ == "__main__":
main()
Ok now I want to check from my script, let's say :
bash> xencheck.py nameofvps
So I want the script to check if the vps name is available and active. This is what I done :
#!/usr/bin/python -u
import libvirt
import sys
import os
def Startup():
if not os.access("/proc/xen", os.R_OK):
print "System is not running Xen kernel!"
sys.exit(1)
#connect to hypervisor
conn = libvirt.open("xen:///default")
if conn == None:
print 'Failed to connect to hypervisor'
sys.exit(1)
dom0 = conn.listDomainsID()
for id in dom0:
dom1 = conn.lookupByID(id)
if dom1.name() == sys.argv[1]:
print dom1.name()
#main function to execute
def main():
Startup()
if __name__ == "__main__":
main()
Comments
masokis tak pandai lagi bsd..:P
http://www.masokis.com