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

Popular posts from this blog

Complete guide to update/upgrade cakephp

This is what people always forgotten. How to update your cakephp to the latest from CLI         phpmamp composer.phar update How to upgrade to 3.* branch     phpmamp composer.phar require --update-with-dependencies "cakephp/cakephp:3.5.*"         ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev)       - Removing cakephp/cakephp (3.4.13)       - Installing cakephp/cakephp (3.5.6)         Downloading: 100% Writing lock file Generating autoload files Done !

DirectAdmin - Upgrading MySQL from 5.5 to 5.6

cd /usr/local/directadmin/custombuild mkdir -p mysql cd mysql wget http://files.directadmin.com/services/all/mysql/64-bit/5.5.41/MySQL-client-5.5.41-1.linux2.6.x86_64.rpm wget http://files.directadmin.com/services/all/mysql/64-bit/5.5.41/MySQL-devel-5.5.41-1.linux2.6.x86_64.rpm wget http://files.directadmin.com/services/all/mysql/64-bit/5.5.41/MySQL-server-5.5.41-1.linux2.6.x86_64.rpm wget http://files.directadmin.com/services/all/mysql/64-bit/5.5.41/MySQL-shared-5.5.41-1.linux2.6.x86_64.rpm cd .. ./build mysql_backup mv mysql_backups mysql_backups.`date +%F` #after this point, you can't abort rpm -e --noscripts `rpm -qa | grep MariaDB` cd mysql rpm -ivh MySQL*5.5.41*.rpm #ensure it's running. cd .. ./build set mysql 5.6 ./build set mysql_inst yes ./build mysql # confirm mysqld is running. ./build php n

VPS crash I'm moving in to blogspot

2 days ago, i noticed my vps becomes slow and have some error in log file so I inform my provider and they said the server disk got some error... and today I got a bad news that the disk is totally corrupted and my data........ totally lost.. So to put some of my setup I realised that I already have this account and I just continue my notes here :) nothnig much I can do, since I have my valuable data and post for my last blog site (myinfinityx.com), yeah.. got a few configuration that I already setup like DNS, mail server, web server ( got a few of my friend host their site with me) and etc.. so.. the journey continued here.. have fun!!