Mailing List Archive

trying to get some data out of XenAPI
Hi,
I wanted to try to get some data out of the XenAPI for monitoring a Xen host.

So, in the end I want ro read some of the host and vm metrics
(hints on how to get total cpu usage and vm cpu usage would be great - but I guess when i have the first steps this will be obvious). From what I heard and read about the API, this must be very easy.

But there are no simple examples to get started using the api. The xenapi_create.py seems to operate in a totally different environment - I actually don't really see how it uses the API itself.

Now I try to get started with the code from Ewan's presenbtation at the Xen summit, and I end up getting this:

The code I run:

import sys
sys.path.append('/usr/lib/python')

>from xen.xm.XenAPI import Session
session = Session('http://localhost:9363/')
session.login_with_password('henning', 'test')
print session
vm_list = session.xenapi.VM.get_all()
for vm_ref in vm_list:
vm_record = session.xenapi.VM.get_record(session, vm_ref)
print "VM name:" + vm_record.name_label
VM.start(session, vm_ref, false)
vbd_list = VM.get_VBDs(session, vm_ref)

But all I get is


<ServerProxy for localhost:9363/>
Traceback (most recent call last):
File "xenapi-test.py", line 28, in ?
vm_record = session.xenapi.VM.get_record(session, vm_ref)
File "/usr/lib/python/xen/xm/XenAPI.py", line 213, in __call__
return self.__send(self.__name, args)
File "/usr/lib/python/xen/xm/XenAPI.py", line 141, in xenapi_request
result = _parse_result(getattr(self, methodname)(*full_params))
File "/usr/lib/python/xen/xm/XenAPI.py", line 188, in _parse_result
raise Failure(result['ErrorDescription'])
xen.xm.XenAPI.Failure: The VM handle {'last_login_method': 'login_with_password', '_ServerProxy__transport': {'verbose': 0}, '_ServerProxy__handler': '/', '_ServerProxy__host': 'localhost:9363', '_ServerProxy__verbose': 0, '_ServerProxy__allow_none': 1, '_session': 'b11780a0-0bd1-a60d-7537-be5da410fb3a', '_ServerProxy__encoding': None, 'last_login_params': ['henning', 'test']} is invalid.


My authentication is set to "none" in the xend config - so any login should be working. I also tried if there is a method login() without any password, but failed, I also tried using two emtpy strings for logging in, and, last but not least, I tried to use pam authentication, but always got wrong password errors. There seem to be missing something here.

Henning




_______________________________________________
xen-api mailing list
xen-api@lists.xensource.com
http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-api
Re: trying to get some data out of XenAPI [ In reply to ]
Hi there

The python bindings 'magically' put in the session variable for you.
Give it a try without passing the session variable to VM.get_record.

Also, print out the vm_list variable and check its a list of uuids.

Cheers

Tom

On 27 May 2007, at 19:48, Henning Sprang wrote:

> Hi,
> I wanted to try to get some data out of the XenAPI for monitoring a
> Xen host.
>
> So, in the end I want ro read some of the host and vm metrics
> (hints on how to get total cpu usage and vm cpu usage would be
> great - but I guess when i have the first steps this will be
> obvious). From what I heard and read about the API, this must be
> very easy.
>
> But there are no simple examples to get started using the api. The
> xenapi_create.py seems to operate in a totally different
> environment - I actually don't really see how it uses the API itself.
>
> Now I try to get started with the code from Ewan's presenbtation at
> the Xen summit, and I end up getting this:
>
> The code I run:
>
> import sys
> sys.path.append('/usr/lib/python')
>
>> from xen.xm.XenAPI import Session
> session = Session('http://localhost:9363/')
> session.login_with_password('henning', 'test')
> print session
> vm_list = session.xenapi.VM.get_all()
> for vm_ref in vm_list:
> vm_record = session.xenapi.VM.get_record(session, vm_ref)
> print "VM name:" + vm_record.name_label
> VM.start(session, vm_ref, false)
> vbd_list = VM.get_VBDs(session, vm_ref)
>
> But all I get is
>
>
> <ServerProxy for localhost:9363/>
> Traceback (most recent call last):
> File "xenapi-test.py", line 28, in ?
> vm_record = session.xenapi.VM.get_record(session, vm_ref)
> File "/usr/lib/python/xen/xm/XenAPI.py", line 213, in __call__
> return self.__send(self.__name, args)
> File "/usr/lib/python/xen/xm/XenAPI.py", line 141, in xenapi_request
> result = _parse_result(getattr(self, methodname)(*full_params))
> File "/usr/lib/python/xen/xm/XenAPI.py", line 188, in _parse_result
> raise Failure(result['ErrorDescription'])
> xen.xm.XenAPI.Failure: The VM handle {'last_login_method':
> 'login_with_password', '_ServerProxy__transport': {'verbose': 0},
> '_ServerProxy__handler': '/', '_ServerProxy__host': 'localhost:
> 9363', '_ServerProxy__verbose': 0, '_ServerProxy__allow_none': 1,
> '_session': 'b11780a0-0bd1-a60d-7537-be5da410fb3a',
> '_ServerProxy__encoding': None, 'last_login_params': ['henning',
> 'test']} is invalid.
>
>
> My authentication is set to "none" in the xend config - so any
> login should be working. I also tried if there is a method login()
> without any password, but failed, I also tried using two emtpy
> strings for logging in, and, last but not least, I tried to use pam
> authentication, but always got wrong password errors. There seem to
> be missing something here.
>
> Henning
>
>
>
>
> _______________________________________________
> xen-api mailing list
> xen-api@lists.xensource.com
> http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-api


_______________________________________________
xen-api mailing list
xen-api@lists.xensource.com
http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-api
Re: trying to get some data out of XenAPI [ In reply to ]
> The python bindings 'magically' put in the session variable for you.

Is the Python API documented somewhere? I can't find all the stuff from the RPC docs in the Python sources.
And it's quite hard to figure the python stuff out from the xml rpc descriptions.


> Give it a try without passing the session variable to VM.get_record.
>
> Also, print out the vm_list variable and check its a list of uuids.


Now I have:

#!/usr/bin/python

import sys
sys.path.append('/usr/lib/python')
from xen.xm.XenAPI import Session
session = Session('http://localhost:9363/')
session.login_with_password(' ', ' ')
print session
host_ref = session.get_this_host
vm_list = session.xenapi.VM.get_all()
print vm_list
for vm_ref in vm_list:
vm_record = session.xenapi.VM.get_record(vm_ref)
print vm_record
print "VM name:" + vm_record["name_label"]


I'll see how far I can come with this. I guess it will take me some fiddling to find the measures I want to have. It's quite hard to get through this currently...

Henning

_______________________________________________
xen-api mailing list
xen-api@lists.xensource.com
http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-api
Re: trying to get some data out of XenAPI [ In reply to ]
>> The python bindings 'magically' put in the session variable for you.
>
> Is the Python API documented somewhere? I can't find all the stuff
> from the RPC docs in the Python sources.
> And it's quite hard to figure the python stuff out from the xml rpc
> descriptions.

The python API works reflectively, so it doesn't actually declare any
of the api. I don't think theres any documentation, but if you look
in tools/python/xen/xm/main.py it should show see how xm sets up its
xenapi connection. And theres the language independent XenAPI docs
in docs/xen-api or on the wiki.

If you want to get started quickly I wrote some java bindings with a
simple example and javadocs which might help - http://
www.cl.cam.ac.uk/~tw275/

Cheers

Tom

>> Give it a try without passing the session variable to VM.get_record.
>>
>> Also, print out the vm_list variable and check its a list of uuids.
>
> Now I have:
>
> #!/usr/bin/python
>
> import sys
> sys.path.append('/usr/lib/python')
> from xen.xm.XenAPI import Session
> session = Session('http://localhost:9363/')
> session.login_with_password(' ', ' ')
> print session
> host_ref = session.get_this_host
> vm_list = session.xenapi.VM.get_all()
> print vm_list
> for vm_ref in vm_list:
> vm_record = session.xenapi.VM.get_record(vm_ref)
> print vm_record
> print "VM name:" + vm_record["name_label"]
>
>
> I'll see how far I can come with this. I guess it will take me some
> fiddling to find the measures I want to have. It's quite hard to
> get through this currently...
>
> Henning


_______________________________________________
xen-api mailing list
xen-api@lists.xensource.com
http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-api
Re: trying to get some data out of XenAPI [ In reply to ]
Tom Wilkie wrote:
> The python API works reflectively, so it doesn't actually declare any of
> the api.

Yeah, I imagined that.

> I don't think theres any documentation, but if you look in
> tools/python/xen/xm/main.py it should show see how xm sets up its xenapi
> connection.

I'll look at this code - it might help.

> And theres the language independent XenAPI docs in
> docs/xen-api or on the wiki.

Yes, I a, trying to do that. the RPC docd give me a vague idea on how
the data structures look like anbd how I might be able to access them,
but in reality it's a lot of fiddling to get to the data I want.

Doesn't look like these bindings will get many good friends in the
programmers world in this state.

> If you want to get started quickly I wrote some java bindings with a
> simple example and javadocs which might help -
> http://www.cl.cam.ac.uk/~tw275/

I like Java very much and will look at these when writing other
management tools - but for a nagios plugin java might not be the right
thing... at least not to be called directly.

Maybe I should look at the perl bindings, but I usually try to avoid
Perl (just a matter of personal taste).

Henning

_______________________________________________
xen-api mailing list
xen-api@lists.xensource.com
http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-api