문제

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?

도움이 되었습니까?

해결책

For example:

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

Your can't get api methods by dir(session) because XenAPI's underlying protocol is XML-RPC and XenAPI.Session object just proxies your requests.

There are many comprehensive API References for future information with field names and methods for every class.

Because of you use XenAPI library, you shouldn't add session reference to all requests and fetch value from result: not .get_all_records("session")['Value'], but .get_all_records(). You can catch all XenAPI errors using XenAPI.Failure Exception.

And XenServer object representation for XenAPI is a dict, yes.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top