summaryrefslogtreecommitdiff
path: root/examples
Commit message (Collapse)AuthorAgeFilesLines
* Add daemon to list of shutdown reasonsPhilipp Hahn2018-11-261-1/+1
| | | | | | Add the support to work with libvirt commit 66a85cb13. Signed-off-by: Philipp Hahn <hahn@univention.de>
* event-test.py: Report ERROR eventsPhilipp Hahn2018-11-011-2/+2
| | | | | | | | 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>
* event-test.py: Fix ERROR eventPhilipp Hahn2018-11-011-2/+2
| | | | | | | | | | | | | | | | | | 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: f5928c6711654f1496707ca77f626b3192843d57 Signed-off-by: Philipp Hahn <hahn@univention.de>
* event-test.py: Fix blanksPhilipp Hahn2018-09-241-26/+71
| | | | | | Closer to pep8 Signed-off-by: Philipp Hahn <hahn@univention.de>
* event-test.py: Convert CONNECTION eventsPhilipp Hahn2018-09-241-4/+5
| | | | | | to use new Description class Signed-off-by: Philipp Hahn <hahn@univention.de>
* event-test.py: Convert SECRET eventsPhilipp Hahn2018-09-241-8/+8
| | | | | | to use new Description class Signed-off-by: Philipp Hahn <hahn@univention.de>
* event-test.py: Convert DEVICE eventsPhilipp Hahn2018-09-241-8/+8
| | | | | | to use new Description class Signed-off-by: Philipp Hahn <hahn@univention.de>
* event-test.py: Convert STORAGE eventsPhilipp Hahn2018-09-241-12/+12
| | | | | | to use new Description class Signed-off-by: Philipp Hahn <hahn@univention.de>
* event-test.py: Convert NETWORK eventsPhilipp Hahn2018-09-241-19/+10
| | | | | | to use new Description class Signed-off-by: Philipp Hahn <hahn@univention.de>
* event-test.py: Convert TRAY eventsPhilipp Hahn2018-09-241-1/+4
| | | | | | to use new Description class Signed-off-by: Philipp Hahn <hahn@univention.de>
* event-test.py: Convert DISK eventsPhilipp Hahn2018-09-241-1/+4
| | | | | | to use new Description class Signed-off-by: Philipp Hahn <hahn@univention.de>
* event-test.py: Convert GRAPHICS eventsPhilipp Hahn2018-09-241-1/+5
| | | | | | to use new Description class Signed-off-by: Philipp Hahn <hahn@univention.de>
* event-test.py: Convert AGENT eventsPhilipp Hahn2018-09-241-9/+8
| | | | | | to use new Description class Signed-off-by: Philipp Hahn <hahn@univention.de>
* event-test.py: Convert ERROR eventsPhilipp Hahn2018-09-241-1/+7
| | | | | | to use new Description class Signed-off-by: Philipp Hahn <hahn@univention.de>
* event-test.py: Convert WATCHDOG eventsPhilipp Hahn2018-09-241-1/+5
| | | | | | to use new Description class Signed-off-by: Philipp Hahn <hahn@univention.de>
* event-test.py: Convert BLOCKJOB eventsPhilipp Hahn2018-09-241-11/+14
| | | | | | to use new Description class Signed-off-by: Philipp Hahn <hahn@univention.de>
* event-test.py: Convert LIVECYCLE eventsPhilipp Hahn2018-09-241-28/+14
| | | | | | to use new Description class Signed-off-by: Philipp Hahn <hahn@univention.de>
* event-test.py: Add class for event descriptionsPhilipp Hahn2018-09-241-0/+25
| | | | Signed-off-by: Philipp Hahn <hahn@univention.de>
* event-test.py: Simplify event ID listsPhilipp Hahn2018-09-241-41/+46
| | | | | | | by directly building the list with the IDs instead of appending them explicitly. Signed-off-by: Philipp Hahn <hahn@univention.de>
* event-test.py: Merge livecycle callbacksPhilipp Hahn2018-09-241-11/+7
| | | | | | | | | | | | | | 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>
* event-test.py: Use __file__Philipp Hahn2018-09-241-1/+1
| | | | | | instead of sys.argv[0] Signed-off-by: Philipp Hahn <hahn@univention.de>
* event-test.py: Add missing globale statementPhilipp Hahn2018-09-241-0/+1
| | | | | | to fix loop termination on exit. Signed-off-by: Philipp Hahn <hahn@univention.de>
* event-test.py: Remove dead assignmentPhilipp Hahn2018-09-241-1/+1
| | | | | | variable is unused Signed-off-by: Philipp Hahn <hahn@univention.de>
* event-test.py: Remove extra parenthesisPhilipp Hahn2018-09-241-1/+1
| | | | Signed-off-by: Philipp Hahn <hahn@univention.de>
* event-test.py: Handle closed connectionPhilipp Hahn2018-09-241-1/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* event-test.py: Sync list of domain lifecycle eventsPhilipp Hahn2018-09-241-4/+4
| | | | | | | | | | | | | | | 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>
* event-test.py: Sync list of storage lifecycle eventsMichal Privoznik2018-05-221-0/+2
| | | | | | | | | | | | 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>
* event-test.py: Remove extra ( in --help outputJiri Denemark2018-02-061-2/+2
| | | | Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
* Don't hardcode interpreter pathCédric Bosdonnat2017-11-301-1/+1
| | | | | | | | 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>
* Add details for shutdown eventMartin Kletzander2017-06-201-1/+1
| | | | | | | | | | 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>
* examples: Introduce sparsestream.pyMichal Privoznik2017-05-241-0/+117
| | | | | | | | | | Sparse streams are not that straight forward to use for the very first time. Especially the sparseRecvAll() and sparseSendAll() methods which expects callbacks. What we can do to make it easier for developers is to have an example where they can take an inspiration from. Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
* event-test: add ability to run the asyncio event loopDaniel P. Berrange2017-04-041-15/+35
| | | | | | | 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>
* event-test: rename example event loop implDaniel P. Berrange2017-04-041-15/+15
| | | | | | | 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>
* event-test: unregister callbacks & close conn on exitDaniel P. Berrange2017-04-041-36/+59
| | | | | | | | | 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>
* event-test: add timeout to exit event loopDaniel P. Berrange2017-04-041-2/+8
| | | | Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
* event-test: free opaque data when removing callbacksDaniel P. Berrange2017-04-041-1/+10
| | | | | | | | | | 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>
* event: Add handler for block threshold eventPeter Krempa2017-03-291-0/+4
| | | | Unfortunately python doesn't generate those.
* examples: Update event-test.pyMichal Privoznik2017-01-101-0/+24
| | | | | | | 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>
* event-test: support node device update callbackJovanka Gulicoska2016-08-171-0/+4
|
* event-test: Add node device lifecycle event testsJovanka Gulicoska2016-08-021-0/+16
|
* Fix crash in storage pool refresh callbackPavel Hrdina2016-07-231-1/+1
| | | | | | | | 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>
* Add support for storage pool refesh callbackv2.0.0Daniel P. Berrange2016-06-241-1/+5
| | | | Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
* event-test: Add storage pool lifecycle event testsJovanka Gulicoska2016-06-161-0/+18
|
* event: Add support VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILEDPeter Krempa2016-04-181-0/+4
|
* Add support for JOB_COMPLETED eventJiri Denemark2016-03-081-0/+3
| | | | Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
* Add support for MIGRATION_ITERATION eventJiri Denemark2016-01-181-0/+4
| | | | Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
* examples: small fix for nodestats.py examplev1.2.19Luyao Huang2015-08-261-0/+3
| | | | | | | Add nodestats.py in MANIFEST.in and add a small description for nodestats.py in README Signed-off-by: Luyao Huang <lhuang@redhat.com>
* examples: Introduce nodestats exampleMichal Privoznik2015-07-171-0/+87
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | So, this is an exercise to show libvirt capabilities. Firstly, for each host NUMA nodes some statistics are printed out, i.e. total memory and free memory. Then, for each running domain, that has memory strictly bound to certain host nodes, a small statistics of how much memory it takes is printed out too. For instance: # ./examples/nodestats.py NUMA stats NUMA nodes: 0 1 2 3 MemTotal: 3950 3967 3937 3943 MemFree: 66 56 42 41 Domain 'fedora': Overall memory: 1536 MiB Domain 'fedora22': Overall memory: 2048 MiB Domain 'fedora21': Overall memory: 1024 MiB nodes 0-1 Node 0: 1024 MiB nodes 0-1 Domain 'gentoo': Overall memory: 4096 MiB nodes 0-3 Node 0: 1024 MiB nodes 0 Node 1: 1024 MiB nodes 1 Node 2: 1024 MiB nodes 2 Node 3: 1024 MiB nodes 3 We can see 4 host NUMA nodes, all of them having roughly 4GB of RAM. Yeah, all of them has nearly all the memory consumed. Then, there are four domains running. For instance, domain 'fedora' has 1.5GB memory which is not pinned onto any specific host NUMA node. Domain 'gentoo' on the other hand has 4GB memory and has 4 NUMA nodes which are pinned 1:1 to host nodes. Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
* examples: Add example to make guest agent lifecycle event usefulPeter Krempa2015-05-113-0/+236
| | | | | | | | | | This example allows to use the guest agent event and metadata to track vCPU count set via the guest agent (agent-based onlining/offlining) and keep it persistent accross domain restarts. The daemon listens for the agent lifecycle event, and if it's received it looks into doman's metadata to see whether a desired count was set and issues the guest agent command.
* Implement the DEVICE_ADDED eventJán Tomko2015-04-151-0/+4
|