Bug 1444114

Summary: Missing association of writers to type in python SDK4
Product: [oVirt] ovirt-engine-sdk-python Reporter: Fabrice Bacchella <fabrice.bacchella>
Component: CoreAssignee: Juan Hernández <juan.hernandez>
Status: CLOSED CURRENTRELEASE QA Contact: Petr Matyáš <pmatyas>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 4.1.1CC: bugs, juan.hernandez, lsvaty, omachace, oourfali, stirabos
Target Milestone: ovirt-4.1.3Flags: rule-engine: ovirt-4.1+
lsvaty: testing_ack+
Target Release: 4.1.4   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: python-ovirt-engine-sdk4-4.1.4 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-07-06 13:25:31 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: Infra RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Fabrice Bacchella 2017-04-20 15:25:26 UTC
I didn't find a way to find the writer that correspond to a given type. Is there a way to do that, or it's up to the end user to manually manage this mapping ?

Comment 1 Juan Hernández 2017-04-20 15:33:33 UTC
This can be addressed adding to the SDK a new Writer.write method that can be used to generate the XML for any SDK object:

  from ovirtsdk4 import types
  from ovirtsdk4 import writer
  from ovirtsdk4 import writers

  vm = types.Vm(
    id='123',
    name='myvm',
    ...
  )

  xml = writer.Writer.write(vm)

  print(xml)

Note that this Writer class (and the equivalent Reader class) are part of the contract of the SDK, and will be kept backwards compatible. But the specific writer and reader classes, for example VmWriter and VmReader, are internal implementation details and they may change at any point without notice. So avoid using them.

Comment 2 Fabrice Bacchella 2017-05-03 08:29:06 UTC
I have started to write some code to wrap together services, types and writer.

Declaring a new set can be as simple as :

import ovlib.verb

from ovlib import ListObjectWrapper, ObjectWrapper, wrapper

from ovirtsdk4.types import Event
from ovirtsdk4.services import EventService, EventsService
from ovirtsdk4.writers import EventWriter

@wrapper(writer_class=EventWriter, type_class=Event, service_class=EventService)
class EventWrapper(ObjectWrapper):
    pass


@wrapper(service_class=EventsService, service_root="events")
class EventsWrapper(ListObjectWrapper):
    pass


The relevant code for can be found at :

https://github.com/fbacchella/ovirtcmd/blob/sdk4/ovlib/__init__.py#L193

Comment 3 Juan Hernández 2017-05-03 08:35:07 UTC
Remember that the content of the ovirtsdk4.writers package is an internal implementation detail, and that it can change or dissappear at any time without notice.

Comment 4 Fabrice Bacchella 2017-05-03 08:40:55 UTC
Until this bug is closed, I have no other choices.

Comment 5 Petr Matyáš 2017-06-02 13:01:57 UTC
Verified on 4.1.3-2