Juan Hernandez has uploaded a new change for review.

Change subject: sdk: Add empty export method to decorator base
......................................................................

sdk: Add empty export method to decorator base

Decorators for resources and collections extend a common base class, for
example:

  class VMSnapshotDisks(Base)

The resource decorators also extend the corresponding parameter class:

  class VMSnapshotDisk(params.Disk, Base)

This means that resource decorators implement the "export" method,
responsible for generating the XML representation of the entity, but
collection decorators don't implement it.

There are situations where decorators are used as parameters, for
example, when creating a VM from a snapshot one could use the following
code:

  snapshot = vm.snapshots.get(id="...")

The resulting object is a decorator, and it contains references to
decorators of collections, for example to the collection of disks. Later
this object can be used as a parameter, as follows:

  snapshots = ovirtsdk.xml.params.Snapshots()
  snapshots.add_snapshot(snapshot)
  newvm = ovirtsdk.xml.params.VM(
    name="newvm",
    snapshots=snapshots,
    ...)
  api.vms.add(newvm)

When doing this the infrastructure will try to generate the XML
document, calling the "export" method on the new VM object, and this
will recursively call the "export" methods of all the referenced
objects, including the collection decorators, which will fail because
they don't have such method.

This usage is not good practice, and not efficient, it is better to
avoid using decorators as parameters:

  snapshot = ovirtsdk.params.Snapshot(id="...")
  snapshots = ovirtsdk.params.Snapshots()
  snapshots.add_snapshot(snapshot)
  newvm = ovirtsdk.xml.params.VM(
    name="newvm",
    snapshots=snapshots,
    ...)
  api.vms.add(newvm)

As this is difficult to enforce this patch adds to the Base class an
empty "export" method, so that these operations won't fail.

Change-Id: I6d2e6b9a42ad1a878f8edbbd41f3bb9d60db2bc8
Bug-Url: https://bugzilla.redhat.com/1024696
Signed-off-by: Juan Hernandez <juan.hernan...@redhat.com>
---
M src/ovirtsdk/infrastructure/common.py
1 file changed, 6 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine-sdk refs/changes/96/32996/1

diff --git a/src/ovirtsdk/infrastructure/common.py 
b/src/ovirtsdk/infrastructure/common.py
index 5fbc581..5e5f714 100644
--- a/src/ovirtsdk/infrastructure/common.py
+++ b/src/ovirtsdk/infrastructure/common.py
@@ -43,3 +43,9 @@
             raise ImmutableError(name)
         else:
             super(Base, self).__setattr__(name, value)
+
+    def export(self, outfile, level, namespace_='', name_='', 
namespacedef_='', pretty_print=True):
+        # This empty method is necessary in order to avoid exceptions when the
+        # infrastructure tries to invoke it on a collection decorator that is
+        # used as a parameter.
+        pass


-- 
To view, visit http://gerrit.ovirt.org/32996
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6d2e6b9a42ad1a878f8edbbd41f3bb9d60db2bc8
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine-sdk
Gerrit-Branch: master
Gerrit-Owner: Juan Hernandez <juan.hernan...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to