On 04/21/2017 05:26 PM, Fabrice Bacchella wrote:
I'm trying to dump informations about console with the following
code:
vm = vms_service.list(search='name=fa41')[0]
# Find the service that manages the graphics consoles of the virtual machine:
vm_service = vms_service.vm_service(vm.id)
consoles_service = vm_service.graphics_consoles_service()
console_type = consoles_service.list()[0]
console_type = connection.follow_link(console_type)
buf = None
writer = None
buf = io.BytesIO()
writer = xml.XmlWriter(buf, indent=True)
ConsoleWriter.write_one(console_type, writer)
writer.flush()
print buf.getvalue()
But i got the following result :
Traceback (most recent call last):
File "./export_console.py", line 69, in <module>
ConsoleWriter.write_one(console_type, writer)
File ".../venv/lib/python2.7/site-packages/ovirtsdk4/writers.py", line 1262,
in write_one
if obj.enabled is not None:
If I add print console_type.__dict__, it contains:
{'_address': None, '_instance_type': None, '_href':
'/ovirt-engine/api/vms/61a6de0a-2a21-4e90-bc20-29e3f0cd0ad8/graphicsconsoles/7370696365',
'_description': None, '_tls_port': None, '_comment': None,
'_port': None, '_name': None, '_vm': <ovirtsdk4.types.Vm object
at 0x1032e4310>, '_protocol': <GraphicsType.SPICE: 'spice'>,
'_template': None, '_id': '7370696365'}
Did I miss something, or is that a but with the console writer ?
The problem is that you are trying to use the ConsoleWriter class to
write something that isn't a Console. The GraphicsConsoleService.list
method returns a list of objects of type GraphicsConsole, not Console.
So you need to use GraphicsConsoleWriter.
Note that once you have the virtual machine you can obtain the graphics
consoles directly using the 'follow_link' method, no need to use the
intermediate services. For example:
vm = ...
console = connection.follow_link(vm.graphics_consoles)[0]
Remember that the WhateverWriter classes are an implementation detail,
and that they may change or disappear without notice. If you need to
convert objects to XML use the generic Writer.write method that will be
introduced by this patch:
Add generic writer
https://gerrit.ovirt.org/75699
Ondra, in what version of the SDK do we plan to include that enhancement?
I also wonder why do you need to convert objects to XML explicitly. Can
you elaborate on what is your need?