[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: [libvirt] [Python] libvirt.libvirtError output
- From: Cole Robinson <crobinso redhat com>
- To: Ivan Vovk <ivovk intermedia net>
- Cc: "libvir-list redhat com" <libvir-list redhat com>
- Subject: Re: [libvirt] [Python] libvirt.libvirtError output
- Date: Tue, 09 Dec 2008 15:32:17 -0500
Ivan Vovk wrote:
> Hello,
>
> i have the following piece of pyhton test code:
>
> try:
> dom = conn.createXML(xmldata, 0)
> except libvirt.libvirtError, le:
> sys.stderr.write(le.message)
> as a result in case of exception i get 2 outputs in stderr:
>
> libvir: OpenVZ error : operation failed: Already an OPENVZ VM defined with the id '3005'
> operation failed: Already an OPENVZ VM defined with the id '3005'
>
> Actually, i just need only second string, which is generated by sys.stderr.write(le.message).
>
> Can an exception be raised without "uncontrolled" direction to stderr (fisrt string)?
>
Yes, you have to set a libvirt error handler, which allows the app to do
whatever they want with the raised libvirt message that by default is
printed to stderr. Here is what we use in virt-manager and virt-install:
# Register libvirt handler
def libvirt_callback(ignore, err):
if err[3] != libvirt.VIR_ERR_ERROR:
# Don't log libvirt errors: global error handler will do that
logging.warn("Non-error from libvirt: '%s'" % err[2])
libvirt.registerErrorHandler(f=libvirt_callback, ctx=None)
- Cole
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]