Python determines if the Linux host on Xen virtualization is a virtual machine

Source: Internet
Author: User
Tags python script


Cloud computing uses Xen virtualization, and sometimes we have to roughly determine if the host is a virtual machine.





Windows host, direct Explorer to view hardware devices.



And Linux hosts can be monitored with Python scripts



Judging Openvz/xen pv/uml



Judge Openvz/xen Pv/uml is the easiest, directly check the/PROC under the relevant directories and files can be known, such as OpenVZ VPS will have/proc/vz this file, Xen PV virtual machine will have/proc/xen/this directory, and the directory has Some things; printing/proc/cpuinfo on UML will find UML flags. Wrote a simple Python script to detect:


#!/usr/bin/python# check if a linux system running on a virtual  machine  (OPENVZ/XEN PV/UML) Import sys, osdef main ():     if  os.getuid ()  != 0:        print  "Must be  run as root "        sys.exit (0)      # check openvz/virtuozzo    if os.path.exists ("/proc/vz"):         if not os.path.exists ("/PROC/BC"):             print  "Openvz container"          else:            print   "Openvz node"     # check Xen    if  Os.path.exists ("/proc/xen/capabilities"):         if  (Os.path.getsize ("/proc/xen/capabilities")  >  0):            print  "xen dom0"          else:             print  "Xen domu"     # check user mode linux   (UML)     f = open ("/proc/cpuinfo",  "R");  t = f.read ();  f.close ()     if  (T.find ("UML")  > 0):         print  "UML" if __name__== "__main__":     main ()








Python determines if the Linux host on Xen virtualization is a virtual machine


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.