Change in ovirt-engine-sdk[sdk_3.6]: Explicitly specify class to parse

juan.hernandez at redhat.com juan.hernandez at redhat.com
Thu Apr 14 09:57:02 UTC 2016


Juan Hernandez has submitted this change and it was merged.

Change subject: Explicitly specify class to parse
......................................................................


Explicitly specify class to parse

Currently when the SDK needs to parse the XML documents returned by the
server it calls the "parseString" method generated by the generateDS.py
tool. This method decides what is the type of the object checking the
root element name. For example, if the root tag is "vm" it will create
an instance of the "VM" class, if the root tag is "cluster" it will
create an instance of the "Cluster" class, etc. But in some cases this
decision isn't correct, particular if the root tag is "version" then the
class can be "Version" or "VersionCaps", as both use the same tag. As a
result, parsing the results of "/capabilities/{id}" generate an object
of class "Version", when it should generate an object of type
"VersionCaps". The consequence of this is that calling
"api.capabilities.get(id=...)" will always return the wrong type of
object. To fix this issue this patch makes the following changes:

1. Add a template to generate inside the "params.py" file a new
"parseClass" method that does almost the same than "parseString", but
that receives a parameter that explicitly indcates what should be the
type of the created object.

2. Modify the "Proxy" class so that all its methods receive and forward
a "cls" parameter containing the type of the object.

3. Modify the template for the capabilities resource so that it
explicitly passes the "VersionCaps" type to the "get" method of the
"Proxy" class.

Change-Id: I4a07fe9baeabb64f3d3b69e0eb77c2e0472b7bfd
Bug-Url: https://bugzilla.redhat.com/1326729
Signed-off-by: Juan Hernandez <juan.hernandez at redhat.com>
---
M generator/src/main/java/org/ovirt/engine/sdk/generator/python/XsdCodegen.java
M generator/src/main/java/org/ovirt/engine/sdk/generator/python/templates/CollectionGetCapabilitiesTemplate
A generator/src/main/java/org/ovirt/engine/sdk/generator/python/templates/ParseClassTemplate
A generator/src/main/java/org/ovirt/engine/sdk/generator/python/templates/ParseClassTemplate.java
M src/ovirtsdk/api.py
M src/ovirtsdk/infrastructure/brokers.py
M src/ovirtsdk/infrastructure/proxy.py
M src/ovirtsdk/xml/params.py
8 files changed, 101 insertions(+), 21 deletions(-)

Approvals:
  Juan Hernandez: Verified; Looks good to me, approved
  Jenkins CI: Passed CI tests
  Fabrice Bacchella: Looks good to me, but someone else must approve



-- 
To view, visit https://gerrit.ovirt.org/56096
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I4a07fe9baeabb64f3d3b69e0eb77c2e0472b7bfd
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine-sdk
Gerrit-Branch: sdk_3.6
Gerrit-Owner: Juan Hernandez <juan.hernandez at redhat.com>
Gerrit-Reviewer: Fabrice Bacchella <fabrice.bacchella at orange.fr>
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Juan Hernandez <juan.hernandez at redhat.com>
Gerrit-Reviewer: gerrit-hooks <automation at ovirt.org>



More information about the Engine-commits mailing list