使用 python 获取正在运行的域信息 +库虚拟机

发布于 2024-10-12 09:59:00 字数 489 浏览 4 评论 0原文

我正在尝试编写一个简单的脚本来获取有关在 xen 主机上运行域的各种信息。

到目前为止,我有:

import libvirt
import pprint
conn = libvirt.open('xen:///')

for id in conn.listDomainsID():
    dom = conn.lookupByID(id)
    infos = libvirt.virDomainGetInfo(dom)

这给了我以下错误:

AttributeError: 'module' object has no attribute 'virDomainGetInfo'

根据 API (http://www.libvirt.org/html/libvirt-libvirt.html#virDomainGetInfo) 至少应该返回一些东西。

有什么线索吗? (我是Python新手)

I'm trying to do a simple script that will get various informations about running domains on a xen host.

So far, i have :

import libvirt
import pprint
conn = libvirt.open('xen:///')

for id in conn.listDomainsID():
    dom = conn.lookupByID(id)
    infos = libvirt.virDomainGetInfo(dom)

which gives me the following error :

AttributeError: 'module' object has no attribute 'virDomainGetInfo'

Which, according to the API (http://www.libvirt.org/html/libvirt-libvirt.html#virDomainGetInfo) should at least return me something.

Any clue ? (i'm a python newbie)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

怪我闹别瞎闹 2024-10-19 09:59:01

要获取有关 python 中的 libvirt API 的文档,请使用内联帮助。

启动你的Python解释器(只需在shell中输入python)。

>>> import libvirt
>>> help(libvirt)

这将为您提供有关 libvirt 的详细文档。

To get documentations about the libvirt APIs in python, use the inline help.

Start your python interpreter (just type python in the shell).

>>> import libvirt
>>> help(libvirt)

This should give you a detailed documentation on libvirt.

梦在夏天 2024-10-19 09:59:01
import libvirt
import xml.etree.ElementTree as ET
conn = libvirt.open(name)
domain = conn.lookupByName(domain_name)
domain_config = ET.fromstring(domain.XMLDesc())
domain_disks = domain_config.findall('//disk')
import libvirt
import xml.etree.ElementTree as ET
conn = libvirt.open(name)
domain = conn.lookupByName(domain_name)
domain_config = ET.fromstring(domain.XMLDesc())
domain_disks = domain_config.findall('//disk')
來不及說愛妳 2024-10-19 09:59:00

来自文档: http://www.libvirt.org/python.html

There is a couple of function who don't map directly to their C counterparts due to specificities in their argument conversions:

    * virConnectListDomains is replaced by virDomain::listDomainsID(self) which returns a list of the integer ID for the currently running domains
    * virDomainGetInfo is replaced by virDomain::info() which returns a list of
         1. state: one of the state values (virDomainState)
         2. maxMemory: the maximum memory used by the domain
         3. memory: the current amount of memory used by the domain
         4. nbVirtCPU: the number of virtual CPU
         5. cpuTime: the time used by the domain in nanoseconds

From the documentation: http://www.libvirt.org/python.html

There is a couple of function who don't map directly to their C counterparts due to specificities in their argument conversions:

    * virConnectListDomains is replaced by virDomain::listDomainsID(self) which returns a list of the integer ID for the currently running domains
    * virDomainGetInfo is replaced by virDomain::info() which returns a list of
         1. state: one of the state values (virDomainState)
         2. maxMemory: the maximum memory used by the domain
         3. memory: the current amount of memory used by the domain
         4. nbVirtCPU: the number of virtual CPU
         5. cpuTime: the time used by the domain in nanoseconds
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文