1
0
mirror of https://gitlab.com/libvirt/libvirt-python.git synced 2024-10-26 07:55:06 +03:00
Commit Graph

275 Commits

Author SHA1 Message Date
Philipp Hahn
bc486beb0d generator: Convert to 'not in' and 'is not'
as recommended by pep8

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
Philipp Hahn
443403e7fe generator: Change type of quiet to bool
Use `bool` instead of `int`.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:00 +00:00
Philipp Hahn
ab1147f524 generator: Simplify exception handling
sys.exc_info() returns a 3-tuple (type, value, traceback), where `value`
is the instance captured by `except type as value`.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:00 +00:00
Philipp Hahn
38a1b70524 generator: Cleanup imports
Move imports to top
Remove unused import string
Remove duplicate import os

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:00 +00:00
Philipp Hahn
e16eab444f generator: Do not use bare except
as it also catches SystemExit, InterruptedError, SyntaxError and such.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:00 +00:00
Philipp Hahn
ee5c856af7 Remove legacy libvirtError arguments
The fields have been deprecated in C with
git:f60dc0bc09f09c6817d6706a9edb1579a3e2b2b8

They are only passed to the libvirtError constructor, but not stored for
later or used anywhere else.

sed -ri '/raise libvirtError/s/, \w+=self(\._dom)?//' *.py

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-06 08:50:37 +02:00
Philipp Hahn
0ca8dc6340 Normalize white space
indent by 4 spaces
one spaces around assignments

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-06 08:50:37 +02:00
Philipp Hahn
ca394b9f3c generator: Fix parent type
The constructors for virDomain, virStoragePool, virDomainCheckpoint,
virDomainSnapshot expect virConnect as their first argument. The current
code always uses `self`, which is okay when such an instance is created
from a method of virConnect itself, but there are several cases where
this is not the case:

    virDomain.migrate() -> virDomain
    virDomain.migrate2() -> virDomain
    virDomain.migrate3() -> virDomain
    virDomainCheckpoint.getParent() -> virDomainCheckpoint
    virDomainSnapshot.getParent() -> virDomainSnapshot
    virStorageVol.storagePoolLookupByVolume() -> virStoragePool

> libvirt.py:1850: error: Argument 1 to "virDomain" has incompatible type "virDomain"; expected "virConnect"
> libvirt.py:1871: error: Argument 1 to "virDomain" has incompatible type "virDomain"; expected "virConnect"
> libvirt.py:1888: error: Argument 1 to "virDomain" has incompatible type "virDomain"; expected "virConnect"
> libvirt.py:3422: error: Argument 1 to "virStorageVol" has incompatible type "virStoragePool"; expected "virConnect"
> libvirt.py:6835: error: Argument 1 to "virDomainCheckpoint" has incompatible type "virDomainCheckpoint"; expected "virDomain"
> libvirt.py:6943: error: Argument 1 to "virDomainSnapshot" has incompatible type "virDomainSnapshot"; expected "virDomain"

>>> import libvirt
>>> con = libvirt.open('test:///default')
>>> dom = con.lookupByName("test")
>>> first = dom.checkpointCreateXML("""<domaincheckpoint><name>First</name></domaincheckpoint>""")
>>> first.domain()
<libvirt.virDomain object at 0x7f728c3b6b80>
            ^^^^^^
>>> second = dom.checkpointCreateXML("""<domaincheckpoint><name>Second</name></domaincheckpoint>""")
>>> parent = second.getParent()
>>> parent.domain()
<libvirt.virDomainCheckpoint object at 0x7f728c424d30>
            ^^^^^^^^^^^^^^^^

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-07-27 13:48:28 +02:00
Philipp Hahn
d2de75dd83 generator: Fix string formatting
remove excessive arguments.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-07-27 13:24:36 +02:00
Philipp Hahn
c23bd95798 generator: Fix undefined variables file
generator.py:931:15: F821 undefined name 'file'
generator.py:951:15: F821 undefined name 'file'

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-07-27 13:24:36 +02:00
Radostin Stoyanov
d4b62ae615 generator: Fix typos
Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
2020-07-17 09:28:39 +01:00
Cole Robinson
cecaa15b64 generator: Fix SyntaxWarning
$ ./setup.py build
running build
/usr/bin/pkg-config --print-errors --atleast-version=0.9.11 libvirt
/usr/bin/python3 generator.py libvirt /usr/share/libvirt/api/libvirt-api.xml
generator.py:1562: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if classname is "virStorageVol":
...

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2020-07-05 17:48:50 -04:00
Michal Privoznik
d0ac75bb9c virStream: Use larger buffer for sendAll/recvAll methods
There are four methods which receive/send entire stream
(sendAll(), recvAll(), sparseSendAll() and sparseRecvAll()). All
these have an intermediary buffer which is either filled by
incoming stream and passed to a user provided callback to handle
the data, or the other way round - user fills it with data they
want to send and the buffer is handed over to virStream.

But the buffer is incredibly small which leads to smaller packets
being sent and thus increased overhead. What we can do is to use
the same buffer as their C counterparts do (e.g.
virStreamSendAll()) - they all use VIR_NET_MESSAGE_LEGACY_PAYLOAD_MAX
long buffer (which is the maximum size of a stream packet we
send) - this is almost exactly 256KiB (it's 256KiB - 24B for the
header).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2020-07-03 19:09:46 +02:00
Daniel P. Berrangé
56afc9b33f Add overrides for network port UUID getter/lookup methods
The generator creates broken code for all these methods.

Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2020-01-03 11:32:57 +00:00
Daniel P. Berrangé
b22e4f2441 Drop support for python 2
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>
2019-12-04 12:14:51 +00:00
Pavel Hrdina
fc76416248 generator.py: add mapping for VIR_DOMAIN_QEMU_AGENT_COMMAND_*
Libvirt commit <95f5ac9ae52455e9da47afc95fa31c9456ac27ae> changed the
VIR_DOMAIN_QEMU_AGENT_COMMAND_* enum values to use different enum values
instead of direct numbers.  We need to translate it back.

Traceback (most recent call last):
  File "generator.py", line 2143, in <module>
    qemuBuildWrappers(sys.argv[1])
  File "generator.py", line 2008, in qemuBuildWrappers
    items.sort(key=lambda i: (int(i[1]), i[0]))
  File "generator.py", line 2008, in <lambda>
    items.sort(key=lambda i: (int(i[1]), i[0]))
ValueError: invalid literal for int() with base 10: 'VIR_DOMAIN_AGENT_RESPONSE_TIMEOUT_BLOCK'

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2019-11-28 10:55:18 +01:00
Daniel P. Berrangé
873e0ca7db Custom impl for virConnectSetIdentity which can't be generated
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-09-20 13:51:20 +01:00
Daniel P. Berrangé
6dff8e4f3f generator: fix constructor for virNetworkPort
The virNetworkPort class is passed both the virNetwork parent
python class and the virNetworkPort C object. This needs special
handling in the generator, similar to how virDomainSnapshots are
dealt with.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-09-12 15:28:13 +01:00
Michal Privoznik
17937cc337 Implement virDomainGetGuestInfo
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2019-08-29 12:04:56 +02:00
Eric Blake
358a8640fa Add virDomainCheckpoint APIs
Copies heavily from existing virDomainSnapshot handling, regarding
what special cases the generator has to be taught and what overrides
need to be written.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2019-07-29 13:39:39 -05:00
Daniel P. Berrangé
05089cc402 generator: fix naming of getter APIs for virNetworkPort
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-06-20 14:10:08 +01:00
Daniel P. Berrangé
a4de6e2ed8 Add support for virNetworkPort object & APIs
Define the various rules in the generator to wire up methods into the
virNetwork class and create the new virNetworkPort class.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-06-20 12:11:59 +01:00
Eric Blake
5301118fd1 generator.py: typo fix
Signed-off-by: Eric Blake <eblake@redhat.com>
2019-02-07 14:52:09 -06:00
John Ferlan
9bc102103c Implement API binding for virDomainSetIOThreadParams
Similar to libvirt_virDomainBlockCopy (and migration API's). Create
the code for the new API.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2018-11-20 13:24:18 -05:00
Daniel P. Berrangé
c1f06dde29 Fix bugs in nwfilter binding APIs
We did not correctly mangle the API names in two cases, and we also
forgot to specialize the lookup method name in the sanity test.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-06-28 12:29:21 +01:00
Daniel P. Berrangé
d5aae37c61 Add support for nwfilter binding objects / apis
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-06-28 12:04:05 +01:00
Erik Skultety
6c136b8150 Add support for virNodeGetSEVInfo
This binding allows to query the AMD's SEV firmware for various platform
specific things, like a PDH certificate and a certificate chain to
establish a trusted connection with the firmware. Because the API uses
typed params, it's exempted from generation.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2018-06-14 17:23:19 +02:00
Erik Skultety
dbae262811 Add support for virDomainGetLaunchSecurityInfo
Libvirt recently introduced support for getting launch security
parameters, most notably AMD SEV VM memory measurement. This API can't
be generated as it's using typed parameters which we need to allocate.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2018-06-14 17:22:59 +02:00
Jiri Denemark
0f3f82e8be Add support for virConnectBaselineHypervisorCPU
The python bindings for this API cannot be generated because are
generator is not capable of handling string arrays (char **) parameters.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2018-06-01 08:16:48 +02:00
Marc Hartmayer
318e305512 libvirt_qemu/lxc: fix a namespace issue
Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Reviewed-by: Bjoern Walk <bwalk@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
2018-05-16 10:40:46 +02:00
Marc Hartmayer
0a07908e69 libvirt_qemu/lxc: import 'sys' package
This fixes the pylint [1] warning "E: 25,16: Undefined variable
'sys' (undefined-variable)".

[1] https://www.pylint.org/

Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Reviewed-by: Bjoern Walk <bwalk@linux.vnet.ibm.com>
2018-05-16 10:40:46 +02: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
John Ferlan
100177c3dc Introduce virDomainMigrateGetMaxDowntime API
Introduce wrapper for virDomainMigrateGetMaxDowntime
2017-08-26 08:58:41 -04:00
Michal Privoznik
d7e1c976f4 virStream: Introduce virStreamSparse{Recv,Send}All
Yet again, our parser is not capable of generating proper
wrapper. To be fair, this one wold be really tough anyway.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-05-24 13:32:37 +02:00
Michal Privoznik
2e4cb22122 virStream: Introduce virStreamRecvFlags
Yet again, we need a custom wrapper over virStreamRecvFlags
because our generator is not capable of generating it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-05-23 13:43:15 +02:00
Michal Privoznik
1f42d8629f Implement virStreamSendHole/virStreamRecvHole
The return value for virStreamRecvHole is slightly different to
its C counterpart. In python, either it returns the hole size or
None if C API fails.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-05-23 13:43:12 +02:00
Daniel P. Berrange
405f537bd0 Removed unused 'functions_list_exception_test' code from generator
The 'functions_list_exception_test' data structure and associated code
in the generator is inherited from libxml. This has never
been used in libvirt, so delete it to simplify the generator.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2017-01-27 09:58:40 +00:00
Daniel P. Berrange
60f71591b9 Removed unused 'converter_type' code from generator
The 'converter_type' data structure and associated code
in the generator is inherited from libxml. This has never
been used in libvirt, so delete it to simplify the generator.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2017-01-27 09:58:40 +00:00
Daniel P. Berrange
d5feb2f664 Removed unused 'classes_ancestor' code from generator
The 'classes_ancestor' data structure and associated code
in the generator is inherited from libxml. This has never
been used in libvirt, so delete it to simplify the generator.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2017-01-27 09:58:40 +00:00
Daniel P. Berrange
34a5fa2f61 Removed unused 'py_return_types' code from generator
The 'py_return_types' data structure and associated code
in the generator is inherited from libxml. This has never
been used in libvirt, so delete it to simplify the generator.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2017-01-27 09:58:40 +00:00
Daniel P. Berrange
bc90127cb6 Removed unused 'foreign_encoding_args' code from generator
The 'foreign_encoding_args' data structure and associated code
in the generator is inherited from libxml. This has never
been used in libvirt, so delete it to simplify the generator.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2017-01-27 09:58:40 +00:00
Daniel P. Berrange
0c53a316ea Removed unused 'function_post' code from generator
The 'function_post' data structure and associated code
in the generator is inherited from libxml. This has never
been used in libvirt, so delete it to simplify the generator.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2017-01-27 09:58:40 +00:00
Daniel P. Berrange
f916d855c7 Removed unused 'reference_keepers' code from generator
The 'reference_keepers' data structure and associated code
in the generator is inherited from libxml. This has never
been used in libvirt, so delete it to simplify the generator.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2017-01-27 09:58:40 +00:00
Daniel P. Berrange
431afe83ce Protect against user accidentally calling constructors directly
When using libvirt python you must never call the object
constructors directly, as these are expecting to be passed
a wrapped C object. For example

   import libvirt
   c = libvirt.virConnect("qemu:///system")
   c.listAllDomains()

will mysteriously segfault. With this change the user now
gets an slightly more helpful error

  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/home/berrange/src/virt/libvirt-python/build/libvirt.py", line 3409, in __init__
      raise Exception("Expected a wrapped C Object but got %s" % type(_obj))
  Exception: Expected a wrapped C Object but got <type 'str'>

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2017-01-27 09:58:40 +00:00
Daniel P. Berrange
69797c4726 Add support for secret event APIs
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2017-01-09 18:07:40 +00:00
Daniel P. Berrange
ff560532fd Add override impl for virStorageVolGetInfoFlags
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-12-21 13:17:28 +00:00
Daniel P. Berrange
f5edaf1ba5 Remove bogus \o escape in regex
One of the regexes has a bogus \o instead of plain 'o'. Somehow
this magically worked on all versions of python, until 3.6 came
along and complained

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-12-21 10:35:17 +00:00
Jovanka Gulicoska
58a986984f Python binding for node poll lifecycle events API 2016-08-02 09:55:56 -04:00
Michal Privoznik
570669f29f Add support for virDomainGetGuestVcpus
This function has virTypedParameterPtr as one of the args and our
generator is unable to deal with that. Therefore we must provide
implementation.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-06-23 10:57:11 +02:00
Jovanka Gulicoska
7eaab4a6c2 Python binding for storage pool lifecycle events API
Code matches the network event API implementation
2016-06-16 12:25:44 -04:00