1
0
mirror of https://gitlab.com/libvirt/libvirt-python.git synced 2025-12-08 08:23:47 +03:00
Commit Graph

54 Commits

Author SHA1 Message Date
Philipp Hahn
389cc9d0c7 Add daemon to list of shutdown reasons
Add the support to work with libvirt commit 66a85cb13.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2018-11-26 14:13:49 +01:00
Philipp Hahn
9af6f1a5d3 event-test.py: Report ERROR events
VIR_DOMAIN_EVENT_ID_IO_ERROR and VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON
callbacks receive the same 'action' parameter, so also translate that
numeric action to a descriptive text for the first callback.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2018-11-01 14:09:20 +01:00
Philipp Hahn
c8b6e5fc3c event-test.py: Fix ERROR event
ERROR_EVENTS translates the numeric 'action' argument to a description,
not the 'reason' argument which already contains a descriptive string
like 'enospc'.

> Traceback (most recent call last):
>   File "/usr/lib/python2.7/dist-packages/libvirt.py", line 4661, in _dispatchDomainEventIOErrorReasonCallback
>     reason, opaque)
>   File "libvirt-python/examples/event-test.py", line 536, in myDomainEventIOErrorReasonCallback
>     dom.name(), dom.ID(), srcpath, devalias, action, ERROR_EVENTS[reason]))
>   File "libvirt-python/examples/event-test.py", line 474, in __getitem__
>     data = self.args[item]
> TypeError: tuple indices must be integers, not str

Fixes: f5928c6711
Signed-off-by: Philipp Hahn <hahn@univention.de>
2018-11-01 14:09:20 +01:00
Philipp Hahn
9dff88056c event-test.py: Fix blanks
Closer to pep8

Signed-off-by: Philipp Hahn <hahn@univention.de>
2018-09-24 09:06:00 +02:00
Philipp Hahn
10ba71a0a0 event-test.py: Convert CONNECTION events
to use new Description class

Signed-off-by: Philipp Hahn <hahn@univention.de>
2018-09-24 09:06:00 +02:00
Philipp Hahn
bf7c6135e8 event-test.py: Convert SECRET events
to use new Description class

Signed-off-by: Philipp Hahn <hahn@univention.de>
2018-09-24 09:06:00 +02:00
Philipp Hahn
c0235d01e7 event-test.py: Convert DEVICE events
to use new Description class

Signed-off-by: Philipp Hahn <hahn@univention.de>
2018-09-24 09:06:00 +02:00
Philipp Hahn
808625fac7 event-test.py: Convert STORAGE events
to use new Description class

Signed-off-by: Philipp Hahn <hahn@univention.de>
2018-09-24 09:06:00 +02:00
Philipp Hahn
616c7c3482 event-test.py: Convert NETWORK events
to use new Description class

Signed-off-by: Philipp Hahn <hahn@univention.de>
2018-09-24 09:06:00 +02:00
Philipp Hahn
298f90c6ef event-test.py: Convert TRAY events
to use new Description class

Signed-off-by: Philipp Hahn <hahn@univention.de>
2018-09-24 09:06:00 +02:00
Philipp Hahn
6a41da247d event-test.py: Convert DISK events
to use new Description class

Signed-off-by: Philipp Hahn <hahn@univention.de>
2018-09-24 09:06:00 +02:00
Philipp Hahn
f58fcd69d2 event-test.py: Convert GRAPHICS events
to use new Description class

Signed-off-by: Philipp Hahn <hahn@univention.de>
2018-09-24 09:06:00 +02:00
Philipp Hahn
dfa00dddd5 event-test.py: Convert AGENT events
to use new Description class

Signed-off-by: Philipp Hahn <hahn@univention.de>
2018-09-24 09:06:00 +02:00
Philipp Hahn
f5928c6711 event-test.py: Convert ERROR events
to use new Description class

Signed-off-by: Philipp Hahn <hahn@univention.de>
2018-09-24 09:06:00 +02:00
Philipp Hahn
ba45c10511 event-test.py: Convert WATCHDOG events
to use new Description class

Signed-off-by: Philipp Hahn <hahn@univention.de>
2018-09-24 09:06:00 +02:00
Philipp Hahn
e5ecf38911 event-test.py: Convert BLOCKJOB events
to use new Description class

Signed-off-by: Philipp Hahn <hahn@univention.de>
2018-09-24 09:06:00 +02:00
Philipp Hahn
257157c984 event-test.py: Convert LIVECYCLE events
to use new Description class

Signed-off-by: Philipp Hahn <hahn@univention.de>
2018-09-24 09:06:00 +02:00
Philipp Hahn
26350dc97d event-test.py: Add class for event descriptions
Signed-off-by: Philipp Hahn <hahn@univention.de>
2018-09-24 09:06:00 +02:00
Philipp Hahn
37e56947cc event-test.py: Simplify event ID lists
by directly building the list with the IDs instead of appending them
explicitly.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2018-09-24 09:06:00 +02:00
Philipp Hahn
73b5ae581c event-test.py: Merge livecycle callbacks
Registering the same function twice using the old domainEventRegister()
interface would not work, as the function reference is used for
un-registering.

But it is not a problem with the new interface domainEventRegisterAny(),
as that returns a unique ID.

While at it also demonstrate the 'opaque' mechanism.

Signed-off-by: Philipp Hahn <hahn@univention.de>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-09-24 09:06:00 +02:00
Philipp Hahn
d408dc944d event-test.py: Use __file__
instead of sys.argv[0]

Signed-off-by: Philipp Hahn <hahn@univention.de>
2018-09-24 09:05:59 +02:00
Philipp Hahn
655b94803e event-test.py: Add missing globale statement
to fix loop termination on exit.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2018-09-24 09:05:59 +02:00
Philipp Hahn
b7d5d60274 event-test.py: Remove dead assignment
variable is unused

Signed-off-by: Philipp Hahn <hahn@univention.de>
2018-09-24 09:05:59 +02:00
Philipp Hahn
5a7a871961 event-test.py: Remove extra parenthesis
Signed-off-by: Philipp Hahn <hahn@univention.de>
2018-09-24 09:05:59 +02:00
Philipp Hahn
77e700c501 event-test.py: Handle closed connection
If libvirtd terminates while event-test.py has an open connection to it,
it will crash with the following traceback:

> myConnectionCloseCallback: qemu:///session: Error
> Exception in thread libvirtEventLoop:
> Traceback (most recent call last):
>   File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
>     self.run()
>   File "/usr/lib/python2.7/threading.py", line 754, in run
>     self.__target(*self.__args, **self.__kwargs)
>   File "examples/event-test.py", line 424, in virEventLoopPollRun
>     eventLoop.run_loop()
>   File "examples/event-test.py", line 242, in run_loop
>     self.run_once()
>   File "examples/event-test.py", line 187, in run_once
>     libvirt.virEventInvokeFreeCallback(opaque)
> AttributeError: 'module' object has no attribute 'virEventInvokeFreeCallback'
>
> libvirt: XML-RPC error : internal error: client socket is closed
> Traceback (most recent call last):
>   File "examples/event-test.py", line 872, in <module>
>     main()
>   File "examples/event-test.py", line 854, in main
>     vc.secretEventDeregisterAny(id)
>   File "/usr/lib/python2.7/dist-packages/libvirt.py", line 4987, in secretEventDeregisterAny
>     if ret == -1: raise libvirtError ('virConnectSecretEventDeregisterAny() failed', conn=self)
> libvirt.libvirtError: internal error: client socket is closed
> Closing qemu:///session

Skip unregistering the event callbacks and closing the connection if the
connection is already broken / closed.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2018-09-24 09:05:59 +02:00
Philipp Hahn
d5342a9803 event-test.py: Sync list of domain lifecycle events
Add new events to prevent crash:
> Traceback (most recent call last):
>   File "/usr/lib/python2.7/dist-packages/libvirt.py", line 4601, in _dispatchDomainEventCallbacks
>     cb(self, virDomain(self, _obj=dom), event, detail, opaque)
>   File "libvirt-python/examples/event-test.py", line 505, in myDomainEventCallback1
>     domDetailToString(event, detail)))
>   File "libvirt-python/examples/event-test.py", line 484, in domDetailToString
>     return domEventStrings[event][detail]
> IndexError: tuple index out of range

Signed-off-by: Philipp Hahn <hahn@univention.de>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-09-24 09:05:59 +02:00
Michal Privoznik
bae22e3eb7 event-test.py: Sync list of storage lifecycle events
https://bugzilla.redhat.com/show_bug.cgi?id=1578337

Since libvirt 3.8.0 we have 6 events: defined, undefined,
started, stopped, created, deleted. However, the last two were
missing in a string list that translates libvirt events (int)
into human readable strings.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2018-05-22 14:22:46 +02:00
Jiri Denemark
324197bfaa event-test.py: Remove extra ( in --help output
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2018-02-06 11:58:42 +01:00
Cédric Bosdonnat
bedc937cce Don't hardcode interpreter path
This is particularly useful on operating systems that don't ship
Python as part of the base system (eg. FreeBSD) while still working
just as well as it did before on Linux.

Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
2017-11-30 08:48:36 +01:00
Martin Kletzander
36430e115d Add details for shutdown event
In commit a8eba5036cb4b0e2ec827e9e6e019ce70e451377, libvirt added
support for two more details.  In python bindings it all worked fine
automagically except an example that was not updated.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1463188

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2017-06-20 16:31:14 +02:00
Daniel P. Berrange
58c4c12ce6 event-test: add ability to run the asyncio event loop
The event test program '--loop' arg is modified to take the name
of an event loop impl to run. eg 'event-test.py --loop asyncio'

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2017-04-04 15:28:50 +01:00
Daniel P. Berrange
1c6503b800 event-test: rename example event loop impl
Use the name 'Poll' instead of 'Pure' for the event loop demo,
since there's now a second pure python loop impl available.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2017-04-04 15:28:50 +01:00
Daniel P. Berrange
4cb0508048 event-test: unregister callbacks & close conn on exit
In order to test cleanup code paths we must unregister all callbacks
and close the connection on shutdown. Since cleanup happens in the
background, we do a short sleep to allow the main loop to run its
cleanup too.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2017-04-04 15:28:50 +01:00
Daniel P. Berrange
6c8d625676 event-test: add timeout to exit event loop
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2017-04-04 15:28:50 +01:00
Daniel P. Berrange
1770fa45b4 event-test: free opaque data when removing callbacks
The pure python event loop impl has to call

  libvirt.virEventInvokeFreeCallback

to free the event opaque data from a clean stack context

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2017-04-04 15:28:50 +01:00
Peter Krempa
a927799334 event: Add handler for block threshold event
Unfortunately python doesn't generate those.
2017-03-29 16:59:39 +02:00
Michal Privoznik
cc0adce95f examples: Update event-test.py
With recent changes there are new events known to libvirt.
Reflect those changes in our event-test.py example script.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-01-10 11:29:45 +01:00
Jovanka Gulicoska
0b050dd015 event-test: support node device update callback 2016-08-17 07:38:30 -04:00
Jovanka Gulicoska
8b2d5c0643 event-test: Add node device lifecycle event tests 2016-08-02 09:55:56 -04:00
Pavel Hrdina
a3a4425338 Fix crash in storage pool refresh callback
Fixes copy-paste typo introduced by commit cb84e36c.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1354271

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-07-23 20:30:05 +02:00
Daniel P. Berrange
cb84e36cb3 Add support for storage pool refesh callback
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-06-24 21:49:09 +01:00
Jovanka Gulicoska
d42cb2b170 event-test: Add storage pool lifecycle event tests 2016-06-16 12:25:44 -04:00
Peter Krempa
1233645a28 event: Add support VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED 2016-04-18 13:18:26 +02:00
Jiri Denemark
3436387627 Add support for JOB_COMPLETED event
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-03-08 16:47:49 +01:00
Jiri Denemark
3413cc44b2 Add support for MIGRATION_ITERATION event
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-01-18 15:52:01 +01:00
Ján Tomko
cd2d02ab0d Implement the DEVICE_ADDED event 2015-04-15 18:48:23 +02:00
Pavel Hrdina
39f19f0a2d fix examples
The dhcpleases example had an old usage of print function. The formating
of leases record was also wrong.

The event-test example had an old usage of exceptions.

It's mainly to make examples compatible with python3.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2014-12-01 17:34:31 +01:00
Peter Krempa
acc47bcb71 event: Add bindings for agent lifecycle event
Also add the example.
2014-11-24 17:53:12 +01:00
Pavel Hrdina
714aa155e8 implement new tunable event
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1147639

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2014-09-30 19:15:29 +02:00
Eric Blake
87b0d97937 event-test: add missing events
Update the example to be able to trace all events.

* examples/event-test.py (main): Match full list of domain events.
(myDomainEventIOErrorReasonCallback)
(myDomainEventControlErrorCallback)
(myDomainEventBlockJobCallback, myDomainEventBlockJob2Callback)
(blockJobTypeToString, blockJobStatusToString): New functions.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-06-18 13:01:52 -06:00