1
0
mirror of https://gitlab.com/libvirt/libvirt-python.git synced 2025-08-05 16:21:59 +03:00

343 Commits

Author SHA1 Message Date
85e58cb2ee add missing includes for C library functions
We use various C library functions like printf, strcmp, free
but don't have the corresponding #includes, getting them
indirectly via Python.h. This is a bad idea as Python.h is
not guaranteed to provided these, and indeed will omit them
when Py_LIMITED_API is greater then 0x030a0000.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2023-09-25 11:17:31 +00:00
c59d3232b7 override: domain: Implement override for virDomainFDAssociate
The bindings generator can't generate proper bindings for FD passing so
the bindings need to be implemented manually both the python wrapper and
the C backend.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2023-01-12 13:52:25 +01:00
c40c5f0cfc Add an override impl for virDomainRestoreParams and virDomainSaveParams
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2022-05-13 13:28:11 +02:00
f8c9ec5387 generator: introduce ability to selectively generate code
Currently we always generate both the C code and Python code at the same
time. To cope with following changes to the build process, we want to be
able to generate C and Python separately.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2022-04-21 12:34:06 +01:00
47b434b142 generator: rename methods for code generation
The names make it clearer exactly what is being generated by each.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2022-04-21 12:34:06 +01:00
83595da93f generator: split function skip logic out of C generator
The python generator needs to know whether certain functions were
skipped in the C generator. This is achieved by the C generator
deleting skipped functions as it runs. This is an unhelpful side
effect as it makes it impossible to run the python generator
without first running the C generator.

This refactors buildStubs to get rid of the global side effects
it has, by providing some helper functions for buildWrappers
to use.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2022-04-21 12:34:01 +01:00
8ec1b5aa16 generator: split function type validation out of C generator
As a side effect of generating the C code, the buildStubs methods
checks for various unsupported types and reports errors. This is
an undesirable side effect, if we want to skip C code generation.

Splitting function type validation out into a separate method
allows better reuse.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2022-04-21 12:32:51 +01:00
2fb2e54136 generator: split loading of APIs out from writing stubs
The buildStubs method has a side effect of loading and parsing the API
XML files, which the buildWrappers method then relies on.

Splitting API loading into a separate method will facilitate running
only the buildWrappers method in future.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2022-04-21 12:32:51 +01:00
3950e1ddd5 generator: merge python wrapper generator methods
Instead of having three separate methods for generating python
wrappers, merge them all together.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2022-04-21 12:32:51 +01:00
c8abe55d4c generator: refactor buildWrappers to make it more generic
Prepare for using buildWrappers to generate code for the QEMU / LXC
APIs too.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2022-04-21 12:32:51 +01:00
f1e5b5c18f generator: simplify some repeated code patterns
Now that we're using common data structures for all the main libvirt,
QEMU and LXC APIs, several of the functions have code duplication
that can be eliminated.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2022-04-21 12:32:51 +01:00
01303d79fa generator: use single function for registering all enums
Now that we only use a single dict for tracking all enums, we
only need a single function for registering them.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2022-04-21 12:32:51 +01:00
ff65b9c67c generator: use single dict for tracking all enums
A single invokation of the generator only handles processing of one
libvirt API module, so there is no need to use separate dicts for
tracking enums.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2022-04-21 12:32:51 +01:00
054c9e9b73 generator: use single function for registering all functions
Now that we only use a single dict for tracking all functions, we
only need a single function for registering them.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2022-04-21 12:32:51 +01:00
6b2cef6182 generator: use single dict for tracking all skipped functions
A single invokation of the generator only handles processing of one
libvirt API module, so there is no need to use separate dicts for
tracking skipped functions.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2022-04-21 12:32:51 +01:00
f4c43ef581 generator: use single dict for tracking all functions
A single invokation of the generator only handles processing of one
libvirt API module, so there is no need to use separate dicts for
tracking functions.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2022-04-21 12:32:51 +01:00
050ed3e629 Implement virDomainQemuMonitorCommandWithFiles() override
With libvirt-8.2.0 there's a new API:
virDomainQemuMonitorCommandWithFiles(). Since the API has both
input and output arguments we need to provide an alternative
implementation. Moreover, since FD passing works only on
UNIX-like systems we can query the returned FDs for their flags
and construct mode for python File object.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2022-03-10 09:51:33 +01:00
322fc085cb Add an override impl for virDomainSetLaunchSecurityState
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2022-01-05 18:17:02 +00:00
066af64107 Add new autostart API for node devices
Provide a manual override for the virNodeDeviceGetAutostart() API
modeled on what's done for the network and storage APIs.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
2021-09-21 16:11:07 -05:00
f234192eb0 generator.py: Untangle virNodeDevice name fixup
The way that virNodeDevice method name fixup is written makes it
hard to find via grep (matching the virNodeDevice prefix and then
matching only the operation like "Get", "Lookup", ...). Expand
the string matching to match the pattern of other cases.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2021-04-15 13:12:53 +02:00
6851c5c8df generator.py: Fix method names for new virNodeDevice*() APIs
In the 7.3.0 release we are going to have three new public APIs:

  virNodeDeviceDefineXML()
  virNodeDeviceUndefine()
  virNodeDeviceCreate()

The first one is slightly problematic, because it takes
virConnectPtr argument and thus our generator wants to put its
wrapper under virConnect python class, which is correct, but
what's incorrect is the name it chooses for the method:
defineXML(). Such method already exists and wraps
virDomainDefineXML() around. Also, the name is rather confusing
anyway - it's missing the 'nodeDevice' prefix.

Fortunately, the fix is easy - add another case into nameFixup().

The story with virNodeDeviceCreate() is similar. Except, this time
the class in which the method was put is correct. But the name is
still wrong, because our generator matched 'virNodeDeviceCreate'
thinking it's the good old virNodeDeviceCreateXML() API and
"fixed" the name of the method to nodeDeviceCreate().

Luckily, virNodeDeviceUndefine() is just fine.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2021-04-15 13:12:29 +02:00
75c053e49e Add impl override for virDomainGetMessages
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2021-02-15 16:02:21 +00:00
767bf23ba6 Implement virDomainAuthorizedSSHKeys{Get,Set}
Both APIs work with string lists (the getter returns it, the
setter gets keys to set from it) -> represent that as a python
list. The rest is kept as is in C.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2020-11-19 18:12:33 +01:00
613411502d fix constructor param name for virDomainSnapshot / virDomainCheckpoint
Fixes 7f021c21d6
Resolves https://gitlab.com/libvirt/libvirt-python/-/issues/4

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2020-10-06 11:15:48 +01:00
22bfd4bcab generator: Work around type change
a variable should not change its type.

Signed-off-by: Philipp Hahn <hahn@univention.de>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-09-01 13:26:01 +00:00
d30d872251 generator: Add PEP 484 type annotations
Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
62d99b6dad generator: Merge common code of print_function_wrapper
Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
7f021c21d6 generator: Merge code for __init__ genration
Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
5a2c12278a generator: Expand tuple to names in for loop
Assign tuple to multiple loop variables for better readability

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
f87eba2fee generator: break lines in generated code
to be closes to pep8 which makes reading the generated code easier and
reduces the number of issues found by flake8.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
f7bd89c0bd generator: Use empty string instead of None
for better type checking: both are bool()==False, but None is not str.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
4df8e83808 generator: Convert to defaultdict()
for nested dictionaries allows to remove the case distinction for
"first" from "all other" cases.

Signed-off-by: Philipp Hahn <hahn@univention.de>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-09-01 13:26:01 +00:00
87e0ca6390 generator: Move funcs_failed into buildStubs()
The variables are local to that funcion

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
099459096a generator: Convert list() to set()
tuple() and list() are sequences, while dict() and set() are hash-based,
which is more efficient for contains().

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
fe100b90ef generator: Convert dict() to set()
Python has a native type for set()s.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
3bb106d5e5 generator: Simplify boolean condition
no need to compare with None or empty string.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
c95a957084 generator: Simplify loop break
Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
9f6638d3b2 generator: Simplify sorting
Use sorted(..., key=...) instead of using explicit list.sort()

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
3b9ef6ecad generator: Fixed writing cached=None
Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
88e668c64c generator: Store arguments and return as tuple
instead of list.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
3f493a3a6b generator: Expand tuple to names in for loop
Assign tuple to multiple loop variables for better readability

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
fad7bce226 generator: Initialize with empty strings
instead of using None as this has a different type.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
5d12443e50 generator: Simplify XML attribute fetching
Use attr.get(key, default) instead.

Also use the empty sting "" as the default value instead of "None": Both
are "False" when used as a bool()ean, but "None" would require an
explicit check for "not None" in many places as str() and None have
different types.

Signed-off-by: Philipp Hahn <hahn@univention.de>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-09-01 13:26:01 +00:00
425901da21 generator: Convert in_function to bool
Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
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
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
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
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
4d06f2b2fb generator: Open file with context manager
Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
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