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

949 Commits

Author SHA1 Message Date
Philipp Hahn
429973c836 libvirtaio: Cleanup imports
Move imports to top

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-06 08:50:37 +02:00
Philipp Hahn
bd238713ef sanitytest: no type change
static typing forbids re-declaring a variable with different types.
Rename the variable.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-06 08:50:37 +02:00
Philipp Hahn
22f2ba37ae sanitytest: Use str.startswith() instead of str[0]
Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-06 08:50:37 +02:00
Philipp Hahn
b6ad44257e sanitytest: Use set for tracking used functions
Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-06 08:50:37 +02:00
Philipp Hahn
ddf73e40a9 sanitytest: Use 3-tuple for finalklassmap
Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-06 08:50:37 +02:00
Philipp Hahn
809b963134 sanitytest: Use 3-tuple for basicklassmap
Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-06 08:50:37 +02:00
Philipp Hahn
94c24929e4 sanitytest: Add PEP 484 type annotations
Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-06 08:50:37 +02:00
Philipp Hahn
fd8b7733dc sanitytest: Drop Python 2 compatibility
Python 3 only has int, remove the Python 2 long type

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-06 08:50:37 +02:00
Philipp Hahn
ff9575a727 sanitytest: Drop else:pass
useless

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-06 08:50:37 +02:00
Philipp Hahn
6279dbefc2 sanitytest: Do not re-declare set
is a built-in python type

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-06 08:50:37 +02:00
Philipp Hahn
39ffa7f838 sanitytest: Convert type() to isinstance()
Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-06 08:50:37 +02:00
Philipp Hahn
8a81fc6f2b sanitytest: Skip type annotations
Teach sanitytest to ignore typing imports

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-06 08:50:37 +02:00
Philipp Hahn
b5f7beb931 sanitytest: Remove unused import
Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-06 08:50:37 +02: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
7c93891420 examples/event-test: Fix remove return type
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>
2020-08-06 08:50:37 +02:00
Philipp Hahn
74a78fa42c examples: Fix white space
indent by 4 spaces
one spaces around assignments

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-05 07:43:02 +00:00
Philipp Hahn
b801ff31fa examples: Replace sys.exit() with exit()
No need to import sys.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-05 07:43:02 +00:00
Philipp Hahn
f496dc55ee examples: Cleanup imports
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>
2020-08-05 07:43:02 +00:00
Philipp Hahn
4e22f4de6f examples: Do not use bare except
as it also catches SystemExit, InterruptedError, SyntaxError and such.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-05 07:43:02 +00:00
Philipp Hahn
06aba185a8 examples: Convert to ArgumentParser
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>
2020-08-05 07:43:02 +00:00
Philipp Hahn
9cf539a2a8 examples: Add/fix PEP 484 type annotation
Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-05 07:43:02 +00:00
Philipp Hahn
5434ed53ff examples: Add missing return values
examples/dhcpleases.py:45: error: Missing return statement

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-05 07:43:02 +00:00
Philipp Hahn
c588ba982e examples/nodestat: Fix None comparison
"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>
2020-08-05 07:43:02 +00:00
Philipp Hahn
900676d3c4 examples/consolecallback: Fix assorted errors
Assert stream is opened before receiving bytes.

Need to check for bytes() instead of [unicode]str().

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-05 07:43:01 +00:00
Philipp Hahn
55415a4870 examples/consolecallback: Add var to save callback
> examples/consolecallback.py:98: error: "Console" has no attribute "stdin_watch"

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-05 07:43:01 +00:00
Philipp Hahn
77f57cd5ec examples/esxlist: Fix Python 2 raw_input()
which was renamed to input() for Python 3.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-05 07:43:01 +00:00
Philipp Hahn
cb8cceb0d8 examples/event-test: Use atexit for Python 3
Assigning sys.exitfunc no longer works with Python 3.

Use atexit.register() instead.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-05 07:43:01 +00:00
Philipp Hahn
59c2df2fa4 examples/event-test: Remove unneeded global statement
It only needed when a value is assigned.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-05 07:43:01 +00:00
Philipp Hahn
a19f086831 examples/dhcp*: Fix None comparison
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>
2020-08-05 07:43:01 +00:00
Philipp Hahn
6aa02b3292 examples/*: Remove stray semicolon
This is Python, not C

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-05 07:43:01 +00:00
Daniel P. Berrangé
dc1dc11efe ci: refresh dockerfiles for changed libvirt build system
Libvirt changed from autotools to meson. All the containers need
refreshing and the CI recipes updated.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2020-08-04 12:23:26 +01:00
Jiri Denemark
2966ed6085 Post-release version bump to 6.7.0
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2020-08-03 00:23:16 +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>
v6.6.0
2020-07-27 13:48:28 +02:00
Philipp Hahn
a14161f01c debug: Fix bit-rot in debug output
Let the compiler optimize out the printf() call instead of doing it with the
pre-processor as the later does not catch format string errors or the following
case, where NULLSTR() is used but not defined:

> libvirt-qemu-override.c: In function ‘libvirt_qemu_virConnectDomainQemuMonitorEventRegister’:
> libvirt-qemu-override.c:271:34: warning: implicit declaration of function ‘NULLSTR’; did you mean ‘NULL’? [-Wimplicit-function-declaration]
>   271 |           pyobj_conn, pyobj_dom, NULLSTR(event), pyobj_cbData, flags);
>       |                                  ^~~~~~~
> libvirt-qemu-override.c:39:28: note: in definition of macro ‘DEBUG’
>    39 |     while (0) {printf(fmt, __VA_ARGS__);}
>       |                            ^~~~~~~~~~~
> libvirt-qemu-override.c:270:11: warning: format ‘%s’ expects argument of type ‘char *’, but argument 4 has type ‘int’ [-Wformat=]
>   270 |     DEBUG("libvirt_qemu_virConnectDomainQemuMonitorEventRegister(%p %p %s %p %x) called\n",
>       |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>   271 |           pyobj_conn, pyobj_dom, NULLSTR(event), pyobj_cbData, flags);
>       |                                  ~~~~~~~~~~~~~~
>       |                                  |
>       |                                  int
> libvirt-qemu-override.c:39:23: note: in definition of macro ‘DEBUG’
>    39 |     while (0) {printf(fmt, __VA_ARGS__);}
>       |                       ^~~
> libvirt-qemu-override.c:270:73: note: format string is defined here
>   270 |     DEBUG("libvirt_qemu_virConnectDomainQemuMonitorEventRegister(%p %p %s %p %x) called\n",
>       |                                                                        ~^
>       |                                                                         |
>       |                                                                         char *
>       |                                                                        %d

Copy the definition of NULLSTR from libvirt/src/internal.h to typewrappers.h

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-07-27 13:24:36 +02:00
Philipp Hahn
cfcf988a98 libvirtaio: Fix return types of callback
libvirt defines the signature for the callback functions, e.g. the
functions for remove() must return -1 on error and 0 on success. Raising
an exception violates that contract.

_remove_timeout() did not explicitly handle a double-remove and
implicitly passed on the exception.

update() expects no return value, so remove the pointless return to pass
on None.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-07-27 13:24:36 +02:00
Philipp Hahn
b595e59b48 qemu-api: Fix return type
The API XML description uses "C types": "str *" is not valid.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-07-27 13:24:36 +02:00
Philipp Hahn
932055e3cb generator: Fix domainCheckpoint.listAllChildren()
virDomainCheckpoint(dom, _obj)
expects a reference to the virDomain as its first argument, but
    virDomainCheckpoint.listAllChildren()
passes `self` instead:

libvirt.py:7056: error: Argument 1 to "virDomainCheckpoint" has incompatible type "virDomainCheckpoint"; expected "virDomain"

>>> import libvirt
>>> con = libvirt.open('test:///default')
>>> dom = con.lookupByName("test")
>>> first = dom.checkpointCreateXML("""<domaincheckpoint><name>First</name></domaincheckpoint>""")
>>> second = dom.checkpointCreateXML("""<domaincheckpoint><name>Second</name></domaincheckpoint>""")
>>> child, = first.listAllChildren()
>>> second.domain()
<libvirt.virDomain object at 0x7f828d777b80>
         ^^^^^^^^^
>>> child.domain()
<libvirt.virDomainCheckpoint object at 0x7f828d8160a0>
         ^^^^^^^^^^^^^^^^^^^

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-07-27 13:24:36 +02:00
Philipp Hahn
a65d230ded generator: Fix domainSnapshot.listAllChildren()
virDomainSnapshot(dom, _obj)
expects a reference to the virDomain as its first argument, but
    virDomainSnapshot.listAllChildren()
passes `self` instead:

libvirt.py:6459: error: Argument 1 to "virDomainSnapshot" has incompatible type "virDomainSnapshot"; expected "virDomain"

>>> import libvirt
>>> con = libvirt.open('test:///default')
>>> dom = con.lookupByName("test")
>>> first = dom.snapshotCreateXML("""<domainsnapshot><name>First</name></domainsnapshot>""")
>>> second = dom.snapshotCreateXML("""<domainsnapshot><name>Second</name></domainsnapshot>""")
>>> child, = first.listAllChildren()
>>> second.domain()
<libvirt.virDomain object at 0x7fb32be3cfd0>
         ^^^^^^^^^
>>> child.domain()
<libvirt.virDomainSnapshot object at 0x7fb32bdb9080>
         ^^^^^^^^^^^^^^^^^

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-07-27 13:24:36 +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
Jiri Denemark
bf049af8f9 Post-release version bump to 6.6.0
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2020-07-23 00:43:16 +02:00
Radostin Stoyanov
d4b62ae615 generator: Fix typos
Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
2020-07-17 09:28:39 +01:00
Radostin Stoyanov
ed545f9fff examples: Refactor domipaddrs
This patch makes domipaddrs example compatible with Python3.

Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
2020-07-15 11:05:35 +01:00
Cole Robinson
c1b9384759 Fix PY_SSIZE_T_CLEAN deprecation warning
Seen running on fedora 32:

DeprecationWarning: PY_SSIZE_T_CLEAN will be required for '#' formats
  ret = libvirtmod.virDomainLookupByUUID(self._o, uuid)

This comes from here: https://bugs.python.org/issue36381
See the section about PY_SSIZE_T_CLEAN here:
https://docs.python.org/3/c-api/arg.html#strings-and-buffers

Solution is to use Py_ssize_t instead of int for unpacked '#' values,
combined with defined PY_SSIZE_T_CLEAN before importing Python.h. The
latter turns these deprecation warnings into runtime segfaults though
if we missed an instance.

I verified the virt-manager's test suite works fine after this change

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2020-07-06 11:01:01 +00: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
Michal Privoznik
11bb65bff3 MANIFEST: Distribute sparsestream.py example
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2020-07-03 19:09:45 +02:00
Daniel P. Berrangé
2ccc481c31 setup: post-release version bump to 6.5.0
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
v6.5.0
2020-06-08 16:43:39 +01:00
Andrea Bolognani
8c5879b44d ci: Test installation
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
v6.4.0
2020-05-22 18:35:19 +02:00