summaryrefslogtreecommitdiff
path: root/examples
Commit message (Collapse)AuthorAgeFilesLines
* examples: remove use of deprecated setDaemon methodDaniel P. Berrangé2022-06-081-6/+10
| | | | | | | | In Python 3.10 the setDaemon method was deprecated. It is redundant since the 'daemon' parameter can be given when creating the thread, or the 'daemon' attribute can be set after it was created. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
* Add support for domain event for memory device size changev7.9.0Daniel P. Berrangé2021-10-081-0/+5
| | | | Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
* Add support for memory failure event callbacksDaniel P. Berrangé2020-11-121-0/+5
| | | | Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
* examples/event-test: Fix remove return typePhilipp Hahn2020-08-061-4/+6
| | | | | | | The remove function are supposed to return 0 on success and -1 on failure. <https://libvirt.org/html/libvirt-libvirt-event.html#virEventRemoveTimeoutFunc> Signed-off-by: Philipp Hahn <hahn@univention.de>
* examples: Fix white spacePhilipp Hahn2020-08-0510-31/+71
| | | | | | | indent by 4 spaces one spaces around assignments Signed-off-by: Philipp Hahn <hahn@univention.de>
* examples: Replace sys.exit() with exit()Philipp Hahn2020-08-0510-28/+18
| | | | | | No need to import sys. Signed-off-by: Philipp Hahn <hahn@univention.de>
* examples: Cleanup importsPhilipp Hahn2020-08-058-15/+10
| | | | | | | | | | Break import into multiple lines as recommended by PEP-8 Move imports to top Remove unused imports Signed-off-by: Philipp Hahn <hahn@univention.de>
* examples: Do not use bare exceptPhilipp Hahn2020-08-052-4/+4
| | | | | | as it also catches SystemExit, InterruptedError, SyntaxError and such. Signed-off-by: Philipp Hahn <hahn@univention.de>
* examples: Convert to ArgumentParserPhilipp Hahn2020-08-0512-236/+143
| | | | | | | | Replace getopt() and hand-rolled-parser with argparse.ArgumentParser. Fix wrong header comments copy-pasted from domstart.py Signed-off-by: Philipp Hahn <hahn@univention.de>
* examples: Add/fix PEP 484 type annotationPhilipp Hahn2020-08-0511-120/+129
| | | | Signed-off-by: Philipp Hahn <hahn@univention.de>
* examples: Add missing return valuesPhilipp Hahn2020-08-051-0/+1
| | | | | | examples/dhcpleases.py:45: error: Missing return statement Signed-off-by: Philipp Hahn <hahn@univention.de>
* examples/nodestat: Fix None comparisonPhilipp Hahn2020-08-051-3/+3
| | | | | | | | | | | | | | "is" compares for "points to the same object", which for strings is the same as comparing the byte sequence itself as Python hashes each strings to only stores a unique copy of each string. > examples/nodestats.py:86:43: F632 use ==/!= to compare constant literals (str, bytes, int, float, tuple) > examples/nodestats.py:91:12: F632 use ==/!= to compare constant literals (str, bytes, int, float, tuple) > examples/nodestats.py:94:40: F632 use ==/!= to compare constant literals (str, bytes, int, float, tuple) Use "==" and "!=" for string comparsion. Signed-off-by: Philipp Hahn <hahn@univention.de>
* examples/consolecallback: Fix assorted errorsPhilipp Hahn2020-08-051-1/+2
| | | | | | | | Assert stream is opened before receiving bytes. Need to check for bytes() instead of [unicode]str(). Signed-off-by: Philipp Hahn <hahn@univention.de>
* examples/consolecallback: Add var to save callbackPhilipp Hahn2020-08-051-0/+1
| | | | | | > examples/consolecallback.py:98: error: "Console" has no attribute "stdin_watch" Signed-off-by: Philipp Hahn <hahn@univention.de>
* examples/esxlist: Fix Python 2 raw_input()Philipp Hahn2020-08-051-1/+1
| | | | | | which was renamed to input() for Python 3. Signed-off-by: Philipp Hahn <hahn@univention.de>
* examples/event-test: Use atexit for Python 3Philipp Hahn2020-08-051-5/+3
| | | | | | | | Assigning sys.exitfunc no longer works with Python 3. Use atexit.register() instead. Signed-off-by: Philipp Hahn <hahn@univention.de>
* examples/event-test: Remove unneeded global statementPhilipp Hahn2020-08-051-8/+0
| | | | | | It only needed when a value is assigned. Signed-off-by: Philipp Hahn <hahn@univention.de>
* examples/dhcp*: Fix None comparisonPhilipp Hahn2020-08-052-2/+2
| | | | | | | None should be compared with "is None" instead of "== None", as the later would invoke a "__cmp__()" method. Signed-off-by: Philipp Hahn <hahn@univention.de>
* examples/*: Remove stray semicolonPhilipp Hahn2020-08-053-4/+4
| | | | | | This is Python, not C Signed-off-by: Philipp Hahn <hahn@univention.de>
* examples: Refactor domipaddrsRadostin Stoyanov2020-07-151-51/+55
| | | | | | This patch makes domipaddrs example compatible with Python3. Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
* examples: remove docs about non-existent XML filesDaniel P. Berrangé2020-05-141-5/+0
| | | | | | | | The docs refers to XML files that don't exist in the python binding since it was split off from the main libvirt.git repo. Fixes #3 Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
* examples: Fix connection error handling 2Philipp Hahn2020-04-272-4/+6
| | | | | | | | | Fix two more cases in examples as libvirt.open*() does not return None but raises an exception Fixes: 283e2bc693746164b22226e14d6fe3ccd38a07bf Signed-off-by: Philipp Hahn <hahn@univention.de> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* examples: Fix connection error handlingPhilipp Hahn2020-04-205-11/+15
| | | | | | libvirt.open*() does not return None but raises an exception Signed-off-by: Philipp Hahn <hahn@univention.de>
* Drop support for python 2Daniel P. Berrangé2019-12-0414-14/+14
| | | | | | | | | python2 will be end of life by the time of the next libvirt release. All our supported build targets, including CentOS7, have a python3 build available. Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
* 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>