1

I'm trying to get a simple inventory list of servers (by hostname) from Xencenter, using XenAPI from the python shell. However, the documentation on XenAPI seems to be pretty sparse, and I'm unable to even do a dir() on the objects that I need to learn more about.

I installed it and ran as follows:

# pip install XenAPI
# python
>>> session = XenAPI.Session("http://myhost")
>>> session.xenapi.login_with_password("myuser", "mypass")

I'm stuck here. Where pysphere has a simple way to pull all VM's, I can't figure out how to do the same thing in XenAPI. A dir(session) does not allow me to view the object -- it looks like the implementation of dict() was not done properly?

Does someone have experience with this module?

4

1 回答 1

3

例如:

>>> for opaque_ref, vm in session.xenapi.VM.get_all_records().items():
...     print vm["name_label"]

您无法获取 api 方法,dir(session)因为 XenAPI 的底层协议是 XML-RPC,而XenAPI.Session对象只是代理您的请求。

有许多全面的API 参考用于未来的信息,其中包含每个类的字段名称和方法。

由于您使用XenAPI库,因此不应将会话引用添加到所有请求并从结果中获取值: not .get_all_records("session")['Value'], but .get_all_records()XenAPI.Failure您可以使用Exception捕获所有 XenAPI 错误。

XenServer 对象表示XenAPI是一个字典,是的。

于 2012-08-29T23:51:31.177 回答