Change in ovirt-engine-sdk[sdk_4.1]: Add Error.code

Code Review gerrit at ovirt.org
Wed May 17 11:15:49 UTC 2017


>From Ondra Machacek <omachace at redhat.com>:

Ondra Machacek has submitted this change and it was merged.

Change subject: Add Error.code
......................................................................


Add Error.code

This patch adds a new 'code' attribute to the Error class.

For errors that are HTTP related, this will contain the HTTP response
code. For example, if the method to retrieve a virtual machine fails
because it doesn't exist, this will contain the value 404. The users of
the SDK can use it like this:

  # Get the identifier of the virtual machine from some place, maybe
  # from a database that is out of sync with the engine:
  id = ...

  # Find the service that manages that virtual machine. Note that this
  # will always succeed, even if the virtual machine doesn't exist, as
  # the calls to the 'whatever_service' methods *do not* perform any
  # call to the server.
  vm_service = vms_service.vm_service(id)

  # Try to retrieve the virtual machine. This *does* send the request
  # to the server, hence it may fail if the virtual machine doesn't
  # exist.
  try:
    vm = vm_service.get()
  except Error as error:
    if error.code == 404:
      # The virtual machine doesn't exist, handle it.
      ...
    else:
      # Something else happened that we don't know how to handle.
      raise

For errors that aren't HTTP related, the value of the new attribute will
be 'None'.

Change-Id: Ic0ba8ab3e72c573f332990724ea042600f1fab39
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1450986
Signed-off-by: Ondra Machacek <omachace at redhat.com>
Signed-off-by: Juan Hernandez <juan.hernandez at redhat.com>
(cherry picked from commit cbdbdb6638cc2eee76747a0dfcf52ed7cf09fce7)
---
M sdk/lib/ovirtsdk4/__init__.py
M sdk/lib/ovirtsdk4/service.py
M sdk/tests/test_vm_service.py
3 files changed, 27 insertions(+), 2 deletions(-)

Approvals:
  Ondra Machacek: Verified; Looks good to me, approved
  Jenkins CI: Passed CI tests



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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ic0ba8ab3e72c573f332990724ea042600f1fab39
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine-sdk
Gerrit-Branch: sdk_4.1
Gerrit-Owner: Ondra Machacek <omachace at redhat.com>
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Ondra Machacek <omachace at redhat.com>
Gerrit-Reviewer: gerrit-hooks <automation at ovirt.org>


More information about the Engine-commits mailing list