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

349 Commits

Author SHA1 Message Date
Philipp Hahn
d560971513 generator: Use string formatting
instead of sting concatenating.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
Philipp Hahn
9be847c7ce generator: Use SAX method names
directly instead of using legacy method names from xmllib.

Depends: 3740a5e4c7
Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
Philipp Hahn
90e861ab4a generator: Remove unused SAX content handler methods
getmethodname()
close()
cdata()

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
Philipp Hahn
06de635ed2 generator: Refactor parser creation
to use closing context manager.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
Philipp Hahn
4d06f2b2fb generator: Open file with context manager
Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
Philipp Hahn
8f354ae738 generator: Use splitlines()
instead of hand-coded implementation.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
Philipp Hahn
f36643acac generator: Just walk the dict
instead of generating a list first.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
Philipp Hahn
ada1554532 generator: Directly get dict length
instead of generating a list and then counting the elements.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
Philipp Hahn
280b1d6640 generator: Walk only the values
instead of the keys and then doing a lookup.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
Philipp Hahn
89c453db00 generator: Use dict.item() to walk keys and values
which saves a lookup of each key.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
Philipp Hahn
659d0b4dfd generator: Check contained in hash
directly instead of explicitly requesting only the keys as a list and
converting that list to another list.
Checking directly for an element to be contained in a hash is much more
efficient as this is done using hashing O(1) instead of walking the list
in half on average O(n).

Signed-off-by: Philipp Hahn <hahn@univention.de>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-09-01 13:26:01 +00:00
Philipp Hahn
a0798b9bbc generator: Initialize function_classes directly
Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
Philipp Hahn
94b30b7fb7 generator: Remove global declarations
for variables with are not assigned.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
Philipp Hahn
f4aefad212 generator: Use string concatenation
:%s,\(\w\+\)\s*=\s*\1\s*+,\1 +=,

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
Philipp Hahn
9e325358de generator: Use increment assignment
:%s,\(\w\+\)\s*=\s*\1\s*+,\1 +=,

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
Philipp Hahn
03b558b32e generator: Use enumerate()
instead of manual iteration counting.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
Philipp Hahn
4b798e3405 generator: Simplify string concatentaion
by using ''.join() instead of concatenating string fragments in a loop,
which is slower as it required re-hashing the string multiple times.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
Philipp Hahn
879dae7483 generator: Use more string formatting
Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
Philipp Hahn
928f5a22e6 generator: Merge now identical if-elif-else cases
Commit ca394b9f "generator: Fix parent type" fixed the case for creating
`virStorage*` instances, which require a reference to `virConnect`, so
the special handling for `._conn` is no longer needed.

Commit ee5c856a "Remove legacy libvirtError arguments" removed the
different arguments, so all cases are the same now.

Signed-off-by: Philipp Hahn <hahn@univention.de>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-09-01 13:26:01 +00:00
Philipp Hahn
2679b06d9c generator: Fix return type on failure
to return a negative value instead of None for consistency.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
Philipp Hahn
241e89b713 generator: Remove useless sort key
tuples are sorted by first component anyway.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
Philipp Hahn
0132c6d2a9 generator: Remove skipped_modules
Unused.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
Philipp Hahn
3b85ec54c9 generator: Remove dead variable assignments
Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
Philipp Hahn
8b8b394555 generator: Use raw-string for regular expression
"\(" is not a valid escape sequence for a Python string, but currently
is passed on unmodified. This might breaks in the future when new escape
sequences are introduced.

> generator.py:1001:7: W605 invalid escape sequence '\('
> generator.py:1001:18: W605 invalid escape sequence '\)'

Use raw python string instead.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
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