1
0
mirror of https://gitlab.com/libvirt/libvirt-python.git synced 2025-07-17 00:59:36 +03:00
Commit Graph

176 Commits

Author SHA1 Message Date
69c4600d61 setPyVirTypedParameter: free whole return variable on error
The @ret value is built in a loop. However, if in one iteration
there's an error, we should free all the fields built so far. For
instance, if there's an error and the previous item was
type of VIR_TYPED_PARAM_STRING we definitely must free it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2014-03-18 14:43:10 +01:00
412c93a7b9 setPyVirTypedParameter: Copy full field name
In the setPyVirTypedParameter we try to produce virTypedParameter
array from a python dictionary. However, when copying field name into
item in returned array, we use strncpy() as the field name is fixed
length array. To determine its size we use sizeof() but mistakenly
dereference it resulting in sizeof(char) which equals to 1 byte.
Moreover, there's no need for using sizeof() when we have a global
macro to tell us the length of the field name:
VIR_TYPED_PARAM_FIELD_LENGTH.

And since array is allocated using VIR_ALLOC() we are sure the memory
is initially filled with zeros. Hence, there's no need to terminate
string we've just copied into field name with '\0' character. It's
there for sure too as we copy up to field length - 1.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2014-03-18 14:43:00 +01:00
faaf2a4835 Fix return type in override method for virStreamRecv
The virStreamRecv override returns a PyObject not an int

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-12-11 16:27:27 +00:00
d40861012c override: Switch virStreamSend wrapper to use libvirt_charPtrSizeUnwrap
Instead of using a 'z#i' format string to receive byte array,
use 'O' and then libvirt_charPtrSizeUnwrap. This lets us hide
the Python 3 vs 2 differences in typewrappers.c

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-12-11 16:14:46 +00:00
e6551e60ce override: Conditionalize use of PyString_Check and PyInt_Check
The PyString and PyInt classes are gone in Python 3, so we must
conditionalize their use to be Python 2 only.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-12-11 16:14:46 +00:00
d021f89dfc override: Replace PyInt_AsLong with helper
Replace use of the PyInt_AsLong libvirt_intUnwrap helper.
This isolates the need for Python3 specific code in one
place

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-12-11 16:12:54 +00:00
a933b7f5d1 override: Replace Py{Int,Long}_FromLong with helpers
Replace use of the PyInt_FromLong and PyLong_FromLongLong
with libvirt_{int,uint,longlong,ulonglong}Wrap helpers.
This isolates the need for Python3 specific code in one
place.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-12-11 16:12:54 +00:00
aac76e7630 override: Replace PyString_AsString with libvirt_charPtrUnwrap
Replace calls to PyString_AsString with the helper method
libvirt_charPtrUnwrap. This isolates the code that will
change in Python3.

In making this change, all callers now have responsibility
for free'ing the string.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-12-11 16:12:54 +00:00
e5161dec9e override: Replace PyString_FromString with libvirt_constcharPtrWrap
Make use of libvirt_constcharPtrWrap in all override code,
to match generated code. This will isolate Python3 specific
changes in one place.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-12-11 16:12:54 +00:00
1b4dc72140 override: Fix native module registration to work with Python3
The way native modules are registered has completely
changed, so the code must be #ifdef'd for Python2 & 3

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-12-11 16:12:54 +00:00
bb3301ba78 Don't free passed in args in libvirt_charPtrWrap / libvirt_charPtrSizeWrap
Functions should not make assumptions about the memory management
callers use for parameters

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-12-11 16:12:14 +00:00
6ea5be0dd2 Added python binding for the new network events API
The new network events code requires manual binding code to
be written.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-12-11 15:39:09 +00:00
7e68c27960 Revert "Optimize callback lookup in event handlers"
This reverts commit 084729e269.

The PyImport_ImportModuleNoBlock method does not exist in
python 2.4

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-12-04 18:05:21 +00:00
084729e269 Optimize callback lookup in event handlers
The event handler code currently invokes PyImport_ImportModule
which is very heavyweight. This is not in fact required, since
we know the libvirt module has already been imported. We can
thus use PyImport_ImportModuleNoBlock and do away with the
global variables caching the imported module reference.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-12-04 17:07:13 +00:00
7f842365b1 Fix use of virDomainEventRegister in python bindings
If an app used the virDomainEventRegister binding instead
of the virDomainEventRegisterAny binding, it would never
have its callback invoked. This is because the code for
dispatching from the C libvirt_virConnectDomainEventCallback
method was totally fubar.

If DEBUG macro was set in the python build the error would
become visible

  "libvirt_virConnectDomainEventCallback dom_class is not a class!"

The code in libvirt_virConnectDomainEventCallback was
inexplicably complex and has apparently never worked. The
fix is to write it the same way as the other callback handlers.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-12-04 14:52:48 +00:00
197153c67e Add missing binding of security model/label APIs
The virNodeGetSecurityModel, virDomainGetSecurityLabel and
virDomainGetSecurityLabelList methods were disabled in the
python binding for inexplicable reasons.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-11-27 11:11:23 +00:00
d05f105992 Make block pull event dispatcher private
The method dispatchDomainEventBlockPullCallback which is
used internally to dispatch block pull events to the python
application code was missing the leading '_', to denote that
it was private.  All other event callback helpers have a
leading '_'. No application should have been using this so
it is justifiable to rename it.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-11-27 11:07:24 +00:00
8dd64f07ea Return right error code for baselineCPU
This Python interface code is returning a -1 on errors for the
`baselineCPU' API.  Since this API is supposed to return a pointer
the error return value should really be VIR_PY_NONE.

Signed-off-by: Don Dugger <donald.d.dugger@intel.com>
2013-11-26 16:54:01 +00:00
b8de31ae0c virConnectGetCPUModelNames API appeared in 1.1.3 2013-11-22 15:59:25 +00:00
298233168c VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED appeared in 1.1.1 2013-11-22 15:58:07 +00:00
33b2b09b7f virDomainCreateXMLWithFiles and virDomainCreateWithFiles APIs appeared in 1.1.1
virDomainCreateXMLWithFiles() and virDomainCreateWithFiles() were not
added to libvirt until 1.1.1
2013-11-22 15:58:07 +00:00
f721af9e54 virDomainMigrate3 and virDomainMigrateToURI3 appeared in 1.1.0
The functions virDomainMigrate3 and virDomainMigrateToURI3 were not
added to libvirt until v1.1.0.
2013-11-22 15:58:07 +00:00
24c5e9b994 virTypedParams* API appeared in 1.0.2 and used in 1.1.0
When building against versions of libvirt prior to 1.0.2, we can not
provide wrappers for virTypedParams* APIs. In addition we don't need
to have the helper APIs until 1.1.0 when the first API we wrap starts
to use them.
2013-11-22 15:58:07 +00:00
121d123af4 virDomainMigrateGetCompressionCache API appeared in 1.0.3 2013-11-22 15:58:07 +00:00
e5da225dd0 virDomainGetJobStats API appeared in 1.0.3 2013-11-22 15:58:07 +00:00
810126620a virNodeGetCPUMap API appeared in 1.0.0 2013-11-22 15:58:07 +00:00
7cc872b35b VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK appeared in 1.0.0 2013-11-22 15:58:07 +00:00
38b2d9304f virStoragePoolListAllVolumes API appeared in 0.10.2 2013-11-22 15:58:07 +00:00
f55e27f210 virNode{Get,Set}MemoryParameters API appeared in 0.10.2 2013-11-22 15:58:07 +00:00
f13a882e00 virConnectListAll* APIs appeared in 0.10.2 2013-11-22 15:58:07 +00:00
6a050c8f43 virDomainPinEmulator and virDomainGetEmulatorPinInfo APIs appeared in 0.10.0 2013-11-22 15:58:06 +00:00
bebe13660f VIR_DOMAIN_EVENT_ID_BALLOON_CHANGED appeared in 0.10.0 2013-11-22 15:58:06 +00:00
cfe670927e virConnect{Unr,R}egisterCloseCallback API appeared in 0.10.0 2013-11-22 15:58:06 +00:00
23e65b47e1 virDomainSnapshotListAllChildren API appeared in 0.9.13 2013-11-22 15:58:06 +00:00
0ee14795fd virConnectListAllDomains API appeared in 0.9.13 2013-11-22 15:58:06 +00:00
31d815b24b virDomainListAllSnapshots API appeared in 0.9.13 2013-11-22 15:58:06 +00:00
218dbee6c6 Remove use of virStrcpyStatic
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-11-22 15:58:06 +00:00
4f1ea70fd1 Import VIR_ALLOC / VIR_ALLOC_N / VIR_REALLOC_N functions
Import the libvirt memory allocation functions, stripping the OOM
testing and error reporting pieces.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-11-22 15:58:06 +00:00
c856b7c623 Import gnulib's xalloc_oversized macro
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-11-22 15:58:05 +00:00
e169d3d8cf Import STREQ macro from libvirt
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-11-22 15:58:05 +00:00
3bfb20266b Update header file includes
We're no longer using automake, so <config.h> files are not
required. Also remove of all libvirt internal util header
files. Reference generated header files in build/ subdir.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-11-22 15:58:05 +00:00
70b8c9a2a3 Mostly revert "python: remove virConnectGetCPUModelNames from globals"
This reverts commit 6b90d7428d72e92db292a9228c44701bfd5003c9.

The original problem was that libvirt_virConnectGetCPUModelNames
was listed twice in the exports table, once automatically from
the generator and once from the manual override. We merely needed
to list it in the skip_impl list, and not delete the manually
written code entirely.
2013-11-22 15:54:43 +00:00
45ac117cf6 python: remove virConnectGetCPUModelNames from globals
Commit de51dc9c9aed0e615c8b301cccb89f4859324eb0 primarily added
virConnectGetCPUModelNames as libvirt.getCPUModelNames(conn, arch)
instead of libvirt.virConnect.getCPUModelNames(arch) so revert the code
that does the former while leaving the code that does the later.

This is the rest of the patch that was ACK'd by Dan but I committed only
the partial patch in 6a8b8ae.
2013-11-21 14:20:45 -06:00
9e8b8a824d maint: fix comma style issues: python
Most of our code base uses space after comma but not before;
fix the remaining uses before adding a syntax check.

* python/libvirt-override.c: Consistently use commas.

Signed-off-by: Eric Blake <eblake@redhat.com>
2013-11-20 09:14:55 -07:00
34b7679331 Add missing break to switch-case block
The case label for VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED did not have its
own break statement but relied on falling through which we probably
don't want.
2013-11-19 10:29:28 -06:00
1da4ac52f5 python: Fix Create*WithFiles filefd passing
Commit d76227be added functions virDomainCreateWithFiles and
virDomainCreateXMLWithFiles, but there was a little piece missing in
python bindings.  This patch fixes proper passing of file descriptors
in the overwrites of these functions.
2013-10-22 23:01:18 +01:00
90461df0ca maint: avoid 'const fooPtr' in python bindings
'const fooPtr' is the same as 'foo * const' (the pointer won't
change, but it's contents can).  But in general, if an interface
is trying to be const-correct, it should be using 'const foo *'
(the pointer is to data that can't be changed).

Fix up offenders in the python bindings.

* python/generator.py (py_types): Drop useless conversions.
* python/libvirt-override.c (getPyVirTypedParameter)
(setPyVirTypedParameter): Use intended type.

Signed-off-by: Eric Blake <eblake@redhat.com>
2013-10-14 14:34:37 -06:00
357df252fb python: add bindings for virConnectGetCPUModelNames
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-09-23 16:59:39 -06:00
793ca0c3b1 Fix potential use of uninitialized value in virDomainGetVcpuPinInfo
The virDomainGetVcpuPinInfo python wrapper had a potential use of
uninitialized values

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-09-20 17:22:39 +01:00
8566ca3ad1 Add VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED event 2013-07-18 15:28:45 +02:00