Skip to main content

Python - How to check active domain

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()

Comments

Masokis said…
Uik.. guna BSD ke? hebat sguh..
masokis tak pandai lagi bsd..:P

http://www.masokis.com
fryshadow said…
BSD tu untuk projek personal je :) , daily usage guna Ubuntu je, oshirix ada kat virtualbox heheh