python判斷xen虛擬化上linux主機是否為虛擬機器

來源:互聯網
上載者:User

標籤:xen

華為的雲端運算採用的是xen的虛擬化,有時候我們要大致判斷下主機是否為虛擬機器。

windows主機,直接資源管理員查看硬體裝置。

而linux主機可以用python指令碼來監測

判斷 OpenVZ/Xen PV/UML

判斷 OpenVZ/Xen PV/UML 是最容易的,直接檢查 /proc 下的相關目錄和檔案就可以知道,比如 OpenVZ VPS 上會有 /proc/vz 這個檔案;Xen PV 虛擬機器上會有 /proc/xen/ 這個目錄,並且目錄下有一些東西;UML 上列印 /proc/cpuinfo 會找到 UML 標誌。寫了一個簡單的 Python 指令碼來檢測:

#!/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判斷xen虛擬化上linux主機是否為虛擬機器

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.