1
0
mirror of https://gitlab.com/libvirt/libvirt-python.git synced 2025-11-22 00:23:47 +03:00

349 Commits

Author SHA1 Message Date
Lukas Billy
cbcafe129b generator.py: Fix hardcoded build directory
This patch changes the hard-coded directory, so it is now possible to have custom name directory.
Signed-off-by: Lukas Billy lbilly@redhat.com
2025-05-21 13:53:34 +02:00
Michal Privoznik
3b526999de override: domain: Implement override for virDomainSetThrottleGroup()
The bindings generator can't generate proper bindings for
virDomainSetThrottleGroup() (because of typed parameters in the
arguments) so implement it manually.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2025-03-21 16:42:48 +01:00
Michal Privoznik
8b350461f7 override: domain: Implement override for virDomainGetAutostartOnce()
The bindings generator can't generate proper bindings for
virDomainGetAutostartOnce() (because of int* in the arguments) so
implement it manually.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2025-03-21 16:42:48 +01:00
Michal Privoznik
a6b8929083 generator.py: Drop build/ prefix from #include
When -Ibuild flag is passed to compiler then build/ can be dropped
from includes. This is safe to do, because the prefix is only on
local includes (#include "") not system ones (#include <>).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2024-05-02 12:50:16 +00:00
Michal Privoznik
dcd4218837 generator.py: Switch from ${module}-export.c to ${module}-export.c.inc
The generator.py generates a (per module) table of functions it
generated code for and stores it in ${module}-export.c file. The
file is then #include-d in corresponding override.c in the table
of all methods implemented in the module.

Now, problem is with naming of the file because the ".c" suffix
might suggest the file needs to be compiled. Well, it doesn't.
It's way closer to being a header file, so change the suffix to
".c.inc".

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2024-05-02 12:50:16 +00:00
Michal Privoznik
865df8b846 generator.py: Allow source and build dirs override
Soon generator.py is going to be ran from a build directory which
is different than the source directory. Allow specifying these
directories on the cmd line.

And while at it, introduce new "c+py" output mode in which both C
and Python files are generated. While this is a fallback mode if
no output mode is selected, we need this new mode so that
aforementioned directories can be specified.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2024-05-02 12:50:16 +00:00
Daniel P. Berrangé
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
Peter Krempa
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
Michal Privoznik
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
Daniel P. Berrangé
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
Daniel P. Berrangé
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
Daniel P. Berrangé
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
Daniel P. Berrangé
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
Daniel P. Berrangé
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
Daniel P. Berrangé
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
Daniel P. Berrangé
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
Daniel P. Berrangé
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
Daniel P. Berrangé
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
Daniel P. Berrangé
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
Daniel P. Berrangé
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
Daniel P. Berrangé
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
Daniel P. Berrangé
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
Michal Privoznik
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
Daniel P. Berrangé
322fc085cb Add an override impl for virDomainSetLaunchSecurityState
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2022-01-05 18:17:02 +00:00
Jonathon Jongsma
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
Michal Privoznik
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
Michal Privoznik
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
Daniel P. Berrangé
75c053e49e Add impl override for virDomainGetMessages
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2021-02-15 16:02:21 +00:00
Michal Privoznik
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
Daniel P. Berrangé
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
Philipp Hahn
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
Philipp Hahn
d30d872251 generator: Add PEP 484 type annotations
Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
Philipp Hahn
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
Philipp Hahn
7f021c21d6 generator: Merge code for __init__ genration
Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
Philipp Hahn
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
Philipp Hahn
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
Philipp Hahn
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
Philipp Hahn
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
Philipp Hahn
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
Philipp Hahn
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
Philipp Hahn
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
Philipp Hahn
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
Philipp Hahn
c95a957084 generator: Simplify loop break
Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
Philipp Hahn
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
Philipp Hahn
3b9ef6ecad generator: Fixed writing cached=None
Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00
Philipp Hahn
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
Philipp Hahn
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
Philipp Hahn
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
Philipp Hahn
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
Philipp Hahn
425901da21 generator: Convert in_function to bool
Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-09-01 13:26:01 +00:00