How do I detect Xen in a Python script? -


i need determine when python script running in xen virtual machine. vm running linux.

i can't find obvious in platform module. closest can appearance of 'xen' in platform.platform()

>>> platform.platform() 'linux-2.6.18-194.el5xen-x86_64-with-redhat-5.5-final' 

what best way determine this?

thanks.

fyi, if paravirtual vm, there should /proc/xen/capabilities file. if contents "control_d" then, running under dom0 else , running on domu.
dont rely on kernel version. if vm compiled custom kernel or different kernel version or modern day pv-ops kernel (which has no "xen" string in it, unlike redhat's kernel), code wont work.

on other hand, there other nifty tricks. cpuid instruction 1 such example. dont know how in python, if set eax 1 , call cpuid, bit 31 of ecx have answer. if set, running on hypervisor. else, not. works 64bit platforms.


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -