Skip to contentSkip to conversation

Error getting VM-informations with Python on Xen 3.0.2

DISCUSSION Thorolf Godawa 2 participants 5 messages Apr 5, 2006 – Apr 6, 2006

lore
Share & tools
lore
#0 lore raw

Hi all,

I wrote a small python-script to monitor the status of the started VMs based on the xenmon.py and the following code I got from Anthony Liguori:

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

from xen.xend.XendClient import server
from xen.xend import sxp

def parse_doms_info(info):

    def get_info(n, t, d):
        return t(sxp.child_value(info, n, d))

    return {
        'dom'      : get_info('domid',        int,   -1),
        'name'     : get_info('name',         str,   '??'),
        'mem'      : get_info('memory',       int,   0),
        'vcpus'    : get_info('online_vcpus', int,   0),
        'state'    : get_info('state',        str,   '??'),
        'cpu_time' : get_info('cpu_time',     float, 0),
        'ssidref'  : get_info('ssidref',      int,   0),
        }

doms = server.xend_list_domains()

print 'Name ID Mem(MiB) VCPUs State Time(s)'
for dom in doms:

    d = parse_doms_info(dom)
    if (d['ssidref'] != 0):
        d['ssidstr'] = (" s:%04x/p:%04x" %
                        ((d['ssidref'] >> 16) & 0xffff,
                          d['ssidref']        & 0xffff))
    else:
        d['ssidstr'] = ""
    print ("%(name)-32s %(dom)3d %(mem)8d %(vcpus)5d %(state)5s%

(cpu_time)7.1f% (ssidstr)s" % d)
----------------------------------------

I wrote the script on SUSE SLES 10.0 Beta 3 with Xen 3.0_8659-2. Unfortunately this script (and therefor my one too) ist not running anymore with the latest SUSE SLES 10.0 Beta 9 that includes Xen 3.0.2_09434-2 :-(

It breaks at line "doms = server.xend_list_domains()" with the following error:

----------------------------------------
Traceback (most recent call last):
File "xentest1.py", line 22, in ?
doms = server.xend_list_domains()
File "/usr/lib/python2.4/xmlrpclib.py", line 1096, in __call__
return self.__send(self.__name, args)
File "/usr/lib/python2.4/xmlrpclib.py", line 1383, in __request
verbose=self.__verbose
File "/usr/lib/python2.4/site-packages/xen/util/xmlrpclib2.py", line
46, in request
return Transport.request(self, host, '/RPC2', request_body, verbose)
File "/usr/lib/python2.4/xmlrpclib.py", line 1147, in request
return self._parse_response(h.getfile(), sock)
File "/usr/lib/python2.4/xmlrpclib.py", line 1286, in _parse_response
return u.close()
File "/usr/lib/python2.4/xmlrpclib.py", line 744, in close

    raise Fault(**self._stack[0])

xmlrpclib.Fault: <Fault 1: 'Traceback (most recent call last):\n File "/usr/lib/python2.4/site-packages/xen/util/xmlrpclib2.py", line 74, in
_marshaled_dispatch\n response = self._dispatch(method, params)\n
File "/usr/lib/python2.4/SimpleXMLRPCServer.py", line 408, in
_dispatch\n raise Exception(\'method "%s" is not supported\' %
method)\nException: method "xend_list_domains" is not supported\n'>
----------------------------------------

If I see right it now uses "/usr/lib/python2.4/SimpleXMLRPCServer.py" (what does not exist in Xen 3.0_8659-2) and breaks because the method "xend_list_domains" is not supported anymore I use to get the domain-informations with the script.

Is there a better way to get the VM-status like name, memory, state, CPU-usage etc. via Python than using the mechanism from xenmon.py and the above one?

Thanks a lot for your answers,

Signature · 9 lines
Chau y hasta luego,

Thorolf

------------------------------------------------------------------
e-Mail:   mailto:[email protected]                      \|/
                                                       /'~'\
Homepage: http://www.godawa.de                        ( o o )
--------------------------------------------------oOOO--(_)--OOOo-
#1 lore raw
Quoted 35 lines · Thorolf Godawa

Hi all,

I wrote a small python-script to monitor the status of the started VMs based on the xenmon.py and the following code I got from Anthony Liguori:

[Snip]

It breaks at line "doms = server.xend_list_domains()" with the following error:

----------------------------------------
Traceback (most recent call last):
File "xentest1.py", line 22, in ?
doms = server.xend_list_domains()
File "/usr/lib/python2.4/xmlrpclib.py", line 1096, in __call__
return self.__send(self.__name, args)
File "/usr/lib/python2.4/xmlrpclib.py", line 1383, in __request
verbose=self.__verbose
File "/usr/lib/python2.4/site-packages/xen/util/xmlrpclib2.py", line
46, in request
return Transport.request(self, host, '/RPC2', request_body, verbose)
File "/usr/lib/python2.4/xmlrpclib.py", line 1147, in request
return self._parse_response(h.getfile(), sock)
File "/usr/lib/python2.4/xmlrpclib.py", line 1286, in _parse_response
return u.close()
File "/usr/lib/python2.4/xmlrpclib.py", line 744, in close

    raise Fault(**self._stack[0])

xmlrpclib.Fault: <Fault 1: 'Traceback (most recent call last):\n File "/usr/lib/python2.4/site-packages/xen/util/xmlrpclib2.py", line 74, in
_marshaled_dispatch\n response = self._dispatch(method, params)\n
File "/usr/lib/python2.4/SimpleXMLRPCServer.py", line 408, in
_dispatch\n raise Exception(\'method "%s" is not supported\' %
method)\nException: method "xend_list_domains" is not supported\n'>
----------------------------------------

Quoted 8 lines

If I see right it now uses "/usr/lib/python2.4/SimpleXMLRPCServer.py" (what does not exist in Xen 3.0_8659-2) and breaks because the method "xend_list_domains" is not supported anymore I use to get the domain-informations with the script.

Is there a better way to get the VM-status like name, memory, state, CPU-usage etc. via Python than using the mechanism from xenmon.py and the above one?

Try server.xend.domains(True). This changed with the new XML-RPC interface, courtesy of the aforementioned hacker.

Ewan.

#2 lore raw

Hi Ewan,

Quoted 2 lines

Try server.xend.domains(True). This changed with the new XML-RPC interface, courtesy of the aforementioned hacker.

thanks a lot, this solved my problem :-)))

Is there any documentation how to use these Python-interfaces?

Signature · 3 lines
Chau y hasta luego,

Thorolf
#3 lore raw
Quoted 7 lines · Thorolf Godawa

Hi Ewan,

Quoted 2 lines

Try server.xend.domains(True). This changed with the new XML-RPC interface, courtesy of the aforementioned hacker.

thanks a lot, this solved my problem :-)))

Is there any documentation how to use these Python-interfaces?

No, I'm afraid not. The XML-RPC interface will stabilise in time, but at the moment, it's not documented.  The Python interface on top of the XML-RPC is not documented either, since it's only a stub onto the XML-RPC, now.

The only interfaces that are guaranteed currently are those required to support old guests on new hypervisors. Everything else is subject to change. The best way for you to keep up is to get your code into the tree, preferably with a unit test or two, and then there's a fair chance that it won't be broken as things change.

Ewan.

#4 lore raw
Quoted 14 lines · Ewan Mellor
Quoted 7 lines · Thorolf Godawa

Hi Ewan,

Quoted 2 lines

Try server.xend.domains(True). This changed with the new XML-RPC interface, courtesy of the aforementioned hacker.

thanks a lot, this solved my problem :-)))

Is there any documentation how to use these Python-interfaces?

No, I'm afraid not. The XML-RPC interface will stabilise in time, but at the moment, it's not documented.  The Python interface on top of the XML-RPC is not documented either, since it's only a stub onto the XML-RPC, now.

Quoted 5 lines

The only interfaces that are guaranteed currently are those required to support old guests on new hypervisors. Everything else is subject to change. The best way for you to keep up is to get your code into the tree, preferably with a unit test or two, and then there's a fair chance that it won't be broken as things change.

And improvements to the documentation are always welcome: if you want to write up a tutorial, it would be gratefully received.

Ewan.